#!/usr/bin/perl -w # use Net::Ping; @SwitchList = qw( 2gsan7 2gsan8 2gsan1 2gsan2 san1 san2 san3 san4 ); # Set BigBro vars $BBHOME = '/opt/bb/bb'; $BB = "$BBHOME/bin/bb"; $BBDISP = 'bb.mydomain.local'; $test = 'status'; $TIME = localtime(time); foreach $switch (@SwitchList) { $hostalive = 'false'; $p = Net::Ping->new() or die "Can't create new ping object: $!\n"; $hostalive = 'true' if $p->ping($switch); $p->close; $color = 'red'; $host = $switch; $host .= ',mydomain,local'; $Message = "\n\n"; if ( $hostalive ne 'true' ) { $Message .= "Unable to connect to the switch. This should be investigated."; system("$BB $BBDISP \"status $host.$test $color $TIME Overall Status of $switch.\n\n$Message\""); next; } $log = "$BBHOME/tmp/$switch" . 'log'; $command = "/opt/bb/bb/ext/sw_cmd.pl -s $switch -u username -p password -o $log switchstatusshow"; system("$command"); if ( -e "$log") { open(LOG,"<$log"); @LOG = ; close(LOG); foreach $line (@LOG) { if ($line =~ /Marginal/i) { $line = '&red ' . $line; $color = 'red'; $Message .= $line; } elsif ($line =~ /HEALTHY\/OK/i) { $line = '&green ' . $line; $color = 'green'; $Message .= $line; } else { $Message .= $line; } } } else { $color = 'yellow'; $Message .= "Unable to get the switch status. This should be investigated."; } system("$BB $BBDISP \"status $host.$test $color $TIME Overall Status of $switch.\n\n$Message\""); unlink("$log"); } #