Files
scripts-conlxsyslog03/rancid/stp_changes/stp_changes3.sh
conetadm 5718e70f15 init
2024-11-14 21:11:06 +01:00

68 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
SW="switch-catalyst-1 switch-catalyst-2 switch-catalyst-3 switch-catalyst-4 switch-catalyst-5 switch-catalyst-6 switch-catalyst-7 switch-nexus-1 switch-nexus-2 switch-nexus-3 switch-nexus-4"
cd /scripts/rancid/stp_changes/
touch stp_changes3.lastrun
for I in `echo $SW`
do
./stp_changes2.sh $I | tr -d "\n\r" | perl -e '
# open file with switch stats from last run
open FILE, "<.$ARGV[0]";
@FIL=<FILE>;
close FILE;
# save values to oldres
foreach (@FIL) {
($a,$b,$c,$d,$e) = split " ", $_;
$oldres{"$a_$b"}=$c;
}
# open temp files for out from stp_changes2.sh
open FILE, ">.tmp.$ARGV[0]";
$l=<STDIN>;
$l=~s/MST/\nMST/g;
@a=split "\n", $l;
foreach (@a) {
chomp;
$sw = $ARGV[0];
if (/MST/) {
# get new values from output
($m,$c,$o,$i) = $_ =~ m/MST([0-9]*) .* changes ([0-9]*) .* occurred (.*) ago .* from (.*)/;
# if change number is higher than last time
if ($oldres{"$sw_$m"} < $c) {
$da=`date`;
chomp $da;
$url="http://10.99.0.99/port_configs.php\?hostname=" . $sw . "&ifname=" . $i;
$d="<a href=" . $url . " target=port_config>config</a>";
# $d soll port config anzeigen
open OUT, ">>stp_changes3.log";
printf OUT "%-30s\tSTP change on switch %25s\tinstance %5d\tcount %5d\t%10s ago\tinterface %s\t%s\n", $da, $sw, $m, $c, $o, $i, $d;
close OUT;
}
$oldres{"$sw_$m"}=$c;
printf FILE "$sw $m $c $o $i\n";
}
}
close FILE;
# if output of stp_changes2.sh is 0 let tmp file there to see that there has been a problem recently
# otherwise save stats to switch file and remove temp one
if ( -s ".tmp.$ARGV[0]" ) { `cp .tmp.$ARGV[0] .$ARGV[0]`; `rm .tmp.$ARGV[0]`; }
' $I
done
DAT=`date`
tac stp_changes3.log | head -n 100 > stp_changes3.temp
echo '<!-- generated at ' $DAT ' -->' > stp_changes3.html
echo '<!-- rancid@conlxsyslog03:/scripts/rancid/stp_changes/stp_changes3.sh -->' >> stp_changes3.html
echo "<html><head><meta http-equiv='refresh' content='300; URL=stp_changes3.html'></head><body><table border=1>" >> stp_changes3.html
cat stp_changes3.temp | sed "s/^/<tr><td>/g" | sed "s/\t/<\/td><td>/g" | sed "s/$/<\/td><\/tr>/" >> stp_changes3.html
echo "</table></body></html>" >> stp_changes3.html
rm stp_changes3.temp