Browse Source

Add "clear" parameter to !nagios refresh -- asr

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

+ 1 - 1
README.md

@@ -35,7 +35,7 @@ The nagios bot is designed to work with nagios notifications, via commands.cfg c
 - `!nagios help` : l'aide
 - `!nagios ack #<ALERT> <message>` : ACK the alert
 - `!nagios check <#ALERT>`(todo) : recheck any alert (service/host)
-- `!nagios refresh [silent]` : request nagios livestatus and import all unack alerts
+- `!nagios refresh [silent] [clear]` : request nagios livestatus and import all unack alerts ; optionnaly clear local alerts cache (bot, not nagios)
 
 Commands allowed by *tc-14.pl* / Dumb module :
 - `!status`      to have a look on inner variables / structures (particularly for the bingo module)

+ 9 - 3
bin/nagios-fifo.pl

@@ -35,7 +35,7 @@ our ( $FIFO,        # fifo absolute filename (expanded from Irssi config)
       $FIFO_HANDLE, # fifo filehandle for `open' et al.
       $FIFO_TAG );  # fifo signal tag for `input_add'
 
-$VERSION = "0.4.0";
+$VERSION = "0.4.1";
 %IRSSI = (
     authors     => 'asr',
     contact     => 'root@lautre.net',
@@ -279,6 +279,7 @@ sub nagios_ack($$$) {
 		`$PRINTF "[\%lu] ACKNOWLEDGE_HOST_PROBLEM;$ACKS[$id]->[0];2;0;1;nagiosadmin;$message" $i > $nagioscmd`
 		);
 	}
+	$ACKS[$id]->[5] = 1;
 	Irssi::active_server->command('MSG ' . $nagios_ack_channel . $msg);
     } else {
 	$server->command ( "msg  ".$nagios_ack_channel. " Usage : !nagios ACK #<alert_num> <ack message to be sent to nagios>. Please validate first, with a !nagios list #<alert_num>");
@@ -594,7 +595,11 @@ sub event_privmsg($$$$) {
 		if ($arg =~ /^refresh ?(.*)/i) {
 			$arg=$1;
 			Irssi::print(">> $arg");
-			if ($arg =~ /^silent/) {
+			if ($arg =~ /\bclear\b/) {
+				$server->command ( "msg  ".$nagios_ack_channel." Local alerts cleared" );
+				@ACKS=();
+			}
+			if ($arg =~ /\bclear\b/) {
 				nagios_query_status("silent");
 			} else {
 				nagios_query_status("");
@@ -642,7 +647,8 @@ sub event_privmsg($$$$) {
 			$server->command ( "msg  ".$nagios_ack_channel.
 				" !nagios check <#ALERTE> TODO : recheck une alerte donnée (service/host)");
 			$server->command ( "msg  ".$nagios_ack_channel.
-				" !nagios refresh [silent] : interroge le nagios pour avoir la liste de toutes les alertes");
+				" !nagios refresh [silent] [clear] : interroge le nagios pour avoir la liste de toutes les alertes");
+				"                                    si le mot clef 'clear' est ajouté, il purge les alertes locales");
 		} elsif ( $arg =~ /^check ?(.*)/i ){
 			nagios_check($1,$server,undef);
 		} elsif ( $arg =~ /^ack ?(.*)/i ){