hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
package HotSaNICmod::syssnmp;
use lib "../../lib";
use HotSaNICsnmp;
sub version {
($VERSION = '$Revision: 1.3 $') =~ s/.*(\d+\.\d+).*/$1/;
return "syssnmp.pm $VERSION";
}
sub sample {
my %args=@_;
my $oid = '.1.3.6.1.2.1.25.4.2.1.2';
# host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunName
# build local process-table first
#
my $command="/bin/ps axc";
open FILE,"$command|" || HotSaNIClog::error("unable to run '$command': $!");
$_=<FILE>; #strip header line
while (<FILE>) {
chomp;
s/ *$//; # strip spaces
s/^.* //; # only need last word
$localapps{$_}++;
}
close FILE;
my %snmpapps=();
foreach $entry (@{$args{APP}}) {
my ($host,$community,$item,$dbname,$name,$file,$description)=HotSaNICmod::common::get_names($entry);
# Collect all SNMP-Apps in an Hash for later querying
# Process all local apps normaly and update rrd
if ($host ne "") {
@val = split /:/,$item;
push @{$snmpapps{"$host"."_$community"}}, $item;
}
}
# Query SNMP hosts and store data to rrd
foreach $item ( keys(%snmpapps) ) {
my ($host, $com) = split "_", $item;
my %count;
$res = HotSaNICsnmp::snmp_walk($host, $com, ($oid));
foreach ( keys(%$res) ) {
$$res{$_} =~ s/\."//g;
$$res{$_} =~ s/"//g;
$count{$$res{$_}}++;
}
for (@{$snmpapps{$host."_".$com}}) {
my $rrd = $host."_".$_;
if(defined($count{$_})) { HotSaNICmod::do_rrd($rrd,"U",time,$count{$_}); }
else { HotSaNICmod::do_rrd($rrd,"U",time,"U"); }
}
}
}
1;