#!/usr/bin/perl -w use strict; # # Petr Simandl, www.simandl.cz #require "/home/www/cgi-bi"/home/www/cgi-bin/switches_definitions.pl"n/switches_definitions.pl"; my %map = do("/etc/switches_definitions.conf"); my $snmpwalk = "/usr/bin/snmpwalk"; my @ports = (); my @sw = (); my %sw_d = (); my $portlist = ""; my $p = 0; my $d = ""; my ($fnc,$mac,$if,$ver,$bin,$geom,$desc); print "Content-type: text/html\n\n"; print "\n\n\n"; print "\n"; print "\n"; print "\n"; #nocache! print "
"; #print "here"; open(CONF,"< /etc/switches.conf") || die("can't open datafile: $!"); while () { chomp; next if (/^#/); next if (/^$/); if (/^draw_/) { push @sw, $_; next; } if (/^([0-9a-fA-F]{2}:[0-9a-fA-F]{2}:)|(([0-9]{1,3}\.){3}[0-9]{1,3})/) { ($mac, $portlist) = split(/\|/, $_, 2); @ports = (); foreach ( split(/\|/, $portlist) ) { ($p, $d) = split /;/; $ports[$p] = $d; } $sw_d{$mac} = [ @ports ]; } } close CONF; foreach (@sw) { ($fnc, $mac, $if, $ver, $bin, $geom, $desc) = split /\|/; SWITCH: { if ($fnc eq "draw_rrcp_switch") { draw_rrcp_switch($mac,$if,$bin,$desc,$map{$geom},\%sw_d); last SWITCH; } if ($fnc eq "draw_snmp_switch") { draw_snmp_switch($mac,$if,$ver,$bin,$desc,$map{$geom},\%sw_d); last SWITCH; } } print "
\n"; } my $date = `date`; print "
$date\n
"; print ""; ################################################################################ sub print_port_graph { my $ip = shift(@_); my $page = shift(@_); my $graph = shift(@_); my $caption = shift(@_); my $text = shift(@_); print "$text"; } # end print_port_graph sub draw_rrcp_switch { my $mac = shift(@_); my $if = shift(@_); my $bin = shift(@_); my $desc = shift(@_); my @map = @{shift(@_)}; my $sw_d = shift(@_); my $w = scalar( @{$map[0]} ); my $h = scalar @map; my $hmac = ""; my $x = 0; my $y = 0; my $e = ""; my $f = ""; my $sirka = 70; my $label = ""; my $bg = ""; my $enab = ""; my $mod = ""; my $stat = ""; my $link = ""; my $flow = ""; my $port = 0; my @row = (); my @pole = (); my $porty=`sudo $bin $mac\@$if show int | grep ^$if | sed 's/://g' | sed 's/$if\\///g'`; print "$desc $mac"; # print "
$porty\n
"; foreach (split("\n",$porty)) { s/auto1000M-/auto 1000M-/; @row = split ; @pole[$row[0]] = [ @row[1..5] ]; } print "\n"; for ($y = 0; $y < $h; $y++) { print "\n"; for ($x = 0; $x < $w; $x++) { $bg = "\"#FFFFFF\""; print " \n"; } else { print " \n"; } } print "\n"; } print "
"; if ($port) { $e = substr($enab,0,1); if (defined($sw_d->{$mac}[$port])) {$label = $sw_d->{$mac}[$port];} else { $label = ""; } if ($flow eq "flowctl") { $f = "Y"; } else { $f = "N"; } $hmac = $mac; $hmac =~ s/:/_/g; print_port_graph("10.33.0.2","${hmac}_${port}.html","${hmac}_${port}-day.png","$mac port $port $label","$port $label"); print "
$e $mod $stat $f
"; } sub draw_snmp_switch { my $myip = shift(@_); my $com = shift(@_); my $ver = shift(@_); my $dhcp = shift(@_); my $desc = shift(@_); my @map = @{shift(@_)}; my $sw_d = shift(@_); my @pole_operstatus = (); my @pole_adminstatus = (); my @pole_speed = (); my %pole_dhcpdhosts = (); my %hash_mac = (); my %mactab = (); my $macind = 0; my $port = 0; my $w = scalar( @{$map[0]} ); my $h = scalar @map; my $x = 0; my $y = 0; my $sirka = 70; my $label = ""; my $bg = ""; my $enab = ""; my $e = ""; my $mod = ""; my $stat = ""; my $link = ""; my $flow = ""; my $barva = ""; my $title = ""; my $popis = ""; my $macinfo = ""; my $macip = ""; my $hip = ""; my @row = (); my $dhcp2 = $dhcp; print "$desc $myip"; my $speedall = `$snmpwalk -Os -c $com -v $ver $myip .1.3.6.1.2.1.2.2.1.5`; my $adminstatusall = `$snmpwalk -Os -c $com -v $ver $myip .1.3.6.1.2.1.2.2.1.7`; my $operstatusall = `$snmpwalk -Os -c $com -v $ver $myip .1.3.6.1.2.1.2.2.1.8`; # my $mactable = `$snmpwalk -Os -c $com -v $ver $myip atPhysAddress`; # my $mactableport = `$snmpwalk -Os -c $com -v $ver $myip ipNetToMediaIfIndex`; my $mactable = `$snmpwalk -Os -Cc -c $com -v $ver $myip mib-2.17.4.3.1.1`; my $mactableport = `$snmpwalk -Os -Cc -c $com -v $ver $myip mib-2.17.4.3.1.2`; my $dhcpdconf = `wget -t 1 -T 1 http://$dhcp2/cgi-bin/dhcp.cgi -q -O -`; my $arpn = `wget -t 1 -T 1 http://$dhcp2/cgi-bin/arpn.cgi -q -O -`; foreach (split("\n",$operstatusall)) { s/^ifOperStatus\.([0-9]+) = INTEGER: (.*)$/$1 $2/; @row = split ; $pole_operstatus[$row[0]] = $row[1]; } foreach (split("\n",$adminstatusall)) { s/^ifAdminStatus\.([0-9]+) = INTEGER: (.*)$/$1 $2/; @row = split ; $pole_adminstatus[$row[0]] = $row[1]; } foreach (split("\n",$speedall)) { s/^ifSpeed\.([0-9]+) = Gauge32: (.*)$/$1 $2/; @row = split ; $row[1] =~ s/10000000$/10M/; $row[1] =~ s/100000000$/100M/; $row[1] =~ s/1000000000$/1G/; $row[1] =~ s/4294967295$/10G/; $pole_speed[$row[0]] = $row[1]; } foreach (split("\n",$mactable)) { s/ = Hex-STRING://; ($macind, my $tmpmac) = split(" ", $_, 2); $tmpmac =~ s/ $//g; $tmpmac =~ s/ /:/g; $hash_mac{$macind} = $tmpmac; } foreach (split("\n",$mactableport)) { s/ = INTEGER://; ($macind, $port) = split ; $macind =~ s/^mib-2\.17\.4\.3\.1\.2/mib-2.17.4.3.1.1/; if (exists $mactab{$port} ) { push @{ $mactab{$port} }, $hash_mac{$macind}; # pridam do pole k portu } else { $mactab{$port} = [ $hash_mac{$macind} ]; # zalozim nove pole pro port } } #@pole_arpn = split("\n",$arpn); $dhcpdconf =~ s/\n/ /g; $dhcpdconf =~ s/\s+/ /g; $dhcpdconf =~ s/host /\nhost /g; $dhcpdconf =~ s/}/}\n/g; $dhcpdconf =~ s/\^host //g; my @pole_dhcpdconf = split("\n",$dhcpdconf); for (@pole_dhcpdconf) { if (/^host/) { s/^host ([^\s]+) {\s*hardware\s+ethernet\s+(([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2})\s*;\s*fixed-address\s+(([0-9]{1,3}\.){3}[0-9]{1,3})\s*;\s*}/$2 $1 $4/; (my $mac, my $host, my $ip) = split; $mac =~ tr/a-f/A-F/; $pole_dhcpdhosts{$mac} = "$host $ip"; } } print "\n"; for ($y = 0; $y < $h; $y++) { print "\n"; for ($x = 0; $x < $w; $x++) { $bg = "\"#FFFFFF\""; print " "; } else { print " \n"; } } print "\n"; } print "
"; if ($port) { if ($enab =~ /^up/) {$e = "E";} else {$e = "D";} if (defined($sw_d->{$myip}[$port])) {$label = $sw_d->{$myip}[$port];} else { $label = ""; } $hip = $myip; $hip =~ s/\./_/g; print_port_graph("$dhcp","${hip}_port${port}.html","${hip}_port${port}-day.png","$myip port $port $label","$port $label"); print "
$e $stat
\n"; foreach $mac (@{ $mactab{$port} }) { if (exists $pole_dhcpdhosts{$mac}) { $barva = "black"; $title = "$mac " . $pole_dhcpdhosts{$mac}; $popis = $pole_dhcpdhosts{$mac}; } else { $barva = "red"; $popis = $mac; $macinfo = `wget -t 1 -T 1 http://$dhcp2/cgi-bin/macinfo.cgi?$mac -q -O -`; if ($macinfo) { ($macip) = split(" ", $macinfo, 1) } else { $macip = "none" }; $title = "$mac je neznama MAC adresa! Nalezena IP : $macip"; } print "$popis
" }; print "
"; }; WebSVN - switches - Blame - Rev 28 - /switches.cgi
  jablonka.czprosek.czf

switches

Subversion Repositories:
[/] [switches.cgi] - Blame information for rev 28

 

Line No. Rev Author Line

Powered by WebSVN 2.2.1