jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [modules/] [part/] [platform/] [syssnmp.pm] - Blame information for rev 36

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::syssnmp;
2 
3use lib "../../lib";
4use HotSaNICsnmp;
5 
6sub version {
7 ($VERSION = '$Revision: 1.1 $') =~ s/.*(\d+\.\d+).*/$1/;
8 return "syssnmp.pm $VERSION";
9 }
10 
11sub sample {
12 my %args=@_;
13 
14 my $oid = '.1.3.6.1.4.1.2021.9.1'; # enterprises.ucdavis.dskTable.dskEntry
15 my $suf_device = '.3.'; # .dskDevice
16 my $suf_total = '.6.'; # .dskTotal
17 my $suf_used = '.8.'; # .dskUsed
18 
19 if (@{$args{DRIVE}} > 0) {
20 undef my %devmax;
21 undef my %devuse;
22 undef my %devyes;
23 undef my %devsnmp;
24 
25# check which drives should be sampled
26#
27 foreach my $entry (@{$args{DRIVE}}) {
28 my ($host,$community,$item,$dbname,$name,$file,$description)=HotSaNICmod::common::get_names($entry);
29 if ($host ne "") {
30 my $key = "$host"."_$community";
31 if (defined($devsnmp{$key})) { push @{$devsnmp{$key}}, $item; }
32 else {$devsnmp{$key} = [ $item ]; }
33 }
34 }
35 
36# Begin SNMP conversation here
37 foreach $remote ( keys(%devsnmp) ) {
38 my ($host, $com) = split "_", $remote;
39 
40 my $res = HotSaNICsnmp::snmp_walk($host, $com, ($oid));
41 
42 if(keys(%$res) == 0) {
43 foreach my $dev (@{$devsnmp{$remote}}) {
44 $devyes{$host."_".$dev} = 1;
45 $devmax{$host."_".$dev} = "U";
46 $devuse{$host."_".$dev} = "U";
47 }
48 }
49 else {
50 for (my $i=1; defined($$res{$oid.$suf_device.$i}); $i++) {
51 my $dev = $$res{$oid.$suf_device.$i};
52 
53 for (@{$devsnmp{$remote}}) {
54 if($_ eq $dev) {
55 my $total = $$res{$oid.$suf_total.$i};
56 my $used = $$res{$oid.$suf_used.$i};
57 
58 $devyes{$host."_".$dev} = 1;
59 $devmax{$host."_".$dev} = $total*1024;
60 $devuse{$host."_".$dev} = $used *1024;
61 }
62 }
63 }
64 }
65 }
66 
67# End SNMP conversation here
68 
69# here begins the evaluation of all sampled data:
70#
71 foreach $name (keys %devmax) {
72 
73# check if the device shall really be sampled
74#
75 if ( defined($devyes{$name}) ) {
76 (my $rrdname = $name) =~ s/(\/|:)/_/g;
77 HotSaNICmod::do_rrd($rrdname,"U",time,$devmax{$name},$devuse{$name});
78 }
79 }
80 }
81 }
82 
831;
84 

Powered by WebSVN 2.2.1