2008-02-28 20:21:35 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use Sys::Syslog;
|
|
|
|
use xCAT::Table;
|
|
|
|
|
|
|
|
# admin needs to create a mail aliase called alerts
|
|
|
|
# put "alerts: emailadd,emailaddr.." to /etc/aliases file
|
|
|
|
# then run newaliases command
|
|
|
|
my $MAILTO="alerts";
|
|
|
|
|
|
|
|
my $message;
|
|
|
|
my $briefmsg;
|
|
|
|
my $pair;
|
|
|
|
my $node1;
|
|
|
|
my $info;
|
|
|
|
my $severity_type;
|
|
|
|
my $severity;
|
|
|
|
|
2008-02-29 16:51:03 +00:00
|
|
|
my $host=<STDIN>;
|
2008-02-28 20:21:35 +00:00
|
|
|
chomp($host);
|
|
|
|
my $ip=<STDIN>;
|
|
|
|
chomp($ip);
|
|
|
|
|
2008-02-29 03:20:20 +00:00
|
|
|
my $holder;
|
|
|
|
my $begin=1;
|
|
|
|
my $pair;
|
|
|
|
|
2008-02-29 16:51:03 +00:00
|
|
|
|
2008-02-29 03:20:20 +00:00
|
|
|
while ($temp=<STDIN>) {
|
|
|
|
chomp($temp);
|
|
|
|
my $temp1=$temp; #save the one with quotes
|
|
|
|
$temp1 =~ s/\"//g;
|
|
|
|
my $c1=length($temp);
|
|
|
|
my $c2=length($temp1);
|
|
|
|
|
|
|
|
|
|
|
|
if (($c1-$c2)%2 == 0) {
|
|
|
|
if ($begin==1) { # single line
|
|
|
|
$pair=$temp;
|
|
|
|
}
|
|
|
|
else { # middle multi-line
|
|
|
|
$pair .= " $temp";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
} else { # multi line
|
|
|
|
if ($begin==1) {
|
|
|
|
$pair=$temp; #start of multi-line
|
|
|
|
$begin=0;
|
|
|
|
next;
|
|
|
|
} else {
|
|
|
|
$pair .= " $temp"; #end of multi-line
|
|
|
|
$begin=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 20:21:35 +00:00
|
|
|
@a=split(/ /, $pair);
|
|
|
|
$oid=shift @a;
|
|
|
|
$value=join(' ', @a);
|
|
|
|
|
|
|
|
$message .= " $oid=$value\n";
|
|
|
|
|
2008-02-29 16:51:03 +00:00
|
|
|
#for BladeCenter MM traps and RSA II traps, creat a brief message
|
|
|
|
if ($oid =~ /BLADESPPALT-MIB::spTrapAppId|RSASPPALT-MIB::ibmSpTrapAppId/) {
|
2008-02-28 20:21:35 +00:00
|
|
|
$briefmsg .= " App ID: $value\n";
|
|
|
|
}
|
2008-02-29 16:51:03 +00:00
|
|
|
elsif ($oid =~ /BLADESPPALT-MIB::spTrapAppType|RSASPPALT-MIB::ibmSpTrapAppType/) {
|
|
|
|
$briefmsg .= " App Alert Type: $value\n";
|
2008-02-28 20:21:35 +00:00
|
|
|
}
|
2008-02-29 16:51:03 +00:00
|
|
|
elsif ($oid =~ /BLADESPPALT-MIB::spTrapMsgText|RSASPPALT-MIB::ibmSpTrapMsgText/) {
|
2008-02-28 20:21:35 +00:00
|
|
|
$briefmsg .= " Message: $value\n";
|
|
|
|
}
|
|
|
|
elsif ($oid =~ /BLADESPPALT-MIB::spTrapBladeName/) {
|
|
|
|
my $temp="$value";
|
|
|
|
$temp =~ /^\"(.*)\"/;
|
|
|
|
if ($1) {
|
|
|
|
$briefmsg .= " Blade Name: $value\n";
|
|
|
|
$node1=$1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (($oid =~ /BLADESPPALT-MIB::spTrapSourceId/)) {
|
|
|
|
$briefmsg .= " Error Source=$value\n";
|
|
|
|
}
|
2008-02-29 16:51:03 +00:00
|
|
|
elsif ($oid =~ /BLADESPPALT-MIB::spTrapPriority|RSASPPALT-MIB::ibmSpTrapPriority/) {
|
2008-02-28 20:21:35 +00:00
|
|
|
# Critical Alert(0), Major(1), Non-Critical Alert(2), System Alert(4),
|
|
|
|
# Recovery Alert(8), Informational Only Alert(255)
|
|
|
|
if ($value==0) {
|
|
|
|
$severity="Critical Alert";
|
|
|
|
$severity_type="Critical";
|
|
|
|
} elsif ($value==1) {
|
|
|
|
$severity="Major Alert";
|
|
|
|
$severity_type="Critical";
|
|
|
|
} elsif ($value==2) {
|
|
|
|
$severity="Non-Critical Alert";
|
|
|
|
$severity_type="Warning";
|
|
|
|
} elsif ($value==4) {
|
|
|
|
$severity="System Alert";
|
|
|
|
$severity_type="Warning";
|
|
|
|
} elsif ($value==8) {
|
|
|
|
$severity="Recovery Alert";
|
|
|
|
$severity_type="Warning";
|
|
|
|
} elsif ($value==255) {
|
|
|
|
$severity="Informational Alert";
|
|
|
|
$severity_type="Informational";
|
|
|
|
}
|
2008-02-29 03:20:20 +00:00
|
|
|
}
|
|
|
|
#elsif ($oid =~ /enterprises\.3183\.1\.1\.1/) { #IPMI starts here
|
|
|
|
# ;
|
2008-02-29 16:51:03 +00:00
|
|
|
# }
|
2008-02-28 20:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($node1) {$info= getMoreInfo($node1);}
|
|
|
|
|
|
|
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
|
|
|
$datetime=sprintf "%2d-%02d-%04d %02d:%02d:%02d", $mon+1,$mday,$year+1900,$hour,$min,$sec;
|
|
|
|
my $head="SNMP $severity received from $host($ip) on $datetime\n$briefmsg\n";
|
|
|
|
my $middle="Trap details:\n$message\n";
|
|
|
|
my $end;
|
|
|
|
if ($info) {
|
|
|
|
$end ="Additonal Info from xCAT:\n$info\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#TODO: decide responses based on severity. settings in monitoring tb.
|
|
|
|
#email the full message to the alerts aliase
|
|
|
|
my $cmd="echo \'$head$middle$end\' \| mail -s \"$severity_type: Cluster SNMP Alert\!\" $MAILTO";
|
|
|
|
`$cmd`;
|
|
|
|
|
|
|
|
# TODO: log the the brief message from the Blad Center MM to the syslog. For other traps, log all.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
=head3 getMoreInfo
|
|
|
|
This function returns the node module/type, serial number, position etc.
|
|
|
|
Arguments:
|
|
|
|
node-- name of the node.
|
|
|
|
Returns:
|
|
|
|
A string with node info ready to display.
|
|
|
|
=cut
|
|
|
|
#--------------------------------------------------------------------------------
|
|
|
|
sub getMoreInfo {
|
|
|
|
my $node=shift;
|
|
|
|
my $pos,$vpd;
|
|
|
|
|
|
|
|
#get module name and serial number from the xCAT DB.
|
|
|
|
my $table=xCAT::Table->new("vpd", -create =>1);
|
|
|
|
if ($table) {
|
|
|
|
(my $ref) = $table->getAttribs({'node' => $node}, ('serial', 'mtm'));
|
|
|
|
if ($ref) {
|
|
|
|
if($ref->{mtm}) { $vpd .= " Type/Mudule: ". $ref->{mtm} ."\n"; }
|
|
|
|
if($ref->{serial}) { $vpd .= " Serial Number: ". $ref->{serial} ."\n";}
|
|
|
|
}
|
|
|
|
$table->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
# get the info from rinv command if nothing in the vpd table
|
|
|
|
if (!$vpd) {
|
|
|
|
my $result=`$XCATROOT/bin/rinv $node all 2>&1 | egrep -i '(model|serial)' | grep -v Univ`;
|
|
|
|
if ($? == 0) {#success
|
|
|
|
chomp($result);
|
|
|
|
my @b=split(/\n/, $result);
|
|
|
|
foreach (@b) {
|
|
|
|
s/^(.*)\:(.*)\:(.*)$/$2: $3/;
|
|
|
|
$vpd .= " $_\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#get the position
|
|
|
|
my $table1=xCAT::Table->new("nodepos", -create =>1);
|
|
|
|
if ($table1) {
|
|
|
|
(my $ref1) = $table1->getAttribs({'node' => $node}, ('rack', 'u', 'chassis', 'slot', 'room'));
|
|
|
|
if ($ref1) {
|
|
|
|
if($ref1->{room}) { $pos .= " Room: ". $ref1->{room} ."\n"; }
|
|
|
|
if($ref1->{rack}) { $pos .= " Rack: ". $ref1->{rack} ."\n"; }
|
|
|
|
if($ref1->{u}) { $pos .= " Vertial position: ". $ref1->{u} ."\n"; }
|
|
|
|
if($ref1->{chassis}) { $pos .= " Chassis: ". $ref1->{chassis} ."\n"; }
|
|
|
|
if($ref1->{slot}) { $pos .= " Slot: ". $ref1->{slot} ."\n"; }
|
|
|
|
}
|
|
|
|
$table1->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($pos) || ($vpd)) {
|
|
|
|
return " Node: $node\n$vpd$pos";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|