1 | 1 | simandl | package HotSaNICmod::syssnmp; |
2 | | | |
3 | | | use lib "../../lib"; |
4 | | | use HotSaNICsnmp; |
5 | | | |
6 | | | sub version { |
7 | | | ($VERSION = '$Revision: 1.3 $') =~ s/.*(\d+\.\d+).*/$1/; |
8 | | | return "syssnmp.pm $VERSION"; |
9 | | | } |
10 | | | |
11 | | | sub sample { |
12 | | | my %args=@_; |
13 | | | |
14 | | | my $oid = '.1.3.6.1.2.1.25.4.2.1.2'; |
15 | | | # host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunName |
16 | | | |
17 | | | # build local process-table first |
18 | | | # |
19 | | | my $command="/bin/ps axc"; |
20 | | | open FILE,"$command|" || HotSaNIClog::error("unable to run '$command': $!"); |
21 | | | $_=<FILE>; #strip header line |
22 | | | while (<FILE>) { |
23 | | | chomp; |
24 | | | s/ *$//; # strip spaces |
25 | | | s/^.* //; # only need last word |
26 | | | $localapps{$_}++; |
27 | | | } |
28 | | | close FILE; |
29 | | | |
30 | | | my %snmpapps=(); |
31 | | | foreach $entry (@{$args{APP}}) { |
32 | | | my ($host,$community,$item,$dbname,$name,$file,$description)=HotSaNICmod::common::get_names($entry); |
33 | | | |
34 | | | # Collect all SNMP-Apps in an Hash for later querying |
35 | | | # Process all local apps normaly and update rrd |
36 | | | if ($host ne "") { |
37 | | | @val = split /:/,$item; |
38 | | | push @{$snmpapps{"$host"."_$community"}}, $item; |
39 | | | } |
40 | | | } |
41 | | | |
42 | | | # Query SNMP hosts and store data to rrd |
43 | | | foreach $item ( keys(%snmpapps) ) { |
44 | | | my ($host, $com) = split "_", $item; |
45 | | | my %count; |
46 | | | |
47 | | | $res = HotSaNICsnmp::snmp_walk($host, $com, ($oid)); |
48 | | | foreach ( keys(%$res) ) { |
49 | | | $$res{$_} =~ s/\."//g; |
50 | | | $$res{$_} =~ s/"//g; |
51 | | | $count{$$res{$_}}++; |
52 | | | } |
53 | | | |
54 | | | for (@{$snmpapps{$host."_".$com}}) { |
55 | | | my $rrd = $host."_".$_; |
56 | | | if(defined($count{$_})) { HotSaNICmod::do_rrd($rrd,"U",time,$count{$_}); } |
57 | | | else { HotSaNICmod::do_rrd($rrd,"U",time,"U"); } |
58 | | | } |
59 | | | } |
60 | | | } |
61 | | | |
62 | | | 1; |
63 | | | |