enhanced the filter in snmp trap handling

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1446 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
linggao 2008-05-19 18:51:48 +00:00
parent 41a7e8ba1f
commit cd6baf65a9

View File

@ -23,15 +23,15 @@ use Socket;
# then run newaliases command
my $MAILTO="alerts";
my $message, $briefmsg;
my $pair;
my $message;
my $briefmsg;
my $node1;
my $info;
my $severity_type;
my $severity;
#get settings
$EMAIL=0, $LOG=0, $RUNCMD=0, $INGNORE=0;
$EMAIL=0, $LOG=0, $RUNCMD=0, $IGNORE=0;
%hashI=(),%hashE=(),%hashL=(),%hashR=();
my %settings=xCAT_monitoring::monitorctrl->getPluginSettings("snmpmon");
my $i=$settings{'ignore'};
@ -183,7 +183,7 @@ while ($temp=<STDIN>) {
my $ipmitab = xCAT::Table->new('ipmi');
if (defined($ipmitab)) {
my @tmp1=$ipmitab->getAllNodeAttribs(['node','bmc']);
if (defined(@tmp1) && (@tmp1 > 0)) {
if (@tmp1 && (@tmp1 > 0)) {
foreach(@tmp1) {
if ($_->{bmc} eq $node1) { $realnode=$_->{node}; last;}
}
@ -248,15 +248,11 @@ if ($EMAIL || ((keys(%hashE)==0) && ($severity_type =~/Critical|Warning/))) {
#$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 $head="SNMP $severity received from $host($ip)\n$briefmsg\n";
my $middle="Trap details:\n$message\n";
my $end;
if ($node1) { $info= getMoreInfo($node1);}
if ($info) {
$end ="Additonal Info from xCAT:\n$info\n";
}
my $middle="Trap details:\n$message\n";
#email the full message to the alerts aliase
my $cmd="echo \'$head$middle$end\' \| mail -s \"$severity_type: Cluster SNMP Alert\!\" $MAILTO";
my $cmd="echo \'$info$head\n$middle\' \| mail -s \"$severity_type: Cluster SNMP Alert\!\" $MAILTO";
`$cmd`;
}
@ -297,15 +293,21 @@ if ($RUNCMD) {
#--------------------------------------------------------------------------------
sub getMoreInfo {
my $node=shift;
my $pos,$vpd;
my $pos;
my $vpd;
#get module name and serial number from the xCAT DB.
# get module name and serial number from the xCAT DB.
my $ref;
my $table=xCAT::Table->new("vpd", -create =>1);
if ($table) {
my $ref = $table->getNodeAttribs($node, ['serial', 'mtm']);
if ($ref) {
if($ref->{mtm}) { $vpd .= " Type/Mudule: ". $ref->{mtm} ."\n"; }
if($ref->{serial}) { $vpd .= " Serial Number: ". $ref->{serial} ."\n";}
$vpd .= " Type/Mudule: ";
if ($ref->{mtm}) { $vpd .= $ref->{mtm};}
$vpd .= "\n";
$vpd .= " Serial Number: ";
if ($ref->{serial}) { $vpd .= $ref->{serial};}
$vpd .= "\n";
}
$table->close();
}
@ -322,24 +324,37 @@ sub getMoreInfo {
}
}
}
if (!$vpd) {
$vpd .= " Type/Mudule: \n";
$vpd .= " Serial Number: \n";
}
#get the position
my $table1=xCAT::Table->new("nodepos", -create =>1);
if ($table1) {
my $ref1 = $table1->getNodeAttribs($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"; }
}
$pos .= " Room: ";
if (($ref1) && ($ref1->{room})) { $pos .= $ref1->{room}; }
$pos .= "\n";
$pos .= " Rack: ";
if(($ref1) && ($ref1->{rack})) { $pos .= $ref1->{rack};}
$pos .= "\n";
$pos .= " Unit: ";
if(($ref1) && ($ref1->{u})) { $pos .= $ref1->{u}; }
$pos .= "\n";
$pos .= " Chassis: ";
if(($ref1) && ($ref1->{chassis})) { $pos .= $ref1->{chassis};}
$pos .= "\n";
$pos .= " Slot: ";
if(($ref1) && ($ref1->{slot})) { $pos .= $ref1->{slot};}
$pos .= "\n";
$table1->close();
}
if (($pos) || ($vpd)) {
return " Node: $node\n$vpd$pos";
return " Node: $node\n$vpd$pos\n";
}
return "";
@ -362,10 +377,15 @@ sub parseSettings {
while (($settings =~ s/^(Informational|Warning|Critical|All|None)()(,)*//) ||
($settings =~ s/^([^\=]+)=(\"[^\"]+\")(,)*//) ||
($settings =~ s/^([^\=]+)=([^\"\,]+)(,)*//)) {
# print "$1=$2\n";
$ret{$1}=$2;
#print "$1=$2\n";
if (exists($ret{$1})) {
my $pa=$ret{$1};
push(@$pa, $2);
}
else {
$ret{$1}=[$2];
}
}
return %ret;
}
@ -389,10 +409,15 @@ sub checkWithOid {
if (exists($hashX->{'All'})) { return 1; }
if (exists($hashX->{'None'})) { return 0; }
if (exists($hashX->{$o}) && ($hashX->{$oid} eq $v)) {return 1; }
if (exists($hashX->{$o})) {
$pa= $hashX->{$o};
foreach(@$pa) {
if ($_ eq $v) {return 1; }
}
}
return 0;
}
if ((!$IGNORE) && (keys(%hashI)>0)) {
$IGNORE=checking(\%hashI);
if ($IGNORE) { return;}
@ -414,6 +439,22 @@ sub checkWithOid {