From 14b59574293e6f771c93cea78308f1fa8262c0f5 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Sep 2016 14:54:05 +0200 Subject: [PATCH 01/16] Add script --- galanga/nagios-irc-bot.pl | 474 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 474 insertions(+) create mode 100755 galanga/nagios-irc-bot.pl diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl new file mode 100755 index 0000000..32285ae --- /dev/null +++ b/galanga/nagios-irc-bot.pl @@ -0,0 +1,474 @@ +#!/usr/bin/perl -w +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Status Bot +# +# The Initial Developer of the Original Code is David D. Miller. +# Portions developed by David D. Miller are Copyright (C) 2002-3 +# David D. Miller. All Rights Reserved. +# +# Contributor(s): David Miller +# Mark Smith +# + +use strict; +use Net::IRC; +use POSIX "sys_wait_h"; +use Term::ANSIColor qw/ :constants /; + +# +# Create the IRC and Connection objects +# + +my $version = "BZBot v1.3 - Modified for use with Nagios."; +my $irc = new Net::IRC; + +#open IPADDR, "; +#chomp ($ipaddr); +#close IPADDR; + +# CONFIG: point this where your Nagios configuration files live +my $nagioslog = "/var/log/icinga/icinga.log"; +my $nagioscmd = "/var/lib/icinga/rw/icinga.cmd"; + +open NAGIOS, "<$nagioslog" or die "failed to open $nagioslog: $!\n"; +seek NAGIOS, 0, 2; # seek to end + +my @cmdqueue = (); +my %ignore = (); +my $ACKCT = 0; +my @ACKS; + +print "Creating connection to IRC server...\n"; + +my $conn; +while (!$conn) { + # CONFIG: you have to tell us where to get on IRC + $conn = $irc->newconn(Server => 'irc.freenode.net', + Port => 6667, + SSL => 0, + Nick => 'vivivi', + Ircname => 'April Nagios alerts', + Username => 'vivivi') + or print "Redialing...\n"; + sleep 1; +} + +print "Connection created.\n"; +$conn->debug(1); +my $laststat = time; +my $identified_to_nickserv = 0; + +# +# Handler subs +# + +# What to do when the bot successfully connects. +sub on_connect { + my $self = shift; + + $identified_to_nickserv = 1; + print "Joining #april-monitoring...\n"; + + # FIXME: this is broken right now. when this is re-added, it has to happen + # before we try to join channels. + #print "Identifying to NickServ...\n"; + #$self->privmsg('nickserv',"identify xxx"); + + # CONFIG: channels you want us to announce to ... + $self->join("#april-monitoring"); + #$self->join("#status"); +} + +# Handles some messages you get when you connect +sub on_init { + my ($self, $event) = @_; + my (@args) = ($event->args); + shift (@args); + + print "*** @args\n"; +} + +# What to do when someone leaves a channel the bot is on. +sub on_part { + my ($self, $event) = @_; + my ($channel) = ($event->to)[0]; + + printf "*** %s has left channel %s\n", $event->nick, $channel; +} + +# What to do when someone joins a channel the bot is on. +sub on_join { + my ($self, $event) = @_; + my ($channel) = ($event->to)[0]; + my ($nick, $userhost) = ($event->nick, $event->userhost); + + printf "*** %s (%s) has joined channel %s\n", + $nick, $userhost, $channel; +} + +# What to do when we receive a private PRIVMSG. +sub on_msg { + my ($self, $event) = @_; + my ($nick) = $event->nick; + my ($arg) = ($event->args); + + print "*$nick* ", ($event->args), "\n"; + if ($arg =~ /Go away/i) { # Tell him to leave, and he does. + $self->quit("Yow!!"); + exit 0; + # CONFIG: if you don't change this, anybody can restart your IRC bot at will + # if they've seen this ... + } elsif ($arg =~ /restart ya dope/) { + $self->quit("Regrouping"); + exec $0; + } else { + $self->privmsg($nick, "Yo!"); + } +} + +# What to do when we receive channel text. +sub on_public { + my ($self, $event) = @_; + my @to = $event->to; + my ($nick, $mynick) = ($event->nick, $self->nick); + my ($arg) = ($event->args); + + # Note that $event->to() returns a list (or arrayref, in scalar + # context) of the message's recipients, since there can easily be + # more than one. + + # FIXME: the logging gets spammy ... do we actually want to log to stdout? + print "<$nick> $arg\n"; + + if ($arg =~ /^$mynick[,: ]/i) { + if ($arg =~ /^$mynick[,: ]\s*ignore (.+)\s*$/i) { + $ignore{$1} = 1; + $self->privmsg([ @to ], "$nick: ok, ignoring notifications about $1"); + } elsif ($arg =~ /^$mynick[,: ]\s*ignore$/i) { + if (keys %ignore) { + foreach my $i (keys %ignore) { + $self->privmsg([ @to ], "$nick: ignoring $i"); + } + $self->privmsg([ @to ], "$nick: end of list"); + } else { + $self->privmsg([ @to ], "$nick: I'm not currently ignoring any notifications"); + } + } elsif ($arg =~ /^$mynick[,: ]\s*unignore (.+)\s*$/i) { + if (!exists($ignore{$1})) { + $self->privmsg([ @to ], "$nick: notifications about $1 weren't being ignored anyway."); + } else { + delete $ignore{$1}; + $self->privmsg([ @to ], "$nick: ok, notifications about $1 no longer being ignored."); + } + } elsif ($arg =~ /^$mynick[,: ]+(?:\s*ack\s*)?(\d+)(?:\s*ack\s*)?[:\s]+([^:]+)\s*$/) { + open CMDPIPE,">",$nagioscmd; + my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; + if ( defined $host && defined $svc ) { + printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$host,$svc,$nick,$2; + } elsif ( defined $host ) { + printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$host,$nick,$2; + } + close CMDPIPE; + } elsif ($arg =~ /^$mynick[,: ]\s*ack ([^:]+):([^:]+)\s*$/) { + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$1,$nick,$2; + close CMDPIPE; + } elsif ($arg =~ /^$mynick[,: ]\s*ack ([^:]+):([^:]+):([^:]+)\s*$/) { + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$1,$2,$nick,$3; + close CMDPIPE; + } elsif ($arg =~ /^$mynick[,: ]\s*unack (\d+)$/) { + open CMDPIPE,">",$nagioscmd; + my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; + if ( defined $host && defined $svc ) { + printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$host,$svc; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host:$svc has been removed."); + } elsif ( defined $host ) { + printf CMDPIPE "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",time(),$host; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host has been removed."); + } + close CMDPIPE; + } elsif ($arg =~ /^$mynick[,: ]\s*unack ([^:]+)\s*$/) { + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",time(),$1; + close CMDPIPE; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1 has been removed."); + } elsif ($arg =~ /^$mynick[,: ]\s*unack ([^:]+):([^:]+)\s*$/) { + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$1,$2; + close CMDPIPE; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1:$2 has been removed."); + } elsif ($arg =~ /^$mynick[,: ]\s*status (\S.*?)\s*$/) { + my @lines = (); + open CMDPIPE,"-|","/usr/local/bin/nag-stat",$1; + while () { + chomp; + push @lines, $_; + } + close CMDPIPE; + foreach my $line (@lines) { + $self->privmsg([ @to ], "$nick: $line"); + } + } elsif ($arg =~ /^$mynick[,: ]\s*help/i) { + $self->privmsg([ @to ], "$nick: You're right, I need help!"); + } elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) { + $self->privmsg([ @to ], "Yo, $nick!"); + } else { +# $self->privmsg([ @to ], "Yo!"); + } + } +} + +# Prints the names of people in a channel when we enter. +sub on_names { + my ($self, $event) = @_; + my (@list, $channel) = ($event->args); # eat yer heart out, mjd! + + # splice() only works on real arrays. Sigh. + ($channel, @list) = splice @list, 2; + + print "Users on $channel: @list\n"; +} + +sub on_ping { + my ($self, $event) = @_; + $self->sl("PONG " . join(' ', ($event->args))); +} + +sub on_pong { + my ($self, $event) = @_; + # don't really need to do anything, just update the time. +} + +# Yells about incoming CTCP PINGs. +sub on_ctcpping { + my ($self, $event) = @_; + my $nick = $event->nick; + + $self->ctcp_reply($nick, join (' ', ($event->args))); + print "*** CTCP PING request from $nick received\n"; +} + +# Yells about incoming CTCP VERSIONs. +sub on_ctcpversion { + my ($self, $event) = @_; + my $nick = $event->nick; + + $self->ctcp_reply($nick, join (' ', ($event->args, $version))); + print "*** CTCP VERSION request from $nick received\n"; +} + +# Gives lag results for outgoing PINGs. +sub on_ping_reply { + my ($self, $event) = @_; + my ($args) = ($event->args)[1]; + my ($nick) = $event->nick; + + $args = time - $args; + print "*** CTCP PING reply from $nick: $args sec.\n"; +} + +# Change our nick if someone stole it. +sub on_nick_taken { + my ($self) = shift; + my ($nick,$num) = $self->nick =~ /^(.+)(\d+)?$/; + $num ||= 0; + $self->nick($nick . ($num + 1)); +} + +# Display formatted CTCP ACTIONs. +sub on_action { + my ($self, $event) = @_; + my ($nick, @args) = ($event->nick, $event->args); + + print "* $nick @args\n"; +} + +# Reconnect to the server when we die. +sub on_disconnect { + my ($self, $event) = @_; + + print "Disconnected from ", $event->from(), " (", + ($event->args())[0], "). Attempting to reconnect...\n"; + $identified_to_nickserv = 0; + while (!$self->connected) { + $self->connect(); + if (!$self->connected) { print "Redialing...\n" } + } +} + +# Look at the topic for a channel you join. +sub on_topic { +} + +sub on_notice { + my ($self, $event) = @_; + + my @args = $event->args(); + + # FIXME: the nickserv path is broken ... + if ((lc($event->nick) eq "nickserv") && ($args[0] =~ "nickname is registered")) { +# print "Identifying to NickServ...\n"; +# $self->privmsg('nickserv',"identify xxx"); + } + + # FIXME: the nickserv path is broken ... + if ((lc($event->nick) eq "nickserv") && ($args[0] =~ "You are now identified")) { + #nickserv identification successful, so let's join channels. + $identified_to_nickserv = 1; + print "Joining channels...\n"; + + # CONFIG: channels that should be joined go here. + $self->join("#april-monitoring"); + } +} + +sub ackable { + my ( $host, $svc, $state, $msg ) = @_; + return '' unless $state eq 'WARNING' || $state eq 'CRITICAL' || $state eq 'UNKNOWN' || $state eq 'DOWN'; + + my $id = $ACKCT++ % 100; + $ACKS[$id] = [ $host, $svc, $state, $msg ]; + return sprintf( '[%02d] ', $id ); +} + +print "Installing handler routines..."; + +$conn->add_global_handler('ping', \&on_ping); +$conn->add_global_handler('pong', \&on_pong); +$conn->add_handler('cping', \&on_ctcpping); +$conn->add_handler('crping', \&on_ping_reply); +$conn->add_handler('cversion', \&on_ctcpversion); +$conn->add_handler('msg', \&on_msg); +$conn->add_handler('public', \&on_public); +$conn->add_handler('caction', \&on_action); +$conn->add_handler('join', \&on_join); +$conn->add_handler('part', \&on_part); +#$conn->add_handler('topic', \&on_topic); +$conn->add_handler('notopic', \&on_topic); +$conn->add_handler('notice', \&on_notice); + +$conn->add_global_handler([ 251,252,253,254,302,255 ], \&on_init); +$conn->add_global_handler('disconnect', \&on_disconnect); +$conn->add_global_handler(376, \&on_connect); +$conn->add_global_handler(433, \&on_nick_taken); +$conn->add_global_handler(353, \&on_names); + +print " done.\n"; + +my %C = ( + W => "\x0315", + B => "\x032", + G => "\x033", + R => "\x034", + O => "\x037", + C => "\x0311", + Y => "\x038", + N => "\x0315", +); + +my $state_to_color = { + OK => $C{G}, + WARNING => $C{Y}, + CRITICAL => $C{R}, + UNKNOWN => $C{C}, +}; + +print "starting...\n"; + +my %renot; # { "host" or "host:service" => time_last_notification } +while (1) { + $irc->do_one_loop(); + + if ($identified_to_nickserv) { + # CONFIG: change where we announce stuff here + my @channels = ('#april-monitoring'); + while (defined (my $line = )) { + print $line; + chomp($line); + if ($line =~ /^\[\d+\] (HOST|SERVICE) NOTIFICATION: (.+)$/) { + my ($type, $msg) = ($1, $2); + my ($who, $host, $service, $state, $how, $output); + if ($type eq "HOST") { + ($who, $host, $state, $how, $output) = split(";",$msg,5); + next if exists $renot{$host} && $renot{$host} >= time() - 5; + $renot{$host} = time(); + + my $id = ackable($host,undef,$state,$output); + $msg = $state_to_color->{$state} . "$id$host is $state: $output"; + } + else { + ($who, $host, $service, $state, $how, $output) = split(";",$msg,6); + next if exists $renot{"$host:$service"} && $renot{"$host:$service"} >= time() - 5; + $renot{"$host:$service"} = time(); + + my $id = ackable($host,$service,$state,$output); + $msg = $state_to_color->{$state} . "$id$host:$service is $state: $output"; + } + $service ||= ""; + + # alerts can be separated by who they're for (which group is getting it) +#if ($who eq "mark") { push @channels, "#dw_ops", "#dw_work" } + + if ((!grep { $_ eq "$host:$service" } keys %ignore) && + (!grep { $_ eq "$host" } keys %ignore)) { + $conn->privmsg($_,"$msg") foreach @channels; + } +#[1310493492] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;gearmanworker-gearmanworker3;1310492897;1310500097;1;0;28800;stumble.barr;rebooting + } elsif ($line =~ /EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;(.+?);(\d+);(\d+);\d+;\d+;\d+;(.+?);(.+)$/) { + my $ns = $3 - $2; + $conn->privmsg($_, "Downtime (${ns}s) scheduled for host $1 by $4: $5") + foreach @channels; + } elsif ($line =~ /EXTERNAL COMMAND: SCHEDULE_SVC_DOWNTIME;(.+?);(.+?);(\d+);(\d+);\d+;\d+;\d+;(.+?);(.+)$/) { + my $ns = $4 - $3; + $conn->privmsg($_, "Downtime (${ns}s) scheduled for service $1: $2 by $5: $6") + foreach @channels; + } elsif ($line =~ /EXTERNAL COMMAND: (EN|DIS)ABLE_HOST_(SVC_)?NOTIFICATIONS;(.+)$/) { + my $type = $2 ? 'All service' : 'Host'; + my $verb = $1 eq 'EN' ? "$C{G}enabled$C{N}" : "$C{R}disabled$C{N}"; + $conn->privmsg($_, "$type notifications $verb: $C{O}$3") + foreach @channels; + } elsif ($line =~ /EXTERNAL COMMAND: (EN|DIS)ABLE_(SVC_)?NOTIFICATIONS;(.+?);(.+)$/) { + my $verb = $1 eq 'EN' ? "$C{G}enabled$C{N}" : "$C{R}disabled$C{N}"; + $conn->privmsg($_, "Service notifications $verb on $C{O}$3$C{N}: $C{O}$4") + foreach @channels; + } elsif ($line =~ /HOST DOWNTIME ALERT: (.+?);(.+?);/) { + my $vb = { CANCELLED => 'been manually removed from', STOPPED => 'exited from', STARTED => 'entered' }->{$2}; + $conn->privmsg($_, "Host $C{O}$1$C{N} has $vb scheduled downtime.") + foreach @channels; + } elsif ($line =~ /SERVICE DOWNTIME ALERT: (.+?);(.+?);(.+?);/) { + my $vb = { CANCELLED => 'been manually removed from', STOPPED => 'exited from', STARTED => 'entered' }->{$3}; + $conn->privmsg($_, "Service $C{O}$1$C{N}: $C{O}$2$C{N} has $vb scheduled downtime.") + foreach @channels; + } + } + + if ((time - $laststat) > 30) { + # we don't want to constantly stat the file or we'll hammer the disk. + # keep it to once every 30 seconds. Here we compare the inode of the + # file we have open and the file at the path we're expecting and see + # if they match. If they don't, then the log has been rotated, so we + # close and reopen it to pick up the new logfile. We also only do it + # if we don't read a line from the file, so that way we make sure + # actually gotten to the end of the current file before we check for + # a rotation. + $laststat = time; + if ((stat NAGIOS)[1] != (stat $nagioslog)[1]) { + close NAGIOS; + open NAGIOS, "<$nagioslog"; + } + } + } +} + From a4b0e0927ebcc4af3a11adb9db2e3d3eaee3e137 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Sep 2016 15:05:57 +0200 Subject: [PATCH 02/16] Update channel name --- galanga/nagios-irc-bot.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 32285ae..f8c87e5 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -78,7 +78,7 @@ sub on_connect { my $self = shift; $identified_to_nickserv = 1; - print "Joining #april-monitoring...\n"; + print "Joining #april-admin...\n"; # FIXME: this is broken right now. when this is re-added, it has to happen # before we try to join channels. @@ -86,7 +86,7 @@ sub on_connect { #$self->privmsg('nickserv',"identify xxx"); # CONFIG: channels you want us to announce to ... - $self->join("#april-monitoring"); + $self->join("#april-admin"); #$self->join("#status"); } @@ -330,7 +330,7 @@ sub on_notice { print "Joining channels...\n"; # CONFIG: channels that should be joined go here. - $self->join("#april-monitoring"); + $self->join("#april-admin"); } } @@ -393,7 +393,7 @@ while (1) { if ($identified_to_nickserv) { # CONFIG: change where we announce stuff here - my @channels = ('#april-monitoring'); + my @channels = ('#april-admin'); while (defined (my $line = )) { print $line; chomp($line); From 9f7533ed4c050aa131fd98d46e3f9c4e2a847fd3 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Sep 2016 15:56:45 +0200 Subject: [PATCH 03/16] Update bot --- galanga/nagios-irc-bot.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index f8c87e5..18bd9a1 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -406,6 +406,9 @@ while (1) { $renot{$host} = time(); my $id = ackable($host,undef,$state,$output); + $output =~ s/^\s*CRITICAL\s*//g; + $output =~ s/^\s*WARNING\s*//g; + $output =~ s/^\s*OK\s*//g; $msg = $state_to_color->{$state} . "$id$host is $state: $output"; } else { From 33b81de014f617b68d61ea6ae75b8173b37c8799 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Sep 2016 16:17:07 +0200 Subject: [PATCH 04/16] Update --- galanga/nagios-irc-bot.pl | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 18bd9a1..6dbf1c5 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -78,7 +78,7 @@ sub on_connect { my $self = shift; $identified_to_nickserv = 1; - print "Joining #april-admin...\n"; + print "Joining #april-monitoring...\n"; # FIXME: this is broken right now. when this is re-added, it has to happen # before we try to join channels. @@ -86,7 +86,7 @@ sub on_connect { #$self->privmsg('nickserv',"identify xxx"); # CONFIG: channels you want us to announce to ... - $self->join("#april-admin"); + $self->join("#april-monitoring"); #$self->join("#status"); } @@ -151,11 +151,11 @@ sub on_public { # FIXME: the logging gets spammy ... do we actually want to log to stdout? print "<$nick> $arg\n"; - if ($arg =~ /^$mynick[,: ]/i) { - if ($arg =~ /^$mynick[,: ]\s*ignore (.+)\s*$/i) { + if ($arg =~ /^$mynick[,: ]/i || $arg =~ /^!/ ) { + if ($arg =~ /^(?:$mynick[,: ]|!)\s*ignore (.+)\s*$/i) { $ignore{$1} = 1; $self->privmsg([ @to ], "$nick: ok, ignoring notifications about $1"); - } elsif ($arg =~ /^$mynick[,: ]\s*ignore$/i) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*ignore$/i) { if (keys %ignore) { foreach my $i (keys %ignore) { $self->privmsg([ @to ], "$nick: ignoring $i"); @@ -164,14 +164,14 @@ sub on_public { } else { $self->privmsg([ @to ], "$nick: I'm not currently ignoring any notifications"); } - } elsif ($arg =~ /^$mynick[,: ]\s*unignore (.+)\s*$/i) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unignore (.+)\s*$/i) { if (!exists($ignore{$1})) { $self->privmsg([ @to ], "$nick: notifications about $1 weren't being ignored anyway."); } else { delete $ignore{$1}; $self->privmsg([ @to ], "$nick: ok, notifications about $1 no longer being ignored."); } - } elsif ($arg =~ /^$mynick[,: ]+(?:\s*ack\s*)?(\d+)(?:\s*ack\s*)?[:\s]+([^:]+)\s*$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)+(?:\s*ack\s*)?(\d+)(?:\s*ack\s*)?[:\s]+([^:]+)\s*$/) { open CMDPIPE,">",$nagioscmd; my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; if ( defined $host && defined $svc ) { @@ -180,15 +180,15 @@ sub on_public { printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$host,$nick,$2; } close CMDPIPE; - } elsif ($arg =~ /^$mynick[,: ]\s*ack ([^:]+):([^:]+)\s*$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*ack ([^:]+):([^:]+)\s*$/) { open CMDPIPE,">",$nagioscmd; printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$1,$nick,$2; close CMDPIPE; - } elsif ($arg =~ /^$mynick[,: ]\s*ack ([^:]+):([^:]+):([^:]+)\s*$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*ack ([^:]+):([^:]+):([^:]+)\s*$/) { open CMDPIPE,">",$nagioscmd; printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$1,$2,$nick,$3; close CMDPIPE; - } elsif ($arg =~ /^$mynick[,: ]\s*unack (\d+)$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unack (\d+)$/) { open CMDPIPE,">",$nagioscmd; my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; if ( defined $host && defined $svc ) { @@ -199,17 +199,17 @@ sub on_public { $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host has been removed."); } close CMDPIPE; - } elsif ($arg =~ /^$mynick[,: ]\s*unack ([^:]+)\s*$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unack ([^:]+)\s*$/) { open CMDPIPE,">",$nagioscmd; printf CMDPIPE "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",time(),$1; close CMDPIPE; $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1 has been removed."); - } elsif ($arg =~ /^$mynick[,: ]\s*unack ([^:]+):([^:]+)\s*$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unack ([^:]+):([^:]+)\s*$/) { open CMDPIPE,">",$nagioscmd; printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$1,$2; close CMDPIPE; $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1:$2 has been removed."); - } elsif ($arg =~ /^$mynick[,: ]\s*status (\S.*?)\s*$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*status (\S.*?)\s*$/) { my @lines = (); open CMDPIPE,"-|","/usr/local/bin/nag-stat",$1; while () { @@ -220,8 +220,9 @@ sub on_public { foreach my $line (@lines) { $self->privmsg([ @to ], "$nick: $line"); } - } elsif ($arg =~ /^$mynick[,: ]\s*help/i) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*help/i) { $self->privmsg([ @to ], "$nick: You're right, I need help!"); + $self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, help"); } elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) { $self->privmsg([ @to ], "Yo, $nick!"); } else { @@ -330,7 +331,7 @@ sub on_notice { print "Joining channels...\n"; # CONFIG: channels that should be joined go here. - $self->join("#april-admin"); + $self->join("#april-monitoring"); } } @@ -393,7 +394,7 @@ while (1) { if ($identified_to_nickserv) { # CONFIG: change where we announce stuff here - my @channels = ('#april-admin'); + my @channels = ('#april-monitoring'); while (defined (my $line = )) { print $line; chomp($line); From 535832cb8e3afff03fdbdac9fbf338c57e62f6af Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Sep 2016 16:52:08 +0200 Subject: [PATCH 05/16] Update output --- galanga/nagios-irc-bot.pl | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 6dbf1c5..b04b9c8 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -69,6 +69,8 @@ $conn->debug(1); my $laststat = time; my $identified_to_nickserv = 0; +$::tagueule = 0; + # # Handler subs # @@ -78,7 +80,7 @@ sub on_connect { my $self = shift; $identified_to_nickserv = 1; - print "Joining #april-monitoring...\n"; + print "Joining #april-admin...\n"; # FIXME: this is broken right now. when this is re-added, it has to happen # before we try to join channels. @@ -86,7 +88,7 @@ sub on_connect { #$self->privmsg('nickserv',"identify xxx"); # CONFIG: channels you want us to announce to ... - $self->join("#april-monitoring"); + $self->join("#april-admin"); #$self->join("#status"); } @@ -225,6 +227,16 @@ sub on_public { $self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, help"); } elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) { $self->privmsg([ @to ], "Yo, $nick!"); + } elsif ($arg =~ /(?:$mynick[,: ]|!)\s*ta\s*g(:?ueu|o)le/i) { + if ( $::tagueule == 0 ) + { + $self->privmsg([ @to ], "$nick: ok, I'll shut up!"); + $::tagueule = 1; + } + else { + $self->privmsg([ @to ], "$nick: ok, I'm back!"); + $::tagueule = 0; + } } else { # $self->privmsg([ @to ], "Yo!"); } @@ -331,7 +343,7 @@ sub on_notice { print "Joining channels...\n"; # CONFIG: channels that should be joined go here. - $self->join("#april-monitoring"); + $self->join("#april-admin"); } } @@ -394,10 +406,11 @@ while (1) { if ($identified_to_nickserv) { # CONFIG: change where we announce stuff here - my @channels = ('#april-monitoring'); + my @channels = ('#april-admin'); while (defined (my $line = )) { print $line; chomp($line); + next if $::tagueule; if ($line =~ /^\[\d+\] (HOST|SERVICE) NOTIFICATION: (.+)$/) { my ($type, $msg) = ($1, $2); my ($who, $host, $service, $state, $how, $output); @@ -407,9 +420,6 @@ while (1) { $renot{$host} = time(); my $id = ackable($host,undef,$state,$output); - $output =~ s/^\s*CRITICAL\s*//g; - $output =~ s/^\s*WARNING\s*//g; - $output =~ s/^\s*OK\s*//g; $msg = $state_to_color->{$state} . "$id$host is $state: $output"; } else { @@ -418,6 +428,9 @@ while (1) { $renot{"$host:$service"} = time(); my $id = ackable($host,$service,$state,$output); + $output =~ s/^\s*CRITICAL\s*:\s//gi; + $output =~ s/^\s*WARNING\s*:\s//gi; + $output =~ s/^\s*OK\s*:\s//gi; $msg = $state_to_color->{$state} . "$id$host:$service is $state: $output"; } $service ||= ""; From 8807bc02e9c76fbd1ee0af2c4bfbb4cc47b8e886 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Sep 2016 14:25:56 +0200 Subject: [PATCH 06/16] Update bot --- galanga/nagios-irc-bot.pl | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index b04b9c8..3ce9845 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -80,7 +80,7 @@ sub on_connect { my $self = shift; $identified_to_nickserv = 1; - print "Joining #april-admin...\n"; + print "Joining #april-monitoring...\n"; # FIXME: this is broken right now. when this is re-added, it has to happen # before we try to join channels. @@ -88,7 +88,7 @@ sub on_connect { #$self->privmsg('nickserv',"identify xxx"); # CONFIG: channels you want us to announce to ... - $self->join("#april-admin"); + $self->join("#april-monitoring"); #$self->join("#status"); } @@ -211,16 +211,18 @@ sub on_public { printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$1,$2; close CMDPIPE; $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1:$2 has been removed."); - } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*status (\S.*?)\s*$/) { + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*status\s*$/) { my @lines = (); - open CMDPIPE,"-|","/usr/local/bin/nag-stat",$1; + open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN"; while () { chomp; push @lines, $_; } close CMDPIPE; + my @prefix = ( 'Warn', 'Critical', 'Unknown' ); + my $i = 0; foreach my $line (@lines) { - $self->privmsg([ @to ], "$nick: $line"); + $self->privmsg([ @to ], "$nick: ".$prefix[$i++].": $line"); } } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*help/i) { $self->privmsg([ @to ], "$nick: You're right, I need help!"); @@ -232,10 +234,12 @@ sub on_public { { $self->privmsg([ @to ], "$nick: ok, I'll shut up!"); $::tagueule = 1; + $self->nick('vivivi[zzz]'); } else { $self->privmsg([ @to ], "$nick: ok, I'm back!"); $::tagueule = 0; + $self->nick('vivivi'); } } else { # $self->privmsg([ @to ], "Yo!"); @@ -343,7 +347,7 @@ sub on_notice { print "Joining channels...\n"; # CONFIG: channels that should be joined go here. - $self->join("#april-admin"); + $self->join("#april-monitoring"); } } @@ -406,7 +410,7 @@ while (1) { if ($identified_to_nickserv) { # CONFIG: change where we announce stuff here - my @channels = ('#april-admin'); + my @channels = ('#april-monitoring'); while (defined (my $line = )) { print $line; chomp($line); @@ -485,6 +489,13 @@ while (1) { close NAGIOS; open NAGIOS, "<$nagioslog"; } + open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN"; + my $count = 0; + while () { + $count += $_; + } + close CMDPIPE; + $conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 ); } } } From 544b4f79866da2f2d547050de342ef1234f6b0d0 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Sep 2016 14:38:15 +0200 Subject: [PATCH 07/16] Add display of number of alerts --- galanga/nagios-irc-bot.pl | 332 ++++++++++++++++++++------------------ 1 file changed, 171 insertions(+), 161 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 3ce9845..4faffd7 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -60,7 +60,7 @@ while (!$conn) { Nick => 'vivivi', Ircname => 'April Nagios alerts', Username => 'vivivi') - or print "Redialing...\n"; + or print "Redialing...\n"; sleep 1; } @@ -80,7 +80,7 @@ sub on_connect { my $self = shift; $identified_to_nickserv = 1; - print "Joining #april-monitoring...\n"; + print "Joining #april-admin...\n"; # FIXME: this is broken right now. when this is re-added, it has to happen # before we try to join channels. @@ -88,7 +88,7 @@ sub on_connect { #$self->privmsg('nickserv',"identify xxx"); # CONFIG: channels you want us to announce to ... - $self->join("#april-monitoring"); + $self->join("#april-admin"); #$self->join("#status"); } @@ -129,8 +129,8 @@ sub on_msg { if ($arg =~ /Go away/i) { # Tell him to leave, and he does. $self->quit("Yow!!"); exit 0; - # CONFIG: if you don't change this, anybody can restart your IRC bot at will - # if they've seen this ... + # CONFIG: if you don't change this, anybody can restart your IRC bot at will + # if they've seen this ... } elsif ($arg =~ /restart ya dope/) { $self->quit("Regrouping"); exec $0; @@ -155,94 +155,95 @@ sub on_public { if ($arg =~ /^$mynick[,: ]/i || $arg =~ /^!/ ) { if ($arg =~ /^(?:$mynick[,: ]|!)\s*ignore (.+)\s*$/i) { - $ignore{$1} = 1; - $self->privmsg([ @to ], "$nick: ok, ignoring notifications about $1"); + $ignore{$1} = 1; + $self->privmsg([ @to ], "$nick: ok, ignoring notifications about $1"); } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*ignore$/i) { - if (keys %ignore) { - foreach my $i (keys %ignore) { - $self->privmsg([ @to ], "$nick: ignoring $i"); - } - $self->privmsg([ @to ], "$nick: end of list"); - } else { - $self->privmsg([ @to ], "$nick: I'm not currently ignoring any notifications"); - } + if (keys %ignore) { + foreach my $i (keys %ignore) { + $self->privmsg([ @to ], "$nick: ignoring $i"); + } + $self->privmsg([ @to ], "$nick: end of list"); + } else { + $self->privmsg([ @to ], "$nick: I'm not currently ignoring any notifications"); + } } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unignore (.+)\s*$/i) { - if (!exists($ignore{$1})) { - $self->privmsg([ @to ], "$nick: notifications about $1 weren't being ignored anyway."); - } else { - delete $ignore{$1}; - $self->privmsg([ @to ], "$nick: ok, notifications about $1 no longer being ignored."); - } + if (!exists($ignore{$1})) { + $self->privmsg([ @to ], "$nick: notifications about $1 weren't being ignored anyway."); + } else { + delete $ignore{$1}; + $self->privmsg([ @to ], "$nick: ok, notifications about $1 no longer being ignored."); + } } elsif ($arg =~ /^(?:$mynick[,: ]|!)+(?:\s*ack\s*)?(\d+)(?:\s*ack\s*)?[:\s]+([^:]+)\s*$/) { - open CMDPIPE,">",$nagioscmd; - my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; - if ( defined $host && defined $svc ) { - printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$host,$svc,$nick,$2; - } elsif ( defined $host ) { - printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$host,$nick,$2; - } - close CMDPIPE; + open CMDPIPE,">",$nagioscmd; + my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; + if ( defined $host && defined $svc ) { + printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$host,$svc,$nick,$2; + } elsif ( defined $host ) { + printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$host,$nick,$2; + } + close CMDPIPE; } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*ack ([^:]+):([^:]+)\s*$/) { - open CMDPIPE,">",$nagioscmd; - printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$1,$nick,$2; - close CMDPIPE; + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$1,$nick,$2; + close CMDPIPE; } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*ack ([^:]+):([^:]+):([^:]+)\s*$/) { - open CMDPIPE,">",$nagioscmd; - printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$1,$2,$nick,$3; - close CMDPIPE; + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$1,$2,$nick,$3; + close CMDPIPE; } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unack (\d+)$/) { - open CMDPIPE,">",$nagioscmd; - my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; - if ( defined $host && defined $svc ) { - printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$host,$svc; - $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host:$svc has been removed."); - } elsif ( defined $host ) { - printf CMDPIPE "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",time(),$host; - $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host has been removed."); - } - close CMDPIPE; + open CMDPIPE,">",$nagioscmd; + my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; + if ( defined $host && defined $svc ) { + printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$host,$svc; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host:$svc has been removed."); + } elsif ( defined $host ) { + printf CMDPIPE "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",time(),$host; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host has been removed."); + } + close CMDPIPE; } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unack ([^:]+)\s*$/) { - open CMDPIPE,">",$nagioscmd; - printf CMDPIPE "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",time(),$1; - close CMDPIPE; - $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1 has been removed."); + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",time(),$1; + close CMDPIPE; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1 has been removed."); } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*unack ([^:]+):([^:]+)\s*$/) { - open CMDPIPE,">",$nagioscmd; - printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$1,$2; - close CMDPIPE; - $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1:$2 has been removed."); + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$1,$2; + close CMDPIPE; + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1:$2 has been removed."); } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*status\s*$/) { - my @lines = (); - open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN"; - while () { - chomp; - push @lines, $_; - } - close CMDPIPE; - my @prefix = ( 'Warn', 'Critical', 'Unknown' ); - my $i = 0; - foreach my $line (@lines) { - $self->privmsg([ @to ], "$nick: ".$prefix[$i++].": $line"); - } + my @lines = (); + open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN"; + while () { + chomp; + push @lines, $_; + } + close CMDPIPE; + my @prefix = ( 'Warn', 'Critical', 'Unknown' ); + my $i = 0; + foreach my $line (@lines) { + $self->privmsg([ @to ], "$nick: ".$prefix[$i++].": $line"); + } } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*help/i) { - $self->privmsg([ @to ], "$nick: You're right, I need help!"); - $self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, help"); + $self->privmsg([ @to ], "$nick: You're right, I need help!"); + $self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, ta gueule, help"); } elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) { - $self->privmsg([ @to ], "Yo, $nick!"); - } elsif ($arg =~ /(?:$mynick[,: ]|!)\s*ta\s*g(:?ueu|o)le/i) { + $self->privmsg([ @to ], "Yo, $nick!"); + } elsif ($arg =~ /(?:$mynick[,: ]|!)\s*ta\s*g(:?ueu|o)le/i || + $arg =~ /(?:$mynick[,: ]|!)\s*chut/i) { if ( $::tagueule == 0 ) { - $self->privmsg([ @to ], "$nick: ok, I'll shut up!"); + $self->privmsg([ @to ], "$nick: d'accord je la ferme :-("); $::tagueule = 1; $self->nick('vivivi[zzz]'); } else { - $self->privmsg([ @to ], "$nick: ok, I'm back!"); + $self->privmsg([ @to ], "$nick: je reviens et je ne suis pas content !"); $::tagueule = 0; - $self->nick('vivivi'); + &adjust_nick ( $conn ); } } else { -# $self->privmsg([ @to ], "Yo!"); + # $self->privmsg([ @to ], "Yo!"); } } } @@ -317,7 +318,7 @@ sub on_disconnect { my ($self, $event) = @_; print "Disconnected from ", $event->from(), " (", - ($event->args())[0], "). Attempting to reconnect...\n"; + ($event->args())[0], "). Attempting to reconnect...\n"; $identified_to_nickserv = 0; while (!$self->connected) { $self->connect(); @@ -336,8 +337,8 @@ sub on_notice { # FIXME: the nickserv path is broken ... if ((lc($event->nick) eq "nickserv") && ($args[0] =~ "nickname is registered")) { -# print "Identifying to NickServ...\n"; -# $self->privmsg('nickserv',"identify xxx"); + # print "Identifying to NickServ...\n"; + # $self->privmsg('nickserv',"identify xxx"); } # FIXME: the nickserv path is broken ... @@ -347,7 +348,7 @@ sub on_notice { print "Joining channels...\n"; # CONFIG: channels that should be joined go here. - $self->join("#april-monitoring"); + $self->join("#april-admin"); } } @@ -393,7 +394,7 @@ my %C = ( C => "\x0311", Y => "\x038", N => "\x0315", -); + ); my $state_to_color = { OK => $C{G}, @@ -409,94 +410,103 @@ while (1) { $irc->do_one_loop(); if ($identified_to_nickserv) { - # CONFIG: change where we announce stuff here - my @channels = ('#april-monitoring'); - while (defined (my $line = )) { - print $line; - chomp($line); - next if $::tagueule; - if ($line =~ /^\[\d+\] (HOST|SERVICE) NOTIFICATION: (.+)$/) { - my ($type, $msg) = ($1, $2); - my ($who, $host, $service, $state, $how, $output); - if ($type eq "HOST") { - ($who, $host, $state, $how, $output) = split(";",$msg,5); - next if exists $renot{$host} && $renot{$host} >= time() - 5; - $renot{$host} = time(); + # CONFIG: change where we announce stuff here + my @channels = ('#april-admin'); + while (defined (my $line = )) { + print $line; + chomp($line); + next if $::tagueule; + if ($line =~ /^\[\d+\] (HOST|SERVICE) NOTIFICATION: (.+)$/) { + my ($type, $msg) = ($1, $2); + my ($who, $host, $service, $state, $how, $output); + if ($type eq "HOST") { + ($who, $host, $state, $how, $output) = split(";",$msg,5); + next if exists $renot{$host} && $renot{$host} >= time() - 5; + $renot{$host} = time(); - my $id = ackable($host,undef,$state,$output); - $msg = $state_to_color->{$state} . "$id$host is $state: $output"; - } - else { - ($who, $host, $service, $state, $how, $output) = split(";",$msg,6); - next if exists $renot{"$host:$service"} && $renot{"$host:$service"} >= time() - 5; - $renot{"$host:$service"} = time(); + my $id = ackable($host,undef,$state,$output); + $msg = $state_to_color->{$state} . "$id$host is $state: $output"; + &adjust_nick ( $conn ); + } + else { + ($who, $host, $service, $state, $how, $output) = split(";",$msg,6); + next if exists $renot{"$host:$service"} && $renot{"$host:$service"} >= time() - 5; + $renot{"$host:$service"} = time(); - my $id = ackable($host,$service,$state,$output); - $output =~ s/^\s*CRITICAL\s*:\s//gi; - $output =~ s/^\s*WARNING\s*:\s//gi; - $output =~ s/^\s*OK\s*:\s//gi; - $msg = $state_to_color->{$state} . "$id$host:$service is $state: $output"; - } - $service ||= ""; + my $id = ackable($host,$service,$state,$output); + $output =~ s/^\s*CRITICAL\s*:\s//gi; + $output =~ s/^\s*WARNING\s*:\s//gi; + $output =~ s/^\s*OK\s*:\s//gi; + $msg = $state_to_color->{$state} . "$id$host:$service is $state: $output"; + &adjust_nick ( $conn ); + } + $service ||= ""; - # alerts can be separated by who they're for (which group is getting it) -#if ($who eq "mark") { push @channels, "#dw_ops", "#dw_work" } + # alerts can be separated by who they're for (which group is getting it) + #if ($who eq "mark") { push @channels, "#dw_ops", "#dw_work" } - if ((!grep { $_ eq "$host:$service" } keys %ignore) && - (!grep { $_ eq "$host" } keys %ignore)) { - $conn->privmsg($_,"$msg") foreach @channels; - } -#[1310493492] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;gearmanworker-gearmanworker3;1310492897;1310500097;1;0;28800;stumble.barr;rebooting - } elsif ($line =~ /EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;(.+?);(\d+);(\d+);\d+;\d+;\d+;(.+?);(.+)$/) { - my $ns = $3 - $2; - $conn->privmsg($_, "Downtime (${ns}s) scheduled for host $1 by $4: $5") - foreach @channels; - } elsif ($line =~ /EXTERNAL COMMAND: SCHEDULE_SVC_DOWNTIME;(.+?);(.+?);(\d+);(\d+);\d+;\d+;\d+;(.+?);(.+)$/) { - my $ns = $4 - $3; - $conn->privmsg($_, "Downtime (${ns}s) scheduled for service $1: $2 by $5: $6") - foreach @channels; - } elsif ($line =~ /EXTERNAL COMMAND: (EN|DIS)ABLE_HOST_(SVC_)?NOTIFICATIONS;(.+)$/) { - my $type = $2 ? 'All service' : 'Host'; - my $verb = $1 eq 'EN' ? "$C{G}enabled$C{N}" : "$C{R}disabled$C{N}"; - $conn->privmsg($_, "$type notifications $verb: $C{O}$3") - foreach @channels; - } elsif ($line =~ /EXTERNAL COMMAND: (EN|DIS)ABLE_(SVC_)?NOTIFICATIONS;(.+?);(.+)$/) { - my $verb = $1 eq 'EN' ? "$C{G}enabled$C{N}" : "$C{R}disabled$C{N}"; - $conn->privmsg($_, "Service notifications $verb on $C{O}$3$C{N}: $C{O}$4") - foreach @channels; - } elsif ($line =~ /HOST DOWNTIME ALERT: (.+?);(.+?);/) { - my $vb = { CANCELLED => 'been manually removed from', STOPPED => 'exited from', STARTED => 'entered' }->{$2}; - $conn->privmsg($_, "Host $C{O}$1$C{N} has $vb scheduled downtime.") - foreach @channels; - } elsif ($line =~ /SERVICE DOWNTIME ALERT: (.+?);(.+?);(.+?);/) { - my $vb = { CANCELLED => 'been manually removed from', STOPPED => 'exited from', STARTED => 'entered' }->{$3}; - $conn->privmsg($_, "Service $C{O}$1$C{N}: $C{O}$2$C{N} has $vb scheduled downtime.") - foreach @channels; - } - } - - if ((time - $laststat) > 30) { - # we don't want to constantly stat the file or we'll hammer the disk. - # keep it to once every 30 seconds. Here we compare the inode of the - # file we have open and the file at the path we're expecting and see - # if they match. If they don't, then the log has been rotated, so we - # close and reopen it to pick up the new logfile. We also only do it - # if we don't read a line from the file, so that way we make sure - # actually gotten to the end of the current file before we check for - # a rotation. - $laststat = time; - if ((stat NAGIOS)[1] != (stat $nagioslog)[1]) { - close NAGIOS; - open NAGIOS, "<$nagioslog"; - } - open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN"; - my $count = 0; - while () { - $count += $_; + if ((!grep { $_ eq "$host:$service" } keys %ignore) && + (!grep { $_ eq "$host" } keys %ignore)) { + $conn->privmsg($_,"$msg") foreach @channels; + } + #[1310493492] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;gearmanworker-gearmanworker3;1310492897;1310500097;1;0;28800;stumble.barr;rebooting + } elsif ($line =~ /EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;(.+?);(\d+);(\d+);\d+;\d+;\d+;(.+?);(.+)$/) { + my $ns = $3 - $2; + $conn->privmsg($_, "Downtime (${ns}s) scheduled for host $1 by $4: $5") + foreach @channels; + } elsif ($line =~ /EXTERNAL COMMAND: SCHEDULE_SVC_DOWNTIME;(.+?);(.+?);(\d+);(\d+);\d+;\d+;\d+;(.+?);(.+)$/) { + my $ns = $4 - $3; + $conn->privmsg($_, "Downtime (${ns}s) scheduled for service $1: $2 by $5: $6") + foreach @channels; + } elsif ($line =~ /EXTERNAL COMMAND: (EN|DIS)ABLE_HOST_(SVC_)?NOTIFICATIONS;(.+)$/) { + my $type = $2 ? 'All service' : 'Host'; + my $verb = $1 eq 'EN' ? "$C{G}enabled$C{N}" : "$C{R}disabled$C{N}"; + $conn->privmsg($_, "$type notifications $verb: $C{O}$3") + foreach @channels; + } elsif ($line =~ /EXTERNAL COMMAND: (EN|DIS)ABLE_(SVC_)?NOTIFICATIONS;(.+?);(.+)$/) { + my $verb = $1 eq 'EN' ? "$C{G}enabled$C{N}" : "$C{R}disabled$C{N}"; + $conn->privmsg($_, "Service notifications $verb on $C{O}$3$C{N}: $C{O}$4") + foreach @channels; + } elsif ($line =~ /HOST DOWNTIME ALERT: (.+?);(.+?);/) { + my $vb = { CANCELLED => 'been manually removed from', STOPPED => 'exited from', STARTED => 'entered' }->{$2}; + $conn->privmsg($_, "Host $C{O}$1$C{N} has $vb scheduled downtime.") + foreach @channels; + } elsif ($line =~ /SERVICE DOWNTIME ALERT: (.+?);(.+?);(.+?);/) { + my $vb = { CANCELLED => 'been manually removed from', STOPPED => 'exited from', STARTED => 'entered' }->{$3}; + $conn->privmsg($_, "Service $C{O}$1$C{N}: $C{O}$2$C{N} has $vb scheduled downtime.") + foreach @channels; + } + } + + if ((time - $laststat) > 30) { + # we don't want to constantly stat the file or we'll hammer the disk. + # keep it to once every 30 seconds. Here we compare the inode of the + # file we have open and the file at the path we're expecting and see + # if they match. If they don't, then the log has been rotated, so we + # close and reopen it to pick up the new logfile. We also only do it + # if we don't read a line from the file, so that way we make sure + # actually gotten to the end of the current file before we check for + # a rotation. + $laststat = time; + if ((stat NAGIOS)[1] != (stat $nagioslog)[1]) { + close NAGIOS; + open NAGIOS, "<$nagioslog"; + } + &adjust_nick ( $conn ); } - close CMDPIPE; - $conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 ); - } } } + +sub adjust_nick +{ + my ( $conn ) = @_; + open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN"; + my $count = 0; + while () { + $count += $_; + } + close CMDPIPE; + $conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 ); +} + From 2b07935655f53f744e4c4d0d163ba05965b75920 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Sep 2016 14:44:53 +0200 Subject: [PATCH 08/16] Change nick for regexp issues --- galanga/nagios-irc-bot.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 4faffd7..4d01747 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -235,7 +235,7 @@ sub on_public { { $self->privmsg([ @to ], "$nick: d'accord je la ferme :-("); $::tagueule = 1; - $self->nick('vivivi[zzz]'); + $self->nick('vivivi{zzz}'); } else { $self->privmsg([ @to ], "$nick: je reviens et je ne suis pas content !"); @@ -507,6 +507,6 @@ sub adjust_nick $count += $_; } close CMDPIPE; - $conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 ); + $conn->nick(sprintf('vivivi{%s}', $count)) if ( $count > 0 ); } From abd898f025e9c3f02b80ebd146570c70e6de1ec0 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Sep 2016 14:49:40 +0200 Subject: [PATCH 09/16] Fix regexp --- galanga/nagios-irc-bot.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 4d01747..e9c9c2b 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -153,6 +153,9 @@ sub on_public { # FIXME: the logging gets spammy ... do we actually want to log to stdout? print "<$nick> $arg\n"; + $mynick =~ s/\[/\\[/g; + $mynick =~ s/\]/\\]/g; + if ($arg =~ /^$mynick[,: ]/i || $arg =~ /^!/ ) { if ($arg =~ /^(?:$mynick[,: ]|!)\s*ignore (.+)\s*$/i) { $ignore{$1} = 1; @@ -235,7 +238,7 @@ sub on_public { { $self->privmsg([ @to ], "$nick: d'accord je la ferme :-("); $::tagueule = 1; - $self->nick('vivivi{zzz}'); + $self->nick('vivivi[zzz]'); } else { $self->privmsg([ @to ], "$nick: je reviens et je ne suis pas content !"); @@ -507,6 +510,6 @@ sub adjust_nick $count += $_; } close CMDPIPE; - $conn->nick(sprintf('vivivi{%s}', $count)) if ( $count > 0 ); + $conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 ); } From 95f595d7016a98434d34adb9fd7f318f03fa463b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Sep 2016 14:57:02 +0200 Subject: [PATCH 10/16] Fixes --- galanga/nagios-irc-bot.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index e9c9c2b..9d34475 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -155,6 +155,7 @@ sub on_public { $mynick =~ s/\[/\\[/g; $mynick =~ s/\]/\\]/g; + print "My nick: $mynick\n"; if ($arg =~ /^$mynick[,: ]/i || $arg =~ /^!/ ) { if ($arg =~ /^(?:$mynick[,: ]|!)\s*ignore (.+)\s*$/i) { @@ -510,6 +511,13 @@ sub adjust_nick $count += $_; } close CMDPIPE; - $conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 ); + if ( $count > 0 ) + { + $conn->nick(sprintf('vivivi[%d]', $count)); + } + else + { + $conn->nick('vivivi'); + } } From 5eaa81d5c8d0a6818b01e2c48fba4870ccdb2f14 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 21 Sep 2016 15:22:39 +0200 Subject: [PATCH 11/16] Fixes --- galanga/nagios-irc-bot.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 9d34475..0f15289 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -234,7 +234,8 @@ sub on_public { } elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) { $self->privmsg([ @to ], "Yo, $nick!"); } elsif ($arg =~ /(?:$mynick[,: ]|!)\s*ta\s*g(:?ueu|o)le/i || - $arg =~ /(?:$mynick[,: ]|!)\s*chut/i) { + $arg =~ /(?:$mynick[,: ]|!)\s*chut/i || + $arg =~ /(?:$mynick[,: ]|!)\s*sieste/i ) { if ( $::tagueule == 0 ) { $self->privmsg([ @to ], "$nick: d'accord je la ferme :-("); @@ -511,7 +512,11 @@ sub adjust_nick $count += $_; } close CMDPIPE; - if ( $count > 0 ) + if ( $::tagueule ) + { + $conn->nick('vivivi[zzz]'); + } + elsif ( $count > 0 ) { $conn->nick(sprintf('vivivi[%d]', $count)); } From 5bd8fa7daaefcb9dd44c3e32e66e45ff3c4d61a5 Mon Sep 17 00:00:00 2001 From: Benjamin Drieu Date: Tue, 4 Oct 2016 16:26:39 +0200 Subject: [PATCH 12/16] Add logging message --- galanga/nagios-irc-bot.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 0f15289..a85449a 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -181,6 +181,7 @@ sub on_public { open CMDPIPE,">",$nagioscmd; my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; if ( defined $host && defined $svc ) { + $self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $host:$svc has been added."); printf CMDPIPE "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;1;1;%s;%s\n",time(),$host,$svc,$nick,$2; } elsif ( defined $host ) { printf CMDPIPE "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;1;%s;%s\n",time(),$host,$nick,$2; From 806790e4c3563c8879ed4b3d0c5c33ab2c6a8ce8 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 18 Oct 2016 23:09:00 +0200 Subject: [PATCH 13/16] Improve vivivi --- galanga/nagios-irc-bot.pl | 66 ++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index a85449a..ddb4d28 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -24,6 +24,7 @@ use strict; use Net::IRC; use POSIX "sys_wait_h"; use Term::ANSIColor qw/ :constants /; +use Data::Dumper; # # Create the IRC and Connection objects @@ -31,6 +32,7 @@ use Term::ANSIColor qw/ :constants /; my $version = "BZBot v1.3 - Modified for use with Nagios."; my $irc = new Net::IRC; +my $channel = '#april-admin'; #open IPADDR, "; @@ -80,16 +82,16 @@ sub on_connect { my $self = shift; $identified_to_nickserv = 1; - print "Joining #april-admin...\n"; - + print "Joining $channel...\n"; # FIXME: this is broken right now. when this is re-added, it has to happen # before we try to join channels. #print "Identifying to NickServ...\n"; #$self->privmsg('nickserv',"identify xxx"); # CONFIG: channels you want us to announce to ... - $self->join("#april-admin"); + $self->join($channel); #$self->join("#status"); + &refresh (); } # Handles some messages you get when you connect @@ -231,7 +233,7 @@ sub on_public { } } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*help/i) { $self->privmsg([ @to ], "$nick: You're right, I need help!"); - $self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, ta gueule, help"); + $self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, chut, list, refresh, recheck, help"); } elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) { $self->privmsg([ @to ], "Yo, $nick!"); } elsif ($arg =~ /(?:$mynick[,: ]|!)\s*ta\s*g(:?ueu|o)le/i || @@ -248,8 +250,34 @@ sub on_public { $::tagueule = 0; &adjust_nick ( $conn ); } + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*list\s*$/) { + my $id = 0; + foreach ( @ACKS ) + { + my ( $host, $svc, $state, $content ) = @$_; + my $msg = sprintf ( "[%02d] %s:%s is %s: %s", + ($id++), $host, $svc, $state, $content ); + $conn->privmsg([ @to ], $msg); + } + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*refresh\s*$/) { + &refresh (); + $conn->privmsg([ @to ], sprintf ( "%d problemes enregistres", ( scalar @ACKS )) ); + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*recheck:?\s*(\d*)$/) { + if ( $ACKS[$1] ) + { + my ( $host, $svc ) = @{ $ACKS[$1] || [ undef, undef ] }; + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu\n",time(),$host,$svc,time(); + printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu\n",time(),$host,$svc,time(); + close CMDPIPE; + $conn->privmsg([ @to ], sprintf ( "Recheck forcé pour %s: %s", $host, $svc ) ); + } + else + { + $conn->privmsg([ @to ], sprintf ( "ID inconnu: %d", $1 ) ); + } } else { - # $self->privmsg([ @to ], "Yo!"); + $self->privmsg([ @to ], "Yo!"); } } } @@ -354,7 +382,7 @@ sub on_notice { print "Joining channels...\n"; # CONFIG: channels that should be joined go here. - $self->join("#april-admin"); + $self->join($channel); } } @@ -367,6 +395,30 @@ sub ackable { return sprintf( '[%02d] ', $id ); } +sub refresh { + $ACKCT=0; + @ACKS=(); + open FILE, '/var/lib/icinga/status.dat' or die $!; + while ( ) + { + if ( /^servicestatus/ ) + { + my %keys; + do + { + $_ = ; + chomp; + $keys{$1} = $2 if ( /\s*([^=]*)=([^=]*)/ ); + } + while ( $_ && ! /^}/ ); + my @states = ( 'OK', 'WARNING', 'CRITICAL', 'UNKNOWN' ); + $ACKS[$ACKCT++] = [ $keys{'host_name'}, $keys{'service_description'}, $states[$keys{'current_state'}], $keys{'plugin_output'} ] if $keys{'current_state'} > 0; + } + } + close FILE; +} + + print "Installing handler routines..."; $conn->add_global_handler('ping', \&on_ping); @@ -417,7 +469,7 @@ while (1) { if ($identified_to_nickserv) { # CONFIG: change where we announce stuff here - my @channels = ('#april-admin'); + my @channels = ($channel); while (defined (my $line = )) { print $line; chomp($line); From 0a0a457e514d06fe4923d1c9c31913277306f0a8 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 19 Oct 2016 09:28:52 +0200 Subject: [PATCH 14/16] fix refresh of vivivi --- galanga/nagios-irc-bot.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index ddb4d28..3b44507 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -91,7 +91,6 @@ sub on_connect { # CONFIG: channels you want us to announce to ... $self->join($channel); #$self->join("#status"); - &refresh (); } # Handles some messages you get when you connect @@ -119,6 +118,7 @@ sub on_join { printf "*** %s (%s) has joined channel %s\n", $nick, $userhost, $channel; + &refresh (); } # What to do when we receive a private PRIVMSG. From b337c2d0e7a7cdb25c0812130149d181be600f29 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 8 Nov 2016 10:37:17 +0100 Subject: [PATCH 15/16] Add recheck all to vivivi --- galanga/nagios-irc-bot.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 3b44507..38386b2 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -276,6 +276,18 @@ sub on_public { { $conn->privmsg([ @to ], sprintf ( "ID inconnu: %d", $1 ) ); } + } elsif ($arg =~ /^(?:$mynick[,: ]|!)\s*recheck:?\s*all$/) { + #recheck all + for my $i ( 0..(@ACKS-1) ) + { + next unless($ACKS[$i]); + my ( $host, $svc ) = @{ $ACKS[$i] || [ undef, undef ] };; + open CMDPIPE,">",$nagioscmd; + printf CMDPIPE "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu\n",time(),$host,$svc,time(); + printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu\n",time(),$host,$svc,time(); + close CMDPIPE; + $conn->privmsg([ @to ], sprintf ( "Recheck forcé pour %s: %s", $host, $svc ) ); + } } else { $self->privmsg([ @to ], "Yo!"); } From cd2fc5b6b6d073b91714c0746662236b1284a9d1 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 8 Nov 2016 10:54:54 +0100 Subject: [PATCH 16/16] vivivi recheck all : print $i --- galanga/nagios-irc-bot.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galanga/nagios-irc-bot.pl b/galanga/nagios-irc-bot.pl index 38386b2..1679608 100755 --- a/galanga/nagios-irc-bot.pl +++ b/galanga/nagios-irc-bot.pl @@ -286,7 +286,7 @@ sub on_public { printf CMDPIPE "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu\n",time(),$host,$svc,time(); printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu\n",time(),$host,$svc,time(); close CMDPIPE; - $conn->privmsg([ @to ], sprintf ( "Recheck forcé pour %s: %s", $host, $svc ) ); + $conn->privmsg([ @to ], sprintf ( "Recheck forcé pour ack : %s du host %s: %s", $i, $host, $svc ) ); } } else { $self->privmsg([ @to ], "Yo!");