|
@@ -89,20 +89,20 @@ my %C = (
|
|
|
Ma => "\x0313", # 12. Light Blue (Royal)
|
|
|
Gr => "\x0314", # 13. Pink (Light Purple) (Fuchsia)
|
|
|
W => "\x0315", # 14. Grey
|
|
|
- # 15. Light Grey (Silver)
|
|
|
+ # 15. Light Grey (Silver)
|
|
|
Z => "\x03",
|
|
|
);
|
|
|
|
|
|
# Numeric to string conversion of nagios status
|
|
|
# 0..4 : hosts
|
|
|
# 10..14 : services
|
|
|
-my @NagStates = qw/UP DOWN WARNING UNKNOWN .. .. .. .. .. ..
|
|
|
+my @NagStates = qw/UP DOWN WARNING UNKNOWN .. .. .. .. .. ..
|
|
|
OK WARNING CRITICAL UNKNOWN/;
|
|
|
|
|
|
# Bold: U+0002 ("0x02") — Example: ^Bold Text^ whereas ^ represents the control character.
|
|
|
# Italics: U+001D ("0x1D") — Example: ^Italicized Text^ whereas ^ represents the control character.
|
|
|
# Underline: U+001F ("0x1F") — Example: ^Underlined Text^ whereas ^ represents the control character.
|
|
|
-# The control character used for color is U+0003 ("0x03").
|
|
|
+# The control character used for color is U+0003 ("0x03").
|
|
|
|
|
|
my $state_to_color = {
|
|
|
OK => $C{G},
|
|
@@ -124,7 +124,7 @@ my ($d,$type,$host,$service,$state,$output);
|
|
|
my ( $host, $svc, $state, $msg, $id );
|
|
|
|
|
|
my ($server, $msg, $nick, $addr, $target);
|
|
|
-my ( $param, $server, $window );
|
|
|
+my ( $param, $server, $window );
|
|
|
my (@issue, $issue);
|
|
|
|
|
|
#my $state_to_color = { OK => '', UP => '', WARNING => '', CRITICAL => '', DOWN => '', UNKNOWN => '' };
|
|
@@ -133,7 +133,7 @@ my (@issue, $issue);
|
|
|
|
|
|
my $last_alert;
|
|
|
|
|
|
-my $DEBUG=Irssi::settings_get_str("nagios_ack_channel");
|
|
|
+my $DEBUG=Irssi::settings_get_str("nagios_ack_channel");
|
|
|
|
|
|
# Simple subs ############################################################
|
|
|
sub TRUE() { 1 } # some constants [perlsyn(1)
|
|
@@ -153,7 +153,7 @@ sub time2date($) {
|
|
|
# where is the memory leak.
|
|
|
|
|
|
# Four unused subs. Still there to be implemented later
|
|
|
-sub parse_status();
|
|
|
+sub parse_status();
|
|
|
sub nagios_ack($$$);
|
|
|
sub nagios_check($$$);
|
|
|
sub nagios_inject;
|
|
@@ -216,9 +216,9 @@ sub event_privmsg ($$$$);
|
|
|
|
|
|
# REFERENCES
|
|
|
# ----------
|
|
|
-#
|
|
|
+#
|
|
|
# This script is mainly adapted from 3 other scripts related to nagios :
|
|
|
-#
|
|
|
+#
|
|
|
# https://github.com/zorkian/nagios-irc-bot/blob/master/nagiosirc.pl
|
|
|
# http://www.update.uu.se/~zrajm/programs/irssi-scripts/fifo_remote.pl-0.5
|
|
|
# https://github.com/mikegrb/irssi-scripts/blob/master/nagios-ack.pl
|
|
@@ -226,7 +226,7 @@ sub event_privmsg ($$$$);
|
|
|
##########################################################################
|
|
|
# CODE ###################################################################
|
|
|
##########################################################################
|
|
|
-
|
|
|
+
|
|
|
##########################################################################
|
|
|
# Part B : user Actions ##################################################
|
|
|
|
|
@@ -294,11 +294,11 @@ sub insert_alert($$$$$) {
|
|
|
if (($ACKS[$i]->[0] eq $host) && ($ACKS[$i]->[1] eq $svc)) {
|
|
|
$ACKS[$i]->[4]=$d;
|
|
|
Irssi::print(">> found $i");
|
|
|
- if ($ACKS[$i]->[2] ne $state) {
|
|
|
+ if ($ACKS[$i]->[2] ne $state) {
|
|
|
# Same alert, but different level
|
|
|
- $ACKS[$i]->[2]=$state;
|
|
|
+ $ACKS[$i]->[2]=$state;
|
|
|
return format_alert_id('C', $i, $state);
|
|
|
- } else {
|
|
|
+ } else {
|
|
|
# Same alert
|
|
|
return format_alert_id('!', $i, $state);
|
|
|
# No need to display...
|
|
@@ -365,7 +365,7 @@ sub open_fifo($) { # [2004-08-14]
|
|
|
fileno($FIFO_HANDLE), INPUT_READ, # there's input in the pipe
|
|
|
\&read_fifo, ''; #
|
|
|
return 1; #
|
|
|
-}
|
|
|
+}
|
|
|
|
|
|
# read from fifo
|
|
|
# (called by fifo input signal)
|
|
@@ -383,7 +383,7 @@ sub read_fifo() { # [2004-08-14]
|
|
|
# TODO: Is the above re-opening of fifo really necessary? -- If not
|
|
|
# invoked here `read_fifo' is called repeatedly, even though no input
|
|
|
# is to be found on the fifo. (This seems a waste of resources to me.)
|
|
|
-}
|
|
|
+}
|
|
|
|
|
|
# create named fifo and open it for input
|
|
|
# (called on script load and fifo name changes)
|
|
@@ -391,7 +391,7 @@ sub create_fifo($) { # [2004-08-14]
|
|
|
my ($new_fifo) = @_; # get args
|
|
|
if (not -p $new_fifo) { # create fifo if non-existant
|
|
|
if (system "mkfifo '$new_fifo' &>/dev/null" and
|
|
|
- system "chmod 777 '$new_fifo' &>/dev/null" and
|
|
|
+ system "chmod 777 '$new_fifo' &>/dev/null" and
|
|
|
system "mknod '$new_fifo' &>/dev/null"){
|
|
|
print CLIENTERROR "`mkfifo' failed -- could not create named pipe";
|
|
|
# TODO: capture `mkfifo's stderr and show that here
|
|
@@ -408,7 +408,7 @@ sub create_fifo($) { # [2004-08-14]
|
|
|
sub nagios_query_status($){
|
|
|
# 1412478149;hyppocampe;apt;2;CRITICAL : unknown: qemu-utils, qemu-kvm, qemu-keymaps
|
|
|
my ($option)=@_;
|
|
|
- my @unixcat;
|
|
|
+ my @unixcat;
|
|
|
my $unixline;
|
|
|
$nagioscmd = Irssi::settings_get_str("nagios_command");
|
|
|
foreach $unixline ( `echo "GET services
|
|
@@ -453,7 +453,7 @@ sub parse_nagios_log($){
|
|
|
# HOST ########################
|
|
|
($d,$host,$state,$output)=@match;
|
|
|
handle_alert($option,$d,"HOST",$host,$state,$output,$service);
|
|
|
-
|
|
|
+
|
|
|
# SERVICE #####################
|
|
|
} elsif (@match=$status_line =~ /\[?(\d+)\]? (\w+) ALERT: ([^;@]+)[@;]([^;@]+)[@;]([^;@]+)[@;]HARD[@;][^;@]*[@;](.+)/) {
|
|
|
($d,$type,$host,$service,$state,$output)=@match;
|
|
@@ -486,7 +486,7 @@ sub handle_alert($$$$$$$) { # $d,$type,$host,$state,$output,$service
|
|
|
# HOST or SERVICE ?
|
|
|
$id = insert_alert($host,$service,$state,$output,$d);
|
|
|
$msg = "$id".$state_to_color->{$state} . "$host:$service".$C{Z}." is $state : $output";
|
|
|
- #Irssi::print( "%B>>%n $IRSSI{name} $msg", MSGLEVEL_CLIENTCRAP);
|
|
|
+ #Irssi::print( "%B>>%n $IRSSI{name} $msg", MSGLEVEL_CLIENTCRAP);
|
|
|
|
|
|
$last_alert="NAGIOS - $host/$service is $state";
|
|
|
$d=time2date($d);
|
|
@@ -496,7 +496,7 @@ sub handle_alert($$$$$$$) { # $d,$type,$host,$state,$output,$service
|
|
|
$nagios_ack_channel= Irssi::settings_get_str("nagios_ack_channel");
|
|
|
Irssi::active_server->command('MSG ' . $nagios_ack_channel .
|
|
|
" ".$message) unless ($option eq "silent");
|
|
|
- # Irssi::print( "%B>>%n $IRSSI{name} $msg", MSGLEVEL_CLIENTCRAP);
|
|
|
+ # Irssi::print( "%B>>%n $IRSSI{name} $msg", MSGLEVEL_CLIENTCRAP);
|
|
|
}
|
|
|
|
|
|
##########################################################################
|
|
@@ -530,8 +530,8 @@ sub event_privmsg($$$$) {
|
|
|
return if $target ne $nagios_ack_channel ;
|
|
|
|
|
|
# !nagios [*] :
|
|
|
-
|
|
|
- # !nagios list [*] :
|
|
|
+
|
|
|
+ # !nagios list [*] :
|
|
|
if ($arg =~ /^refresh ?(.*)/i) {
|
|
|
$arg=$1;
|
|
|
Irssi::print(">> $arg");
|
|
@@ -610,9 +610,9 @@ print CLIENTCRAP "%B>>%n $IRSSI{name} $VERSION (by $IRSSI{authors}) loaded";
|
|
|
##########################################################################
|
|
|
# REFERENCES
|
|
|
# ----------
|
|
|
-#
|
|
|
+#
|
|
|
# This script is mainly adapted from 3 other scripts related to nagios :
|
|
|
-#
|
|
|
+#
|
|
|
# https://github.com/zorkian/nagios-irc-bot/blob/master/nagiosirc.pl
|
|
|
# http://www.update.uu.se/~zrajm/programs/irssi-scripts/fifo_remote.pl-0.5
|
|
|
# https://github.com/mikegrb/irssi-scripts/blob/master/nagios-ack.pl
|