#!/usr/bin/perl -w # # Get the qrVTable from a NetApp filer. Print in a simple form. # Original author, Greg Paris . # #use BER; #use SNMP_Session; use SNMP_util; use strict; my $host = $ARGV[0] || 'toaster'; my $netapp = '.1.3.6.1.4.1.789'; my $quota = $netapp . '.1.4'; my $qrVEntry = $quota . '.5.1'; my %qrV = ( Index => 1, Type => 2, Id => 3, KBytesUsed => 4, KBytesLimit => 5, FilesUsed => 6, FileLimit => 7, PathName => 8, Volume => 9, Tree => 10, ); my %qrVType = ( User => 1, Group => 2, Tree => 3, UserDefault => 4, GroupDefault => 5, Unknown => 6, ); # # Simple checks first. # CHECKS: { gethostbyname $host or die "$0: unknown host $host\n"; if ($< == 0) { require Net::Ping; my $p = Net::Ping->new("icmp"); # requires root privs $p->ping($host, 2) or die "$0: $host not responding\n"; $p->close; } } # # Walk the qrVEntry table. Fill %tree using partial OIDs as keys. # my %tree; my @walk = snmpwalk($host, $qrVEntry); foreach (@walk) { next unless defined $_; next unless /^([^:]+?):(.+)/; $tree{$1} = $2; } # # Get the list of objects we found. # my @obj = map {$_ =~ /^$qrV{Index}\.(.*)/o} keys %tree; die "$0: no objects\n" unless @obj; # # Convert the info to array form. # my @info; foreach my $o (@obj) { my %r = (OBJ => $o); while (my ($k, $n) = each %qrV) { $r{$k} = $tree{"$n.$o"}; } push @info, \%r; } # # Output in form easy for MRTG to access. # foreach my $r (@info) { next if $r->{Type} != $qrVType{Tree}; printf "qtree %s KBytesUsed: %d\n", $r->{Tree}, $r->{KBytesUsed}; printf "qtree %s KBytesLimit: %d\n", $r->{Tree}, $r->{KBytesLimit}; my $kbpct = int(100 * $r->{KBytesUsed} / $r->{KBytesLimit} + 0.5); printf "qtree %s PctKBytesUsed: %d\n", $r->{Tree}, $kbpct; printf "qtree %s FilesUsed: %d\n", $r->{Tree}, $r->{FilesUsed}; printf "qtree %s FileLimit: %d\n", $r->{Tree}, $r->{FileLimit}; my $fupct = int(100 * $r->{FilesUsed} / $r->{FileLimit} + 0.5); printf "qtree %s PctFilesUsed: %d\n", $r->{Tree}, $fupct; } exit 0;