Browse Source

Add comments, README, and installation files -- ASR

Gaétan RYCKEBOER 10 years ago
parent
commit
77f2612572
5 changed files with 98 additions and 7 deletions
  1. 34 0
      README
  2. 13 0
      README.md
  3. 13 7
      bin/nagios-fifo.pl
  4. 37 0
      bin/nagios-irssi.pl
  5. 1 0
      bin/tc-14.pl

+ 34 - 0
README

@@ -0,0 +1,34 @@
+Quick install in 3 words
+
+* Check the symlinks
+* put nagios-irssi.pl into /usr/local/bin
+* modify config file (to be put on ~.irssi/) to match your configuration
+* put scripts .pl into ~/.irssi/scripts/autorun
+
+Add to nagios commands :
+# 'notify-host-by-irssi' command definition
+define command{
+        command_name    notify-host-by-irssi
+        command_line    /usr/local/bin/nagios-irssi.pl $CONTACTPAGER$ "[$LASTHOSTSTATECHANGE$] HOST ALERT: $HOSTNAME$@$HOSTSTATE$@HARD@1@$HOSTOUTPUT$"
+}
+
+define command{
+        command_name    notify-service-by-irssi
+        command_line    /usr/local/bin/nagios-irssi.pl $CONTACTPAGER$ "[$LASTSERVICESTATECHANGE$] SERVICE ALERT: $HOSTALIAS$@$SERVICEDESC$@$SERVICESTATE$@HARD@1@$SERVICEOUTPUT$"
+}
+
+Add to /etc/nagios3/<placeholder>.cfg
+define contact {
+        contact_name                    TC-14
+        service_notification_period     24x7
+        alias                           IRSSI Bot
+        #service_notification_options   w,c,u,r,s
+        #host_notification_options      d,u,r,s
+        service_notification_options    c,r
+        host_notification_options       d,u,r,s
+        email                           tc-14@yoursystem.com
+        service_notification_commands   notify-service-by-irssi
+        host_notification_commands      notify-host-by-irssi
+        pager                           /home/tc-14/var/nagios-fifo
+}
+

+ 13 - 0
README.md

@@ -14,4 +14,17 @@ respective irssi directories :
 5/ symlink it to etc/config.local
 6/ start "screen irssi"
 
+The bot is made of 3 scripts :
+- nagios bot ;
+- tweet.pl made to tweet, take care of a changelog ;
+- tc-14 a simple talkeng droid.
+
+Commands allowed inside a chan are :
+- !nagios list : liste des alertes nagios reçues ici");
+- !nagios help : l'aide");
+- !nagios ack <#ALERTE> <message> : aquitte l'alerte");
+- !nagios check <#ALERTE> : recheck une alerte donnée (service/host)");
+- !nagios refresh [silent] : interroge le nagios pour avoir la liste de toutes les alertes");
+
+The nagios bot is designed to work with nagios notifications 
 

+ 13 - 7
bin/nagios-fifo.pl

@@ -297,10 +297,10 @@ sub insert_alert($$$$$) {
 				if ($ACKS[$i]->[2] ne $state) { 
 					# Same alert, but different level
 					$ACKS[$i]->[2]=$state; 
-					return mark ('C', $i, $state);
+					return format_alert_id('C', $i, $state);
 				} else { 
 					# Same alert
-					return mark ('!', $i, $state);
+					return format_alert_id('!', $i, $state);
 					# No need to display...
 				}
 			}
@@ -413,7 +413,9 @@ sub nagios_query_status($){
 	$nagioscmd = Irssi::settings_get_str("nagios_command");
         foreach $unixline ( `echo "GET services
 Columns: last_state_change host_name display_name state plugin_output
-Filter: state > 1" | unixcat $nagioscmd` ) {
+Filter: state > 0
+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);
 		Irssi::print("%B>>%n $unixline", MSGLEVEL_CLIENTCRAP);
@@ -422,7 +424,9 @@ Filter: state > 1" | unixcat $nagioscmd` ) {
 	return;
         foreach $unixline ( `echo "GET hosts
 Columns: last_state_change host_name state plugin_output
-Filter: state > 1" | unixcat $nagioscmd` ) {
+Filter: state > 0
+Filter: acknowledged = 0
+And: 2" | unixcat $nagioscmd` ) {
 		($d,$host,$state,$output)=split /;/,$unixline;
 		handle_alert($option,$d,'HOST',$host,$NagStates[$state],$output,"");
 		Irssi::print("%B>>%n $unixline", MSGLEVEL_CLIENTCRAP);
@@ -437,19 +441,21 @@ Filter: state > 1" | unixcat $nagioscmd` ) {
 sub parse_nagios_log($){
 	my $option="";
 	$d=0; $status_line=""; $host="";$output="";$service="";
+	$status_line=shift;
 
 	### log :
 	# [1412330770] SERVICE ALERT: ella;IMAPs_LOGIN;OK;SOFT;2;OK - CO1N OK LOGIN Ok.
 	# /\[\d+\] (\w+) ALERT: (\w+);(\w+);(\w+);HARD;(\d+);(.+)/
 	# [1410969598] HOST ALERT: filou;DOWN;SOFT;1;PING CRITICAL -  Paquets perdus = 100%
 	# [TIMESTAMP] PROCESS type ALERT: host;service;STATE1;HARD;num;commentaire
-	if (@match=$status_line =~ /\[?(\d+)\]? HOST ALERT: ([^@;]+)[@;](\w+)[@;]HARD[@;].*[@;](.+)/) {
+
+	if (@match=$status_line =~ /\[?(\d+)\]? HOST ALERT: ([^@;]+)[@;]([^;@]+)[@;]HARD[@;][^;@]*[@;](.+)/) {
 	# HOST ########################
 		($d,$host,$state,$output)=@match;
 		handle_alert($option,$d,"HOST",$host,$state,$output,$service);
 		
 	# SERVICE #####################
-	} elsif (@match=$status_line =~ /\[?(\d+)\]? (\w+) ALERT: ([^;@]+)[@;]([^;@]+)[@;](\w+)[@;]HARD[@;].*[@;](.+)/) {
+	} elsif (@match=$status_line =~ /\[?(\d+)\]? (\w+) ALERT: ([^;@]+)[@;]([^;@]+)[@;]([^;@]+)[@;]HARD[@;][^;@]*[@;](.+)/) {
 		($d,$type,$host,$service,$state,$output)=@match;
 
 		$service=~s/[^\w\d_-]/_/g;
@@ -462,7 +468,7 @@ sub parse_nagios_log($){
 	# FALLBACK ####################
 	} else {
 		Irssi::print(                          #
-		    "%B>>%n $IRSSI{name} received command: \"$_\"",
+		    "%B>>%n $IRSSI{name} received message: \"$_\"",
 		    MSGLEVEL_CLIENTCRAP);              #
 		next
 	}

+ 37 - 0
bin/nagios-irssi.pl

@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+# asr - Gaetan Ryckeboer - 2014
+#
+# Nagios notification to irssi handler
+# Based on capture_plugin.pl v1.0 from Wolfgang Wagner, 2007.
+#
+
+use strict;
+
+my $FIFO="/home/tc-14/var/nagios-fifo";
+$FIFO = shift;
+
+# This plugin does not need any nagios utils. It just interfaces the original plugin.
+
+my ($cmd, $ret_code, $output);
+# First display all arguments
+my ($numArgs, $argnum);
+$numArgs = $#ARGV + 1;
+
+# create the command-line
+
+$cmd = "";
+$cmd = join " ", @ARGV;
+#print "$cmd\n";
+
+# log the start, output, retcode & end
+
+my $LogFile;
+# open could be better: check success later; if unsuccessful return UNKNWON to Nagios
+open (LogFile, ">>$FIFO") || die ("Cannot open logfile");
+print LogFile "$cmd\n";
+close(LogFile);
+# avoid access problems for others.
+#chmod 0777, $LOG_FILE;
+
+exit 1;

+ 1 - 0
bin/tc-14.pl

@@ -21,6 +21,7 @@ $VERSION = "1.2.4";
     license => 'GNU GPL v2 or later',
     url => 'http://www.lautre.net/',
 );
+# those 4 files contains random quotes. One per line.
 open ( CLOCKE, "<.irssi/randyes" ) or die "can't open randyes:$!\n";
 chomp( @randyes = <CLOCKE> );
 close CLOCKE;