init III
This commit is contained in:
90
Windows Procurve STP Status via Perl/stp_state_noservice.pl
Normal file
90
Windows Procurve STP Status via Perl/stp_state_noservice.pl
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/bin/perl
|
||||
our %Config;
|
||||
|
||||
my @AlarmText;
|
||||
|
||||
while (1) {
|
||||
my %switches;
|
||||
my @StpStatusTrans = qw / undef disabled blocking listening learning forwarding broken/;
|
||||
my $AlarmFlag;
|
||||
|
||||
my $t=localtime;
|
||||
printf "%s\n", $t;
|
||||
|
||||
@AlarmText=();
|
||||
my $Header = sprintf " %-15s %-6s %-12s %-12s\n ------------------------------------------------\n", "Switch", "Port", "Erwartet", "Ausgelesen";
|
||||
push @AlarmText, $Header;
|
||||
|
||||
open CONF, "<stp_state.conf";
|
||||
my @config=<CONF>;
|
||||
close CONF;
|
||||
|
||||
eval "@config";
|
||||
|
||||
my %IfIndex;
|
||||
my %StpStatus;
|
||||
|
||||
# Jede Switch durchlaufen
|
||||
foreach my $switch (keys %switches) {
|
||||
# debug ausgabe
|
||||
#print "\n$switch\n";
|
||||
|
||||
# Port Namen lesen um auf IfIndex zurückzuschließen
|
||||
my @IfIndexArray = `snmpwalk -mall -c public $switch .1.3.6.1.2.1.2.2.1.2`;
|
||||
|
||||
# STP Status lesen um zum IfIndex den STP Status zuzuordnen
|
||||
my @IfStpStatusArray = `snmpwalk -mall -c public $switch .1.3.6.1.2.1.17.2.15.1.3`;
|
||||
|
||||
# Jeden Port dieser Switch durchlaufen
|
||||
foreach (@{$switches{$switch}}) {
|
||||
my ($SollStatus,$port) = $_ =~ /([0-9])_(.*)/;
|
||||
# debug ausgabe
|
||||
#printf " %-6s %-12s", $port, $StpStatusTrans[$SollStatus];
|
||||
|
||||
# Suche IfIndex zu Portname
|
||||
foreach (@IfIndexArray) {
|
||||
if ($_ =~ /$port"/) {
|
||||
my $index;
|
||||
($index) = $_ =~ /\.([0-9]*) =/;
|
||||
${$IfIndex{$switch}}{$port} = $index;
|
||||
|
||||
# Suche STP Status zu IfIndex
|
||||
foreach (@IfStpStatusArray) {
|
||||
if ($_ =~ /$index = /) {
|
||||
my $stp;
|
||||
($stp) = $_ =~ /= ([0-9])/;
|
||||
${$StpStatus{$switch}}{$port} = $StpStatusTrans[$stp];
|
||||
# debug ausgabe
|
||||
#printf "%-12s", $StpStatusTrans[$stp];
|
||||
if ($stp != $SollStatus) {
|
||||
# debug ausgabe
|
||||
#print " ! ";
|
||||
AlarmMail($switch, $port, $StpStatusTrans[$SollStatus], $StpStatusTrans[$stp]);
|
||||
$AlarmFlag = 1;
|
||||
}
|
||||
# debug ausgabe
|
||||
#print "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($AlarmFlag) {
|
||||
open OUT, ">output.txt";
|
||||
printf OUT "@AlarmText";
|
||||
close OUT;
|
||||
|
||||
# Mailserver
|
||||
`clemail -to a.wisniewski\@icfsystems.de -subject "Unerwarteter STP Status" -bodyfile output.txt -from rz\@icfsystems.de -smtpserver 130.35.0.143 -smtpport 25`;
|
||||
|
||||
}
|
||||
# Pause zwischen Prüfungen in Sekunden
|
||||
sleep(600);
|
||||
}
|
||||
|
||||
sub AlarmMail {
|
||||
my ($a,$b,$c,$d) = @_;
|
||||
push @AlarmText, sprintf "%-15s %-6s %-12s %-12s\n", $a, $b, $c, $d;
|
||||
}
|
||||
Reference in New Issue
Block a user