Browse Source

Add pattern to !nagios list -- ASR

Gaétan RYCKEBOER 10 years ago
parent
commit
6feb1f7f54
2 changed files with 12 additions and 4 deletions
  1. 1 1
      README.md
  2. 11 3
      bin/nagios-fifo.pl

+ 1 - 1
README.md

@@ -23,7 +23,7 @@ all are designed to work standalone.
 
 Commands allowed by nagios-fifo.pl / Nagios module :
 The nagios bot is designed to work with nagios notifications, via commands.cfg configuration file.
-- !nagios list : list of received alerts
+- !nagios list [PATTERN] : list of received alerts
 - !nagios help : l'aide");
 - !nagios ack <#ALERT> <message> 
                : ACK the alert");

+ 11 - 3
bin/nagios-fifo.pl

@@ -418,6 +418,7 @@ Filter: acknowledged = 0
 And: 2" | unixcat $nagioscmd` ) {
 		($d,$host,$service,$state,$output)=split /;/,$unixline;
 		handle_alert($option,$d,'SERVICE',$host,$NagStates[$state+10],$output,$service);
+		chomp $unixline;
 		Irssi::print("%B>>%n $unixline", MSGLEVEL_CLIENTCRAP);
 	}
 
@@ -429,6 +430,7 @@ Filter: acknowledged = 0
 And: 2" | unixcat $nagioscmd` ) {
 		($d,$host,$state,$output)=split /;/,$unixline;
 		handle_alert($option,$d,'HOST',$host,$NagStates[$state],$output,"");
+		chomp $unixline;
 		Irssi::print("%B>>%n $unixline", MSGLEVEL_CLIENTCRAP);
 	}
 }
@@ -545,18 +547,24 @@ sub event_privmsg($$$$) {
 			$server->command ( "msg  ".$nagios_ack_channel.
 				" ".scalar @ACKS." alertes");
 		}
-		elsif ($arg =~ /^list/i) {
+		elsif ($arg =~ /^list ?(.*)/i) {
 			$server->command ( "msg  ".$nagios_ack_channel.
 				" ".scalar @ACKS." alertes");
 			my $i=0;
+			my $grepto;
+			my $togrep="$1";
+			Irssi::print("> ".$togrep);
 			foreach $K (@ACKS) {
+				my $grepto="@$K";
+				Irssi::print("> ".$grepto);
 				$server->command ( "msg  ".$nagios_ack_channel.
-					" ". format_alert_id(' ',$i++,$K->[2]) ." ".$K->[0]." / $K->[1] / $K->[2] / $K->[3] / ".time2date $K->[4]);
+					" ". format_alert_id(' ',$i,$K->[2]) ." ".$K->[0]." / $K->[1] / $K->[2] / $K->[3] / ".time2date $K->[4]) if ($grepto =~ /$togrep/);
+				$i++;
 			}
 		}
 		elsif ($arg =~ /^help/i) {
 			$server->command ( "msg  ".$nagios_ack_channel.
-				" !nagios list : liste des alertes nagios reçues ici");
+				" !nagios list [pattern] :liste des alertes nagios reçues ici");
 			$server->command ( "msg  ".$nagios_ack_channel.
 				" !nagios help : l'aide");
 			$server->command ( "msg  ".$nagios_ack_channel.