#!/bin/perl # Program: check-t3.pl # Description: Simple, automated health check of Sun StorEdge T3s # Version: 1.0 # Last Update: 22 August 2001 # Written by: Dusan U. Baljevic # # Copyright 2001-2014 Dusan Baljevic # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # The prompt on the T3 arrays is of the form: # [a-z][a-z][0-9][0-9]-t3-[0-9][0-9]-[es|wg] # For example: # mn34-t3-01-es # pq02-t3-02-wg # Change if it is different at your site. # # Make the script tight. # $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/sbin'; $ENV{'SHELL'} = '/bin/sh' if $ENV{'SHELL'} ne ''; $ENV{'IFS'} = '' if $ENV{'IFS'} ne ''; use strict; use POSIX 'uname'; use Net::Telnet (); require Mail::Send; use vars qw($username $password @lines $T3command $Time %T3ARRAYS $key $fh $t $ln @xines $line $msg $DefTimeOut $RecipientX $header @values $Arr $RealPrompt); # # Associative array of T3 disk arrays and their passwords. # %T3ARRAYS = ( "xy44-t3-02-es", "password1", "mn34-t3-01-es", "password2", "ld67-t3-01-es", "password3", "pq02-t3-02-wg", "password4", "rs95-t3-01-wg", "password5" ); # # Who will receive warnings via email? # $RecipientX = "SAN-admin\@company.com"; # # T3 CLI commands and values. # $DefTimeOut = 10; # seconds $T3command = "fru stat"; $Time = localtime; foreach $Arr ( keys %T3ARRAYS ) { print "$Time: Checking $Arr\n"; $RealPrompt = "$Arr"; $username = "root"; $password = "$T3ARRAYS{$Arr}"; $t = new Net::Telnet( Timeout => $DefTimeOut, Prompt => '/$RealPrompt:\/:<1>$/' ); $t->errmode("return"); if ( $t->open("$Arr") ) { $t->login( $username, $password ); my @lines = $t->cmd( String => "$T3command\n", Prompt => '/$RealPrompt:\/:<1>/', Timeout => $DefTimeOut ); while ( $line = $t->getline( TimeOut => $DefTimeOut ) ) { @xines = split( /\n/m, $line ); foreach $ln (@xines) { if ( ( grep( /offline/i, $ln ) ) || ( grep( /disable/i, $ln ) ) ) { print "$Time: ERROR $Arr -> $ln\n"; $msg = new Mail::Send; $msg->to("$RecipientX"); $msg->subject("ERROR: $Arr -> $ln"); $msg->set( $header, @values ); $msg->add( $header, @values ); $msg->delete($header); $fh = $msg->open; print $fh "Check $Arr -> $ln IMMEDIATELY!\n"; $fh->close; } } } $t->close; } else { print "ERROR: Cannot telnet to server $Arr\n"; } } exit(0);