#! /usr/bin/perl # # # use GDBM_File; $genesis_dir='/home/wleiden/svn/genesis'; #$revision_file='/usr/local/wcl/mrtg/last_cfgmaker_revision'; #$revision=`cat $revision_file`; #$revision=~s/\D*(\d+)\D*/$1/s; $host=$ARGV[0]; $arg=$ARGV[1]; if ($ARGV[2] eq 'DEBUG') {$DEBUG=1;$fptime=5;} else {$fptime=20;} $MB=1024*1024; $datafile="/home/wleiden/stats/mrtg/data/${host}.gdbm"; $total_datafile="/home/wleiden/stats/mrtg/total_stats.gdbm"; $pingnodes="172.17.8.1 172.18.8.1 172.17.136.1 172.20.128.1 172.19.128.1 172.17.48.1"; # Cope Jasper Cetim1 RV Unigor Thomas if ($arg eq 'fetch') { $cmd=cmd(); $proxycounter=0; { local(%DATA); tie %DATA,'GDBM_File',"$datafile", &GDBM_READER, 0640|| die "Could not open file: $datafile\n"; foreach $key (keys %DATA) {$OLD_DATA{$key}=$DATA{$key};} untie(%DATA); } unlink("$datafile.work"); tie %DATA,'GDBM_File',"$datafile.work", &GDBM_WRCREAT, 0640|| die "Could not open file: $datafile\n"; $DATA{"timestamp"}=$unow=time(); $elapsed=$unow-$OLD_DATA{"timestamp"}; #print STDERR "EL: $unow -> $elapsed\n"; $doit="/usr/bin/ssh root\@$host /usr/local/bin/bash -c \'\"$cmd\"\'"; if ($DEBUG) {print STDERR "DOIT: $doit\n";} open (DEBUG,">$datafile.debug") || die "$! $datafile.debug"; open (STATS,"$doit|") || die "Could not pipe $doit"; while () { print DEBUG $_; chomp(); if (/^XXX-(\S+)/) {$doing=$1;next} if ($doing eq 'top') { if (/load averages:\s+([0-9.]+),\s+([0-9.]+),\s+([0-9.]+)\s+up\s+(\S+)\s+/) { $now=$1;$five=$2;$ten=$3;$uptime=$4; $DATA{now}=$1; $DATA{five}=$1; $DATA{ten}=$1; $DATA{uptime}=$uptime; if ($uptime=~/(\d+)\+/) {$uptime=$1;} else {$uptime=0;} $DATA{updays}=$uptime; # print "UPTIME:$now:$five:$ten:$uptime\n"; next; } elsif (/Mem:.*? (\d+)M Wired/) {$DATA{mem}=$1*1024*1024;} elsif (/Swap:.*? (\d+)(.) Used/) { $swap=$1; if ($2 eq 'K') {$swap*=1024;} if ($2 eq 'M') {$swap*=1024*1024;} $DATA{swap}=$swap; } # print "$doing: $_\n"; } elsif ($doing eq 'ARP') { if (/\(([0-9.]+)\)\s+at\s+([0-9a-f:]{17})/) { $ip=$1;$mac=lc($2); $ARP{$mac}=$1; #print STDERR "IP=$ip=$mac\n"; } } elsif ($doing=~/users-(\S+)/) { $if=$1; if (/^(\d+)\s+stations?:$/) {$DATA{"users-$if"}=$1;next;} }elsif ($doing=~/signals-(\w+)/) { $if=$1; #print "$doing: $_\n"; if (/: ([0-9a-f:]{17}).*sig: (-\d+), noise: (-\d+), qual: (\d+)/i) { $MAC=lc($1);$sig=$2;$noise=$3;$qual=$4; if (! ($ip=$ARP{$MAC})) {$ip=$MAC;} #print STDERR "MAC=====$ip=$MAC|$sig|$noise|$qual|\n"; $DATA{"SNR-$if-$ip"}="$sig|$noise|$qual"; $DATA{"$if-beacons"}++; } } elsif ($doing eq 'routes') { if (/UG/) {$DATA{'routes'}++;} if (/(\S+)\s+UG1c\s+\d+\s+\d+\s+([a-z0-9]+)/i) { $neighbor=$1;$if=$2; $DATA{"$if-$neighbor-routes"}++; $DATA{"$if-routes"}++; #if ($DEBUG) {print STDERR "OK: $1:$2;\n"} } } elsif ($doing eq 'fping') { #172.16.0.45 : xmt/rcv/%loss = 20/20/0%, min/avg/max = 2.33/3.51/5.15 #172.16.0.41 : xmt/rcv/%loss = 4/0/100% #print "FPING: $_\n"; if (/^(\S+)\s+.*loss = .*?(\d+)%/) { $dest_ip=$1; $loss=$2;$avg=0; if (/$max = (\S+)\/(\S+)\/(\S+)/) {$avg=$2;} $DATA{"pktloss-$dest_ip"}=$loss; $DATA{"latency-$dest_ip"}=$avg; } } elsif ($doing eq 'httpspeed') { if (/^(\d+) bytes transferred in (\S+) seconds/i) { $bytes=$1;$elapsed=$2; if ($elapsed > 0) {$speed=$bytes/$elapsed;} else {$speed=0;} #Receiving /dev/null (102400 bytes): 100% (ETA 00:00) #102400 bytes transferred in 47.6 seconds (2.10 kBps) if ($proxycounter eq 0) {$DATA{"proxyspeed"}=$speed;$proxycounter++;} else {$DATA{"tangospeed"}=$speed;} } } elsif ($doing=~/wicontrol-(\S+)/) { $if=$1; if (/TX rate \(selection\).*?(\d+)/) {$DATA{"sel-TX-speed-$if"}=$1;} if (/actual speed.*?(\d+)/) {$DATA{"act-TX-speed-$if"}=$1;} } elsif($doing=~/dhcp/) { # ahum } elsif ($doing=~/interfaces/) { s/\s+-\s+/ 0 /gi; ($Name,$Mtu,$Network,$Address,$Ipkts,$Ierrs,$Ibytes,$Opkts, $Oerrs,$Obytes,$Coll)=split(/\s+/); if ($Name=~/Name/) {next;} if (/&1; fetch -v -F -o /dev/null -T 10 http://www.wleiden1.demon.nl/fullfile4 2>&1; EOR1 $r=~s/\n/ /gi; return($r); } sub parse_config { foreach $if (keys %config) { $cfg=$config{$if}; #if (! $html) {print "Parsing interface: $if\n";} while ($cfg) { $cfg=~s/^([^\n\r]+)[\r\n]*//m; $line=$1; $line=~s/\s*#.*//; if ((($name,$value)=split(/=/,$line)) eq 2) { #print "VAL($name)=$value\n"; $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\"$separator$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}"; #print "DOIT: [$doit]\n"; eval($doit); } #print "CFG:[$cfg]\n"; $cfg=~s/[\r\n]*$//m; } } #if ($functions_only<1) {print "Done parsing config.\n";} }