jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [packets/] [platform/] [openbsd.pm] - Blame information for rev 31

 

Line No. Rev Author Line
131simandlpackage HotSaNICmod::OSdep;
2 
3use RRDs;
4use lib "../../lib";
5use HotSaNICsnmp;
6 
7sub version {
8 ($VERSION = '$Revision: 1.4 $') =~ s/.*(\d+\.\d+).*/$1/;
9 return "$^O.pm $VERSION";
10 }
11 
12sub sample {
13 my %args=@_;
14 
15 undef my %maxin;
16 undef my %maxout;
17 undef my %devin;
18 undef my %devout;
19 undef my %sampletime;
20 undef my %snmpinterfaces;
21 undef my %snmpmethods;
22 
23 foreach (keys(%args)) {
24 if ( index($_,"DEV") >= 0) {
25 ($dev,$maxin,$maxout,$description)=split /,/,$args{$_};
26 if ( index($dev,"SNMP\:") >= 0) {
27 (undef,$host,$interface,$community,$method)=split /:/,$dev;
28 if (defined $method) { if ($method eq "walk") { $SNMPWALK{$host}=1 }; }
29 ($dev=$host."_".$interface) =~ s/\./_/g;
30 if (defined $snmpinterfaces{$host.":".$community}) {
31 $snmpinterfaces{$host.":".$community}=$snmpinterfaces{$host.":".$community}." ".$interface;
32 }
33 else { $snmpinterfaces{$host.":".$community}=$interface; }
34 }
35 else { $dev =~ s/:/_/g; }
36 $maxin{$dev}=$maxin;
37 $maxout{$dev}=$maxout;
38 $devin{$dev}="U";
39 $devout{$dev}="U";
40 $sampletime{$dev}=time;
41 }
42 }
43 
44# untested, but very similar to FreeBSD so should work. will test soon.
45 open(IN,"netstat -ib | grep Link |");
46 while(<IN>) {
47 chomp;
48 s/[0-9a-f]{2}(:([0-9a-f]{2})){5}//; # remove mac address
49 ($name, $d, $d, $input, $output)=split;
50 $devin{$name}=$input;
51 $devout{$name}=$output;
52 $sampletime{$name}=time;
53 }
54 close(IN);
55 
56 # then query SNMP hosts and check interfaces
57 #
58 
59 if (%snmpinterfaces) {
60# if ($DEBUGLEVEL >= 6) { print "SNMP defined, checking args...\n"; }
61 $SNMPGET_CMD=$args{"SNMPGET"};
62 $SNMPWALK_CMD=$args{"SNMPWALK"};
63 foreach $combined (sort keys %snmpinterfaces) {
64 ($host,$community)=split /:/,$combined;
65 $interfaces=$snmpinterfaces{$combined};
66 undef @results;
67 if ( ! defined $SNMPWALK{$host} ) {
68 if ( ($SNMPGET_CMD ne "") && ($SNMPGET_CMD ne "not configured") ) {
69 @results=HotSaNICsnmp::snmp_sysbulk($SNMPGET_CMD,$host,$community,".1.3.6.1.2.1.2.2.1.10 .1.3.6.1.2.1.2.2.1.16",$interfaces); }
70 else { print time,": ",$args{MODNAME},"Can't query SNMP target $host - SNMPGET not configured in global settings!"; }
71 }
72 else {
73 if ( ($SNMPWALK_CMD ne "") && ($SNMPWALK_CMD ne "not configured") ) {
74 @unfiltered=HotSaNICsnmp::snmp_sysquery($SNMPWALK_CMD,$host,$community,"interfaces","ifInOctets","ifOutOctets");
75 foreach $line (@unfiltered) {
76 # check if interface number is configured
77 ($interface)=split / /,$line;
78 if (" $interfaces " =~ / $interface /) { push @results,$line; }
79 }
80 }
81 else { print time,": ",$args{MODNAME},"Can't query SNMP target $host - SNMPGET not configured in global settings!"; }
82 }
83 if (defined @results) {
84 foreach $line (@results) {
85 $line =~ s/[A-Za-z]*[0-9]*: //g;
86 ($interface,$input,$output)=split / /,$line;
87 ($nn=$host."_$interface") =~ s/\./_/g;
88 $devin{$nn}=$input;
89 $devout{$nn}=$output;
90 $sampletime{$name}=time;
91 }
92 }
93 }
94 }
95 
96 foreach $name (keys %maxin) {
97 
98 # build new database if needed
99 #
100 if (! -e "rrd/$name.rrd" ) {
101 
102 # get max. transmission value
103 #
104 my $max=$maxin{$name};
105 if ($max < $maxout{$name}) { $max=$maxout{$name} };
106 
107 # if max-transmission is not set, assume 100 MBit.
108 #
109 if ($max == 0) { $max=12500000; }
110 system("./makerrd","$name","$max")
111 }
112 
113 # update database
114 RRDs::update "rrd/$name.rrd",$sampletime{$name}.":".$devin{$name}.":".$devout{$name};
115 if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
116 }
117 
118 }
119 
1201;
121 

Powered by WebSVN 2.2.1