#!/usr/bin/perl
$|=1;
use Net::SNMP qw/:ALL/;
use feature qw/say switch/;
use strict;
my @switches = qw /10.99.0.201 10.99.0.202 10.99.0.203 10.99.0.204 10.99.0.211 10.99.0.212 10.99.0.215 10.1.1.101 10.1.1.102 10.1.1.105 10.1.1.106 10.1.1.107 10.1.1.108 10.1.1.109 10.1.1.110 10.1.1.111 10.1.1.112 10.130.30.249 10.130.10.241 10.130.10.242 10.130.10.243 10.130.41.201 10.130.40.239/;
#my @switches = qw /10.99.0.215/;
my $community="con";
my $wwwPath="/mnt/syslog/switchview";
my $refreshInterval=60;
my $OnlyErrors = 0; #1|0
my $SpecialPorts = 0; #1|0, VLAN und loopback ausblenden wenn 0
my $PortErrorFile = '/mnt/syslog/switchview/port-errors';
my $AllPortErrorFile = '/mnt/syslog/switchview/port-errors-alltime';
my $PortErrorWOPath = 'port-errors';
my $AllPortErrorWOPath = 'port-errors-alltime';
foreach (@switches) {
read_switch("$_", "$community");
}
my @HTML;
{ # HTML Datei bauen
push @HTML, "
";
push @ta, " ";
push @ta, " | ";
push @ta, " IP";
push @ta, " | ";
push @ta, " ";
push @ta, " Hostname";
push @ta, " | ";
push @ta, " ";
push @ta, " Uptime";
push @ta, " | ";
push @ta, " ";
push @ta, " Typ";
push @ta, " | ";
push @ta, "
";
push @ta, " ";
push @ta, "";
push @ta, "";
push @ta, "$SwitchIP";
push @ta, "";
push @ta, "";
my @IPs = split/,/,$IPstr;
foreach (@IPs) {
my ($ip,$mask) = split / /,$_;
push @ta, "| $ip | $mask | ";
}
push @ta, " ";
push @ta, "";
push @ta, " | \n";
push @ta, " ";
push @ta, " $SwitchHostname";
push @ta, " | ";
push @ta, " ";
push @ta, " $SwitchUptime";
push @ta, " | ";
push @ta, " ";
push @ta, " $SwitchType";
push @ta, " | ";
push @ta, "
";
push @ta, "
";
push @ta, "";
push @ta, "";
push @ta, "";
push @ta, "Port Interface";
push @ta, " | ";
push @ta, "";
push @ta, "Admin Status Oper Status";
push @ta, " | ";
push @ta, "";
push @ta, "Speed/Duplex configured Speed/Duplex running";
push @ta, " | ";
push @ta, "";
push @ta, "Description";
push @ta, " | ";
push @ta, "";
push @ta, "VLAN";
push @ta, " | ";
push @ta, "";
push @ta, "Last Change"; # Letze Portstatusänderung vor ....
push @ta, " | ";
push @ta, "";
push @ta, "in octets out octets";
push @ta, " | ";
push @ta, "";
push @ta, "in errors out errors";
push @ta, " | ";
push @ta, "";
push @ta, "STP status";
push @ta, " | ";
push @ta, "
";
}
my $j=0;
foreach (sort keys %{$RSwitch{$SwitchIP}->{'Ports'}}) {
my $PortName;
{ # Portname
$PortName = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifName'};
next if ($PortName =~ /loopback/i or $PortName =~ /vlan/i);
if ($PortName =~ /^$/i) {
$PortName = "not plugged";
}
}
my $PortIndex;
my $STP_text;
my $STP_color;
{ # Portindex
$PortIndex=sprintf("%d",$_);
}
{ # STP status
$STP_text = $STP[$RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifSTPStatus'}];
$STP_text = "" if ($STP_text eq "undef");
$STP_color = "yellow";
$STP_color = "green" if ($RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifSTPStatus'} == 5);
$STP_color = "red" if ($RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifSTPStatus'} == 2);
}
my $ASTATUS_text;
my $ASTATUS_color;
{ # Admin Status, soll Port aktiv sein
$ASTATUS_text = $ASTATUS[$RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifAdminStatus'}];
$ASTATUS_text = "" if ($ASTATUS_text eq "undef");
$ASTATUS_color = "yellow";
$ASTATUS_color = "green" if ($RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifAdminStatus'} == 1);
$ASTATUS_color = "red" if ($RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifAdminStatus'} == 2);
}
my $OSTATUS_text;
my $OSTATUS_color;
{ # Oper Status, Port aktiv?
$OSTATUS_text = $OSTATUS[$RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifOperStatus'}];
$OSTATUS_text = "" if ($OSTATUS_text eq "undef");
$OSTATUS_color = "yellow";
$OSTATUS_color = "green" if ($RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifOperStatus'} == 1);
$OSTATUS_color = "red" if ($RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifOperStatus'} == 2);
}
my $ifInOctets;
my $ifInOctetsString;
{ # in octets, eingehende Datenmenge
$ifInOctets = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifInOctets'};
if ($ifInOctets >= 1000000000) {
$ifInOctets /= 1000000000;
$ifInOctetsString = sprintf "%.2f GBytes", $ifInOctets;
}
elsif ($ifInOctets >= 1000000) {
$ifInOctets /= 1000000;
$ifInOctetsString = sprintf "%.2f MBytes", $ifInOctets;
}
elsif ($ifInOctets >= 1000) {
$ifInOctets /= 1000;
$ifInOctetsString = sprintf "%.2f KBytes", $ifInOctets;
}
else {
$ifInOctetsString = sprintf "%.2f Bytes", $ifInOctets;
}
}
my $ifEtherMode;
my $ifEtherModeString;
{ # Ethermode, konfigurierte Porteinstellung
$ifEtherMode = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifEtherMode'};
given($ifEtherMode) {
when(1) { $ifEtherModeString = "10-HDx" }
when(2) { $ifEtherModeString = "100-HDx" }
when(3) { $ifEtherModeString = "10-FDx" }
when(4) { $ifEtherModeString = "100-FDx" }
when(5) { $ifEtherModeString = "Auto" }
when(6) { $ifEtherModeString = "1000-FDx" }
when(7) { $ifEtherModeString = "Auto-10" }
when(8) { $ifEtherModeString = "Auto-100" }
when(9) { $ifEtherModeString = "Auto-1000" }
when(10) { $ifEtherModeString = "Auto-10G" }
when(11) { $ifEtherModeString = "Auto-10-100" }
default { $ifEtherModeString = "not conf." }
}
}
my $ifAlias;
{ # Alias
$ifAlias = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifAlias'};
}
my $ifVLAN;
{ # VLAN Name
$ifVLAN = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifVLAN'};
}
my $ifInErrors;
{ # in errors, eingehende Fehler
$ifInErrors = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifInErrors'};
}
my $ifOutOctets;
my $ifOutOctetsString;
{ # out octets, ausgehende Datenmenge
$ifOutOctets = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifOutOctets'};
if ($ifOutOctets >= 1000000000) {
$ifOutOctets /= 1000000000;
$ifOutOctetsString = sprintf "%.2f GBytes", $ifOutOctets;
}
elsif ($ifOutOctets >= 1000000) {
$ifOutOctets /= 1000000;
$ifOutOctetsString = sprintf "%.2f MBytes", $ifOutOctets;
}
elsif ($ifOutOctets >= 1000) {
$ifOutOctets /= 1000;
$ifOutOctetsString = sprintf "%.2f KBytes", $ifOutOctets;
}
else {
$ifOutOctetsString = sprintf "%.2f Bytes", $ifOutOctets;
}
}
my $ifOutErrors;
{ # out errors, ausgehende Fehler
$ifOutErrors = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifOutErrors'};
}
my $ifSpeed;
my $ifSpeedString;
my $ifDuplexMode;
{ # speed/duplex, aktuelle Portgeschwindigkeit
# Speed
$ifSpeed = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifSpeed'};
$ifSpeedString = $ifSpeed;
$ifSpeedString = "10 Gbit/s" if ($ifSpeed == 10000000000);
$ifSpeedString = "1 Gbit/s" if ($ifSpeed == 1000000000);
$ifSpeedString = "100 Mbit/s" if ($ifSpeed == 100000000);
$ifSpeedString = "10 Mbit/s" if ($ifSpeed == 10000000);
# Duplexmodus
$ifDuplexMode = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifDuplexMode'};
given ($ifDuplexMode) {
when (1) { $ifDuplexMode="HDx" }
when (2) { $ifDuplexMode="FDx" }
default { $ifDuplexMode="??"}
}
}
my $ifPortType;
{ # Interface, Typ des physikalischen Ports
if ($SwitchType =~ /hp/i) {
$ifPortType = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifPortTypehp'}
}
else {
$ifPortType = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifPortType'};
}
given ($ifPortType) {
when (2) { $ifPortType="none" }
when (3) { $ifPortType="unknown (3)" }
when (6) { $ifPortType="ethernetCsmacd" }
when (7) { $ifPortType="iso88023Csmacd" }
when (15) { $ifPortType="fddi" }
when (37) { $ifPortType="atm" }
when (53) { $ifPortType="Port-Channel/Stack" }
when (54) { $ifPortType="propMultiplexor" }
when (55) { $ifPortType="ieee80212" }
when (56) { $ifPortType="(virtual) FibreChannel" }
when (62) { $ifPortType="fastEther" }
when (69) { $ifPortType="fastEtherFX" }
when (117) { $ifPortType="gigabitEthernetSX" }
when (118) { $ifPortType="gigabitEthernetLX" }
when (119) { $ifPortType="gigabitEthernetT" }
when (120) { $ifPortType="gigabitEthernetStk"}
when (121) { $ifPortType="gigabitEthernetLH" }
when (122) { $ifPortType="tenGbE-CX4" }
when (123) { $ifPortType="gigabitEthernetESP" }
when (124) { $ifPortType="tenGbE-SR" }
when (125) { $ifPortType="tenGbE-ER" }
when (126) { $ifPortType="tenGbE-LR" }
when (127) { $ifPortType="gigabitEthernetT-sfp" }
default { $ifPortType="unknown value ($ifPortType)" }
}
}
my $TimeDiff;
{ # Last change, letzte Statusänderung des Ports
$TimeDiff = $RSwitch{$SwitchIP}->{'Switch'}->{'Uptime'} - $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifLastChange'};
# wenn zeitspanne zw. reboot und portstatuswechsel < 3 sek oder der letzte wechsel vor reboot war
# dann wird behauptet das es nie einen statuswechsel gab
if ($RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifLastChange'} < 300 or $TimeDiff < 0) {
$TimeDiff = "Never";
}
else {
$TimeDiff = ticks_to_time ($TimeDiff);
}
}
my $ifType;
{ # Port ein Trunk?
$ifType=$RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifTrkName'};
$ifType=sprintf("%d",$ifType);
given ($ifType) {
when (0) {$ifType="Access"}
when (1) {$ifType="Mesh"}
default {$ifType--;$ifType="Trunk ($ifType)"}
}
given ($PortName) {
when (/Mesh/) {$ifType="Mesh"}
when (/Trk/) {$ifType="Trunk"}
}
}
my $ifVLANs;
{ # VLANs
$ifVLANs = $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifVLANs'};
}
my $display;
{ ### Should this port be displayed?
$display=1;
$display=0 if ($OnlyErrors and $ifOutErrors==0 and $ifInErrors==0);
$display=0 if ($SpecialPorts==0 and $PortName=~/VLAN|loopback|Null|Stack/i);
}
if ($display) { # Port in Tabelle anzeigen
push @ta, "\n";
my @MAC = split / /,$RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'onifMAC'};
my $str;
foreach (@MAC) {
$str .= "$_
";
}
push @ta, "\n";
push @ta, "$PortName ($PortIndex) $ifPortType";
my $para="Switch: $SwitchIP
Port: $PortName
Port-MAC: $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifMAC'}
Angeschlossene MACs: $str";
push @ta, " ";
push @ta, "";
push @ta, "MAC Addresse des Interface: $RSwitch{$SwitchIP}->{'Ports'}->{$_}->{'ifMAC'} Angeschlossene MAC Adressen: ";
push @ta, "$str";
push @ta, "";
push @ta, " | \n";
push @ta, "";
push @ta, "\n\n| ";
push @ta, "$ASTATUS_text";
push @ta, " | \n \n";
push @ta, "\n| ";
push @ta, "$OSTATUS_text";
push @ta, " | \n \n ";
push @ta, "";
push @ta, "Interface ist abgeschaltet." if ($ASTATUS_text eq 'down');
push @ta, "Interface ist eingeschaltet aber ohne Link." if ($ASTATUS_text eq 'up' and $OSTATUS_text eq 'down');
push @ta, "Interface hat einen Link." if ($ASTATUS_text eq 'up' and $OSTATUS_text eq 'up');
push @ta, "";
push @ta, " | \n";
push @ta, "";
push @ta, "$ifEtherModeString $ifSpeedString $ifDuplexMode";
push @ta, " ";
push @ta, "";
push @ta, "Interface auf $ifEtherModeString konfiguriert und läuft mit $ifSpeedString $ifDuplexMode";
push @ta, "";
push @ta, " | \n";
push @ta, "";
push @ta, "$ifAlias";
push @ta, " ";
push @ta, "";
push @ta, "Konfigurierte Beschreibung";
push @ta, "";
push @ta, " | \n";
$para = $ifVLANs;
$para =~ s/ /
/g;
$para = "Switch: $SwitchIP
Port: $PortName
VLANs:
" . $para;
push @ta, "";
push @ta, "$ifType \n$ifVLAN \n";
my @VL;
@VL = split/ /,$ifVLANs;
# my $str;
$str='';
$j=0;
foreach (@VL) {
$_ =~ s/\(/ \(/;
if ($j%2==0) {
$str .= "\n| • $_ | \n";
}
else {
$str .= "• $_ | \n \n";
}
$j++;
}
$str .= " \n";
push @ta, $str;
push @ta, " | \n";
push @ta, "";
push @ta, "$TimeDiff";
push @ta, " ";
push @ta, "";
if ($TimeDiff eq "Never") {
push @ta, "Interface seit dem letzten Switchstart ohne Link";
}
else {
push @ta, "Interface seit $TimeDiff ohne Link" if ($OSTATUS_text eq "down");
push @ta, "Interface hat seit $TimeDiff einen Link" if ($OSTATUS_text eq "up");
}
push @ta, "";
push @ta, " | \n";
push @ta, "";
push @ta, "$ifInOctetsString $ifOutOctetsString";
push @ta, " ";
push @ta, "";
push @ta, "Empfangene Datenmenge: $ifInOctetsString Gesendete Datenmenge: $ifOutOctetsString";
push @ta, "";
push @ta, " | \n";
push @ta, "";
push @ta, "$ifInErrors $ifOutErrors";
push @ta, " ";
push @ta, "";
push @ta, "Anzahl fehlerhafter Pakete die empfangen wurden: $ifInErrors nicht gesendet werden konnten: $ifOutErrors";
push @ta, "";
push @ta, " | \n";
push @ta, "";
push @ta, "$STP_text";
push @ta, " | \n";
push @ta, "
\n";
}
}
push @ta, "
\n";
return @ta;
}
sub snmp_get {
my ($OID, $IP, $COMMUNITY) = @_;
my ($session, $error) = Net::SNMP->session(
-hostname => $IP,
-community => $COMMUNITY,
-translate => [
-all => 0,
-octetstring => 0,
-null => 0,
-timeticks => 0,
-opaque => 0,
-nosuchobject => 0,
-nosuchinstance => 0,
-endofmibview => 0,
-unsigned => 0,
]
);
my $result = $session->get_request(-varbindlist => [ $OID ],);
$session->close();
return $result->{$OID};
}
sub snmp_walk2 {
my ($OID, $IP, $COMMUNITY) = @_;
my ($session, $error) = Net::SNMP->session(
-hostname => $IP,
-community => $COMMUNITY,
-version => "snmpv2c",
-translate => [
-all => 0,
-octetstring => 0,
-null => 0,
-timeticks => 0,
-opaque => 0,
-nosuchobject => 0,
-nosuchinstance => 0,
-endofmibview => 0,
-unsigned => 0,
]
);
my $result = $session->get_table(
-baseoid => $OID,
);
if (!defined $result) {
$session->close();
return 1;
}
$session->close();
return %{$result};
}
sub read_switch {
my $SwitchIP = $_[0];
my $SwitchSNMPcommunity = $_[1];
printf "\n\nPruefe Switch %s mit community %s\n", $SwitchIP, $SwitchSNMPcommunity;
print " SwitchType\n";
my $SwitchType = snmp_get("1.3.6.1.2.1.1.1.0", $SwitchIP, $SwitchSNMPcommunity);
my $SwType;
$SwType = "cisco" if $SwitchType =~ /Cisco/;
$SwType = "hp" if $SwitchType =~ /HP/i;
print " SwitchHostname\n";
my $SwitchHostname = snmp_get("1.3.6.1.2.1.1.5.0", $SwitchIP, $SwitchSNMPcommunity);
print " SwitchUptime\n";
my $SwitchUptime = snmp_get("1.3.6.1.2.1.1.3.0", $SwitchIP, $SwitchSNMPcommunity);
print " SwitchIPs\n";
my %SwitchIPs = snmp_walk2("1.3.6.1.2.1.4.20.1.3", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifIndex\n";
my %RifIndex = snmp_walk2("1.3.6.1.2.1.2.2.1.1", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifName\n";
my %RifName = snmp_walk2("1.3.6.1.2.1.2.2.1.2", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifAdminStatus\n";
my %RifAdminStatus = snmp_walk2("1.3.6.1.2.1.2.2.1.7", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifOperStatus\n";
my %RifOperStatus = snmp_walk2("1.3.6.1.2.1.2.2.1.8", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifSpeed\n";
my %RifSpeed = snmp_walk2("1.3.6.1.2.1.2.2.1.5", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifLastChange\n";
my %RifLastChange = snmp_walk2("1.3.6.1.2.1.2.2.1.9", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifInOctets\n";
my %RifInOctets = snmp_walk2("1.3.6.1.2.1.2.2.1.10", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifOutOctets\n";
my %RifOutOctets = snmp_walk2("1.3.6.1.2.1.2.2.1.16", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifSTPStatus\n";
my %RifSTPStatus = snmp_walk2("1.3.6.1.2.1.17.2.15.1.3", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifInErrors\n";
my %RifInErrors = snmp_walk2("1.3.6.1.2.1.2.2.1.14", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifOutErrors\n";
my %RifOutErrors = snmp_walk2("1.3.6.1.2.1.2.2.1.20", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifHighSpeed\n";
my %RifHighSpeed = snmp_walk2("1.3.6.1.2.1.31.1.1.1.15", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifEtherMode\n";
my %RifEtherMode = snmp_walk2("1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.10", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifVLAN\n";
my %RifVLAN;
if ($SwType eq "hp") {
%RifVLAN = snmp_walk2("1.3.6.1.2.1.17.7.1.4.5.1.1", "$SwitchIP", "$SwitchSNMPcommunity");
}
if ($SwType eq "cisco") {
%RifVLAN = snmp_walk2("1.3.6.1.4.1.9.9.68.1.2.2.1.2", "$SwitchIP", "$SwitchSNMPcommunity");
foreach (keys %RifVLAN) {
my $VL = sprintf ("%s", $RifVLAN{$_});
$RifVLAN{$_} = $VL;
#print "$_ $VL\n";
}
}
print " RifTrunk\n";
my %RifTrunk = snmp_walk2("1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.8", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifPortType\n";
my %RifPortTypehp = snmp_walk2("1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.2", "$SwitchIP", "$SwitchSNMPcommunity");
my %RifPortType = snmp_walk2("1.3.6.1.2.1.2.2.1.3", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifDuplexMode\n";
my %RifDuplexMode = snmp_walk2("1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.5", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifAlias\n";
my %RifAlias = snmp_walk2("1.3.6.1.2.1.31.1.1.1.18", "$SwitchIP", "$SwitchSNMPcommunity");
print " RifMAC\n";
my %RifMAC = snmp_walk2("1.3.6.1.2.1.2.2.1.6", "$SwitchIP", "$SwitchSNMPcommunity");
print " RTagging\n";
my %RTagging;
if ($SwType eq "hp") {
%RTagging = snmp_walk2("1.3.6.1.2.1.17.7.1.4.3.1.2", "$SwitchIP", "$SwitchSNMPcommunity");
}
elsif ($SwType eq "cisco") {
%RTagging = snmp_walk2("1.3.6.1.4.1.9.9.68.1.2.2.1.2", "$SwitchIP", "$SwitchSNMPcommunity");
foreach (keys %RTagging) {
my $VL = sprintf ("%s", $RTagging{$_});
$RTagging{$_} = $VL;
}
}
print " RonifMAC\n";
my %RonifMAC = snmp_walk2("1.3.6.1.2.1.17.4.3.1.2", "$SwitchIP", "$SwitchSNMPcommunity");
my @ALLVLAN;
if ($SwType eq "hp") {
print " VLANs\n";
foreach my $VLANID (sort keys %RTagging) {
$VLANID =~ s/1.3.6.1.2.1.17.7.1.4.3.1.2.//;
$ALLVLAN[$VLANID] = snmp_get("1.3.6.1.2.1.17.7.1.4.3.1.1.$VLANID", $SwitchIP, $SwitchSNMPcommunity);
}
}
elsif ($SwType eq "cisco") {
print " VLANs\n";
}
else { print " VLANs skipped\n"; }
my %RSwitch;
my %RTagg;
$RSwitch{$SwitchIP}->{'Switch'}->{'Type'} = $SwitchType;
$RSwitch{$SwitchIP}->{'Switch'}->{'Hostname'} = $SwitchHostname;
$RSwitch{$SwitchIP}->{'Switch'}->{'Uptime'} = $SwitchUptime;
my $IPs;
foreach (keys %SwitchIPs) {
my $IP = $_;
$IP =~ s/1.3.6.1.2.1.4.20.1.3.//;
$IPs .= $IP . " $SwitchIPs{$_},"
}
$RSwitch{$SwitchIP}->{'Switch'}->{'IPs'} = $IPs;
print " VLANs zu Ports\n";
foreach my $ifindexoid (keys %RifIndex) {
my ($IntIdx)=$ifindexoid=~/\.([0-9]*)$/;
my $myifindex = sprintf "%05s", $RifIndex{$ifindexoid};
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifIndex'} = $RifIndex{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.1/1.3.6.1.2.1.2.2.1.2/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifName'} = $RifName{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.2/1.3.6.1.2.1.2.2.1.7/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifAdminStatus'} = $RifAdminStatus{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.7/1.3.6.1.2.1.2.2.1.8/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifOperStatus'} = $RifOperStatus{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.8/1.3.6.1.2.1.2.2.1.5/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifSpeed'} = $RifSpeed{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.5/1.3.6.1.2.1.2.2.1.9/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifLastChange'} = $RifLastChange{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.9/1.3.6.1.2.1.2.2.1.10/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifInOctets'} = $RifInOctets{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.10/1.3.6.1.2.1.2.2.1.16/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifOutOctets'} = $RifOutOctets{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.16/1.3.6.1.2.1.17.2.15.1.3/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifSTPStatus'} = $RifSTPStatus{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.17.2.15.1.3/1.3.6.1.2.1.2.2.1.14/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifInErrors'} = $RifInErrors{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.14/1.3.6.1.2.1.2.2.1.20/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifOutErrors'} = $RifOutErrors{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.20/1.3.6.1.2.1.31.1.1.1.15/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifHighSpeed'} = $RifHighSpeed{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.31.1.1.1.15/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.10/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifEtherMode'} = $RifEtherMode{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.10/1.3.6.1.2.1.31.1.1.1.18/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifAlias'} = $RifAlias{$ifindexoid};
if ($SwType eq "hp") {
$ifindexoid =~ s/1.3.6.1.2.1.31.1.1.1.18/1.3.6.1.2.1.17.7.1.4.5.1.1/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifVLAN'} = snmp_get("1.3.6.1.2.1.17.7.1.4.3.1.1.$RifVLAN{$ifindexoid}", $SwitchIP, $SwitchSNMPcommunity);
$ifindexoid =~ s/1.3.6.1.2.1.17.7.1.4.5.1.1/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.8/;
}
elsif ($SwType eq "cisco") {
$ifindexoid =~ s/1.3.6.1.2.1.31.1.1.1.18/1.3.6.1.4.1.9.9.68.1.2.2.1.2/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifVLAN'} = $RifVLAN{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.4.1.9.9.68.1.2.2.1.2/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.8/;
}
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifTrkName'} = $RifTrunk{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.8/1.3.6.1.2.1.2.2.1.3/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifPortType'} = $RifPortType{$ifindexoid};
my $ifPortType = $RifPortType{$ifindexoid};
$ifindexoid =~ s/1.3.6.1.2.1.2.2.1.3/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.2/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifPortTypehp'} = $RifPortTypehp{$ifindexoid} if ($SwitchType =~ /hp/i);
$ifindexoid =~ s/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.2/1.3.6.1.4.1.11.2.14.11.5.1.7.1.3.1.1.5/;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifDuplexMode'} = $RifDuplexMode{$ifindexoid};
my $str=$RifMAC{"1.3.6.1.2.1.2.2.1.6.$IntIdx"};
my @MAC=split//,$str;
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifMAC'} = sprintf ("%02X:%02X:%02X:%02X:%02X:%02X", ord($MAC[0]),ord($MAC[1]),ord($MAC[2]),ord($MAC[3]),ord($MAC[4]),ord($MAC[5]) );
my $str1;
my @MAC1;
################
print "\n Suche MAC zu Interface $RSwitch{$SwitchIP}->{'Ports'}->{$myifindex}->{'ifName'}: ";
foreach (keys %RonifMAC) {
last if ($ifPortType != 6 ); # not ethernetCsmacd
my $BID=$RonifMAC{$_};
my $Int = snmp_get("1.3.6.1.2.1.17.1.4.1.2.$BID", "$SwitchIP", "$SwitchSNMPcommunity");
($MAC1[0], $MAC1[1], $MAC1[2], $MAC1[3], $MAC1[4], $MAC1[5]) = $_ =~ /\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/;
if ($Int == $IntIdx) {
my $s = sprintf ("%02X:%02X:%02X:%02X:%02X:%02X ", $MAC1[0],$MAC1[1],$MAC1[2],$MAC1[3],$MAC1[4],$MAC1[5]);
$str1 .= $s;
print "!";
}
else {
print ".";
}
}
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'onifMAC'} = $str1;
# ifIndex
my $VLANS;
if($SwType eq "hp") {
foreach my $VLANID (sort keys %RTagging) {
my $HEXSTR = $RTagging{$VLANID};
$VLANID =~ s/1.3.6.1.2.1.17.7.1.4.3.1.2.//;
my $i=0;
my $II = $IntIdx;
while ($II>8) {
$i++;
$II-=8;
}
my $MASK=128>>($II -1);
my $IN=$MASK & ord(substr($HEXSTR, $i, 1));
if ($IN != 0) {
$VLANS = $VLANS . $ALLVLAN[$VLANID] . "($VLANID)" . ' ';
}
}
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifVLANs'} = $VLANS;
}
if($SwType eq "cisco") {
$RSwitch{$SwitchIP}->{'Ports'}->{"$myifindex"}->{'ifVLANs'} = $RTagging{"1.3.6.1.4.1.9.9.68.1.2.2.1.2.$myifindex"};
#"aaa";
}
}
my @switchtable = create_switch_table("$_", \%RSwitch);
my @HTML;
@HTML = (@HTML, @switchtable);
open HTMLFILE, ">$wwwPath/$SwitchIP.html";
printf HTMLFILE "@HTML";
close HTMLFILE;
}