package HotSaNICmod::OSdep; use RRDs; use lib "../../lib"; use HotSaNICsnmp; sub version { ($VERSION = '$Revision: 1.13 $') =~ s/.*(\d+\.\d+).*/$1/; return "default.pm $VERSION"; } sub sample { my %args=@_; my $oid = '.1.3.6.1.4.1.2021.9.1'; # enterprises.ucdavis.dskTable.dskEntry # my $suf_device = '.3.'; # .dskDevice my $suf_total = '.6.'; # .dskTotal my $suf_used = '.8.'; # .dskUsed if ($args{NUM} > 0) { undef my %devmax; undef my %devuse; undef my %devyes; undef my %devsnmp; # $dev $max $use $name $old $d @arr @diskfree $ERROR %ARGS); # check which drives should be sampled and which existing databases ahve to be updated # foreach (keys(%args)) { if(index($_, "DRIVE") == 0 && $args{$_} > 0) { if(index($_, "SNMP:") >= 0) { my @arg; my $key; s/DRIVE:SNMP://; @arg = split ":"; $key = join "_", $arg[0], $arg[1]; if(defined($devsnmp{$key})) { push @{$devsnmp{$key}}, $arg[2]; } else { $devsnmp{$key} = [ $arg[2] ]; } } else { s/DRIVE://; $devyes{$_} = 1; $devmax{$_} = "U"; $devuse{$_} = "U"; } } } # add/overwrite with summary of all currently available partitions # using "df" system command. $old=""; if ( $args{NFSPARTS} == 0) { @diskfree = grep(/\//,`df -lk`); } else { @diskfree = grep(/\//,`df -k`); } foreach $_ (@diskfree) { $_="$old $_"; $old=""; chomp; ($dev,$max,$use) = split; # check for line-break if ((!defined $use) || ($use eq "")) { $old=$_; next; } $max*=1024 if defined $max; $use*=1024 if defined $use; next if !defined($devyes{$dev}); $devmax{$dev}=$max; $devuse{$dev}=$use; } # Begin SNMP conversation here foreach ( keys(%devsnmp) ) { my ($host, $com) = split "_", $_; my @targets = @{$devsnmp{$_}}; my $res; $res = HotSaNICsnmp::snmp_walk($host, $com, ($oid)); if(keys(%$res) == 0) { for (@targets) { $devyes{$host."_".$_} = 1; $devmax{$host."_".$_} = "U"; $devuse{$host."_".$_} = "U"; } } else { for (my $i=1; defined($$res{$oid.$suf_device.$i}); $i++) { my $dev = $$res{$oid.$suf_device.$i}; for (@targets) { if($_ eq $dev) { my $total = $$res{$oid.$suf_total.$i}; my $used = $$res{$oid.$suf_used.$i}; $devyes{$host."_".$dev} = 1; $devmax{$host."_".$dev} = $total*1024; $devuse{$host."_".$dev} = $used *1024; } } } } } # End SNMP conversation here # here begins the evaluation of all sampled data: # foreach $name (keys %devmax) { # check if the device shall really be sampled # if ( defined($devyes{$name}) ) { (my $rrdname = $name) =~ s/(\/|:)/_/g; # build new database if needed and update database # if ( ! -e "rrd/$rrdname.rrd" ) { system("./makerrd","$rrdname","U") } RRDs::update "rrd/$rrdname.rrd",time.":".$devmax{$name}.":".$devuse{$name}; if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to update `$rrdname.rrd': $ERROR\n"; } } } } } 1;
hotsanic |
Subversion Repositories: |
Line No. | Rev | Author | Line |
---|