Add display of number of alerts

This commit is contained in:
root 2016-09-21 14:38:15 +02:00
parent 8807bc02e9
commit 544b4f7986

View File

@ -80,7 +80,7 @@ sub on_connect {
my $self = shift; my $self = shift;
$identified_to_nickserv = 1; $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 # FIXME: this is broken right now. when this is re-added, it has to happen
# before we try to join channels. # before we try to join channels.
@ -88,7 +88,7 @@ sub on_connect {
#$self->privmsg('nickserv',"identify xxx"); #$self->privmsg('nickserv',"identify xxx");
# CONFIG: channels you want us to announce to ... # CONFIG: channels you want us to announce to ...
$self->join("#april-monitoring"); $self->join("#april-admin");
#$self->join("#status"); #$self->join("#status");
} }
@ -226,23 +226,24 @@ sub on_public {
} }
} 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: You're right, I need help!");
$self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, help"); $self->privmsg([ @to ], "$nick: supported commands: ignore, unignore, ack, unack, ta gueule, help");
} elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) { } elsif ($arg =~ /(?:hey|hi|hello|yo)(?:\.|,|\!|\s_)/i) {
$self->privmsg([ @to ], "Yo, $nick!"); $self->privmsg([ @to ], "Yo, $nick!");
} elsif ($arg =~ /(?:$mynick[,: ]|!)\s*ta\s*g(:?ueu|o)le/i) { } elsif ($arg =~ /(?:$mynick[,: ]|!)\s*ta\s*g(:?ueu|o)le/i ||
$arg =~ /(?:$mynick[,: ]|!)\s*chut/i) {
if ( $::tagueule == 0 ) if ( $::tagueule == 0 )
{ {
$self->privmsg([ @to ], "$nick: ok, I'll shut up!"); $self->privmsg([ @to ], "$nick: d'accord je la ferme :-(");
$::tagueule = 1; $::tagueule = 1;
$self->nick('vivivi[zzz]'); $self->nick('vivivi[zzz]');
} }
else { else {
$self->privmsg([ @to ], "$nick: ok, I'm back!"); $self->privmsg([ @to ], "$nick: je reviens et je ne suis pas content !");
$::tagueule = 0; $::tagueule = 0;
$self->nick('vivivi'); &adjust_nick ( $conn );
} }
} else { } else {
# $self->privmsg([ @to ], "Yo!"); # $self->privmsg([ @to ], "Yo!");
} }
} }
} }
@ -336,8 +337,8 @@ sub on_notice {
# FIXME: the nickserv path is broken ... # FIXME: the nickserv path is broken ...
if ((lc($event->nick) eq "nickserv") && ($args[0] =~ "nickname is registered")) { if ((lc($event->nick) eq "nickserv") && ($args[0] =~ "nickname is registered")) {
# print "Identifying to NickServ...\n"; # print "Identifying to NickServ...\n";
# $self->privmsg('nickserv',"identify xxx"); # $self->privmsg('nickserv',"identify xxx");
} }
# FIXME: the nickserv path is broken ... # FIXME: the nickserv path is broken ...
@ -347,7 +348,7 @@ sub on_notice {
print "Joining channels...\n"; print "Joining channels...\n";
# CONFIG: channels that should be joined go here. # CONFIG: channels that should be joined go here.
$self->join("#april-monitoring"); $self->join("#april-admin");
} }
} }
@ -393,7 +394,7 @@ my %C = (
C => "\x0311", C => "\x0311",
Y => "\x038", Y => "\x038",
N => "\x0315", N => "\x0315",
); );
my $state_to_color = { my $state_to_color = {
OK => $C{G}, OK => $C{G},
@ -410,7 +411,7 @@ while (1) {
if ($identified_to_nickserv) { if ($identified_to_nickserv) {
# CONFIG: change where we announce stuff here # CONFIG: change where we announce stuff here
my @channels = ('#april-monitoring'); my @channels = ('#april-admin');
while (defined (my $line = <NAGIOS>)) { while (defined (my $line = <NAGIOS>)) {
print $line; print $line;
chomp($line); chomp($line);
@ -425,6 +426,7 @@ while (1) {
my $id = ackable($host,undef,$state,$output); my $id = ackable($host,undef,$state,$output);
$msg = $state_to_color->{$state} . "$id$host is $state: $output"; $msg = $state_to_color->{$state} . "$id$host is $state: $output";
&adjust_nick ( $conn );
} }
else { else {
($who, $host, $service, $state, $how, $output) = split(";",$msg,6); ($who, $host, $service, $state, $how, $output) = split(";",$msg,6);
@ -436,17 +438,18 @@ while (1) {
$output =~ s/^\s*WARNING\s*:\s//gi; $output =~ s/^\s*WARNING\s*:\s//gi;
$output =~ s/^\s*OK\s*:\s//gi; $output =~ s/^\s*OK\s*:\s//gi;
$msg = $state_to_color->{$state} . "$id$host:$service is $state: $output"; $msg = $state_to_color->{$state} . "$id$host:$service is $state: $output";
&adjust_nick ( $conn );
} }
$service ||= ""; $service ||= "";
# alerts can be separated by who they're for (which group is getting it) # 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 ($who eq "mark") { push @channels, "#dw_ops", "#dw_work" }
if ((!grep { $_ eq "$host:$service" } keys %ignore) && if ((!grep { $_ eq "$host:$service" } keys %ignore) &&
(!grep { $_ eq "$host" } keys %ignore)) { (!grep { $_ eq "$host" } keys %ignore)) {
$conn->privmsg($_,"$msg") foreach @channels; $conn->privmsg($_,"$msg") foreach @channels;
} }
#[1310493492] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;gearmanworker-gearmanworker3;1310492897;1310500097;1;0;28800;stumble.barr;rebooting #[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+;(.+?);(.+)$/) { } elsif ($line =~ /EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;(.+?);(\d+);(\d+);\d+;\d+;\d+;(.+?);(.+)$/) {
my $ns = $3 - $2; my $ns = $3 - $2;
$conn->privmsg($_, "Downtime (${ns}s) scheduled for host $1 by $4: $5") $conn->privmsg($_, "Downtime (${ns}s) scheduled for host $1 by $4: $5")
@ -489,6 +492,15 @@ while (1) {
close NAGIOS; close NAGIOS;
open NAGIOS, "<$nagioslog"; open NAGIOS, "<$nagioslog";
} }
&adjust_nick ( $conn );
}
}
}
sub adjust_nick
{
my ( $conn ) = @_;
open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN"; open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN";
my $count = 0; my $count = 0;
while (<CMDPIPE>) { while (<CMDPIPE>) {
@ -496,7 +508,5 @@ while (1) {
} }
close CMDPIPE; close CMDPIPE;
$conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 ); $conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 );
}
}
} }