jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [part/] [platform/] [default.pm] - Blame information for rev 21

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::OSdep;
2 
3use RRDs;
4 
5use lib "../../lib";
6use HotSaNICsnmp;
7 
8sub version {
9 ($VERSION = '$Revision: 1.13 $') =~ s/.*(\d+\.\d+).*/$1/;
10 return "default.pm $VERSION";
11 }
12 
13sub sample {
14 my %args=@_;
15 
16 my $oid = '.1.3.6.1.4.1.2021.9.1';
17 # enterprises.ucdavis.dskTable.dskEntry
18 #
19 my $suf_device = '.3.';
20 # .dskDevice
21 my $suf_total = '.6.';
22 # .dskTotal
23 my $suf_used = '.8.';
24 # .dskUsed
25 
26 if ($args{NUM} > 0) {
27 undef my %devmax;
28 undef my %devuse;
29 undef my %devyes;
30 undef my %devsnmp;
31 
32# $dev $max $use $name $old $d @arr @diskfree $ERROR %ARGS);
33 
34# check which drives should be sampled and which existing databases ahve to be updated
35#
36 foreach (keys(%args)) {
37 if(index($_, "DRIVE") == 0 && $args{$_} > 0) {
38 if(index($_, "SNMP:") >= 0) {
39 my @arg;
40 my $key;
41 s/DRIVE:SNMP://;
42 @arg = split ":";
43 $key = join "_", $arg[0], $arg[1];
44 if(defined($devsnmp{$key})) {
45 push @{$devsnmp{$key}}, $arg[2];
46 } else {
47 $devsnmp{$key} = [ $arg[2] ];
48 }
49 } else {
50 s/DRIVE://;
51 $devyes{$_} = 1;
52 $devmax{$_} = "U";
53 $devuse{$_} = "U";
54 }
55 }
56 }
57 
58# add/overwrite with summary of all currently available partitions
59# using "df" system command.
60 
61 $old="";
62 if ( $args{NFSPARTS} == 0) { @diskfree = grep(/\//,`df -lk`); }
63 else { @diskfree = grep(/\//,`df -k`); }
64 
65 foreach $_ (@diskfree) {
66 $_="$old $_";
67 $old="";
68 chomp;
69 ($dev,$max,$use) = split;
70# check for line-break
71 if ((!defined $use) || ($use eq "")) { $old=$_; next; }
72 
73 $max*=1024 if defined $max;
74 $use*=1024 if defined $use;
75 
76 next if !defined($devyes{$dev});
77 $devmax{$dev}=$max;
78 $devuse{$dev}=$use;
79 }
80 
81# Begin SNMP conversation here
82 foreach ( keys(%devsnmp) ) {
83 my ($host, $com) = split "_", $_;
84 my @targets = @{$devsnmp{$_}};
85 my $res;
86 
87 $res = HotSaNICsnmp::snmp_walk($host, $com, ($oid));
88 if(keys(%$res) == 0) {
89 for (@targets) {
90 $devyes{$host."_".$_} = 1;
91 $devmax{$host."_".$_} = "U";
92 $devuse{$host."_".$_} = "U";
93 }
94 } else {
95 for (my $i=1; defined($$res{$oid.$suf_device.$i}); $i++) {
96 my $dev = $$res{$oid.$suf_device.$i};
97 
98 for (@targets) {
99 if($_ eq $dev) {
100 my $total = $$res{$oid.$suf_total.$i};
101 my $used = $$res{$oid.$suf_used.$i};
102 
103 $devyes{$host."_".$dev} = 1;
104 $devmax{$host."_".$dev} = $total*1024;
105 $devuse{$host."_".$dev} = $used *1024;
106 }
107 }
108 }
109 }
110 }
111 
112# End SNMP conversation here
113 
114# here begins the evaluation of all sampled data:
115#
116 foreach $name (keys %devmax) {
117 
118# check if the device shall really be sampled
119#
120 if ( defined($devyes{$name}) ) {
121 (my $rrdname = $name) =~ s/(\/|:)/_/g;
122 
123# build new database if needed and update database
124#
125 if ( ! -e "rrd/$rrdname.rrd" ) { system("./makerrd","$rrdname","U") }
126 RRDs::update "rrd/$rrdname.rrd",time.":".$devmax{$name}.":".$devuse{$name};
127 if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to update `$rrdname.rrd': $ERROR\n"; }
128 }
129 }
130 }
131 }
132 
1331;
134 

Powered by WebSVN 2.2.1