From 6ac3c398c99cd193bf11994cc09278b7adcb38db Mon Sep 17 00:00:00 2001 From: linggao Date: Fri, 21 May 2010 15:25:14 +0000 Subject: [PATCH] snmp monitoring enhancement: added contains =~ in the monsettting table to filter the traps out for certain actions. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6197 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/monitoring/snmpmon.pm | 8 ++-- xCAT-server/sbin/xcat_traphandler | 46 ++++++++++++++++------ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/xCAT-server/lib/xcat/monitoring/snmpmon.pm b/xCAT-server/lib/xcat/monitoring/snmpmon.pm index 06f128b9d..4a9763370 100644 --- a/xCAT-server/lib/xcat/monitoring/snmpmon.pm +++ b/xCAT-server/lib/xcat/monitoring/snmpmon.pm @@ -781,7 +781,7 @@ sub getDescription { Settings: ignore: specifies the events that will be ignored. It's a comma separated pairs of oid=value. For example, - BLADESPPALT-MIB::spTrapAppType=4,BLADESPPALT-MIB::spTrapAppType=4. + spTrapAppType=4,spTrapMsgText=~power,spTrapMsgText=Hello there. email: specifies the events that will get email notification. log: specifies the events that will get logged. runcmd: specifies the events that will be passed to the user defined scripts. @@ -798,9 +798,9 @@ sub getDescription { Informational -- all informational events. For example, you can have the following setting: - email CRITICAL,BLADESPPALT-MIB::pTrapPriority=4 - This means send email for all the critical events and the BladeCenter - system events.\n" + email Critical,spTrapMsgText=~Test this,spTrapMsgText=Hello there + This means send email for all the critical events and events with spTrapMsgText + contains the phrase 'Test this' or equals 'Hello there'.\n" } #-------------------------------------------------------------------------------- diff --git a/xCAT-server/sbin/xcat_traphandler b/xCAT-server/sbin/xcat_traphandler index 116360d4f..e05188618 100755 --- a/xCAT-server/sbin/xcat_traphandler +++ b/xCAT-server/sbin/xcat_traphandler @@ -12,6 +12,7 @@ use xCAT::NetworkUtils; use xCAT_plugin::ipmi; use xCAT_monitoring::monitorctrl; use Socket; +use Data::Dumper; #------------------------------------------------------------------------------- @@ -412,18 +413,23 @@ sub getMoreInfo { sub parseSettings { my $settings=shift; my %ret=(); - while (($settings =~ s/^(Informational|Warning|Critical|All|None)()(,)*//) || - ($settings =~ s/^([^\=]+)=(\"[^\"]+\")(,)*//) || - ($settings =~ s/^([^\=]+)=([^\"\,]+)(,)*//)) { - #print "$1=$2\n"; - if (exists($ret{$1}{'eq'})) { - my $pa=$ret{$1}{eq}; - push(@$pa, $2); + while (($settings =~ s/^(Informational|Warning|Critical|All|None)()()(,)*//) || + ($settings =~ s/^([^\=]+)(=~)(\"[^\"]+\")(,)*//) || + ($settings =~ s/^([^\=]+)(=~)([^\"\,]+)(,)*//) || + ($settings =~ s/^([^\=]+)(=)(\"[^\"]+\")(,)*//) || + ($settings =~ s/^([^\=]+)(=)([^\"\,]+)(,)*//)) { + my $val='eq'; + if ($2 eq "=~") { $val='=~';} + if (exists($ret{$1}{$val})) { + my $pa=$ret{$1}{$val}; + push(@$pa, $3); } else { - $ret{$1}{'eq'}=[$2]; + $ret{$1}{$val}=[$3]; } } + + #print Dumper(%ret); return %ret; } @@ -451,19 +457,37 @@ sub checkWithOid { @a_oid=split('::', $o); my $new_o=$o; if (@a_oid == 2) { $new_o=$a_oid[1]; } - print "o=$o, new_o=$new_o\n"; + #print "o=$o, new_o=$new_o v=$v\n"; + + #check for 'contains' + if (exists($hashX->{$o})) { + my $pa= $hashX->{$o}{'=~'}; + foreach(@$pa) { + if ($v =~ /$_/) {return 1; } + } + } + if (exists($hashX->{$new_o})) { + my $pa= $hashX->{$new_o}{'=~'}; + foreach(@$pa) { + if ($v =~ /$_/) {return 1; } + } + } + + #check for 'equals' if (exists($hashX->{$o})) { my $pa= $hashX->{$o}{'eq'}; foreach(@$pa) { - if ($_ eq $v) {return 1; } + if ($_ eq $v) { return 1; } } } if (exists($hashX->{$new_o})) { my $pa= $hashX->{$new_o}{'eq'}; foreach(@$pa) { - if ($_ eq $v) {return 1; } + if ($_ eq $v) { return 1; } } } + + return 0; }