Update bot

This commit is contained in:
root 2016-09-21 14:25:56 +02:00
parent 535832cb8e
commit 8807bc02e9
1 changed files with 18 additions and 7 deletions

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-admin...\n"; print "Joining #april-monitoring...\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-admin"); $self->join("#april-monitoring");
#$self->join("#status"); #$self->join("#status");
} }
@ -211,16 +211,18 @@ sub on_public {
printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$1,$2; printf CMDPIPE "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",time(),$1,$2;
close CMDPIPE; close CMDPIPE;
$self->privmsg([ @to ], "$nick: ok, acknowledgment (if any) for $1:$2 has been removed."); $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 = (); my @lines = ();
open CMDPIPE,"-|","/usr/local/bin/nag-stat",$1; open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN";
while (<CMDPIPE>) { while (<CMDPIPE>) {
chomp; chomp;
push @lines, $_; push @lines, $_;
} }
close CMDPIPE; close CMDPIPE;
my @prefix = ( 'Warn', 'Critical', 'Unknown' );
my $i = 0;
foreach my $line (@lines) { foreach my $line (@lines) {
$self->privmsg([ @to ], "$nick: $line"); $self->privmsg([ @to ], "$nick: ".$prefix[$i++].": $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: You're right, I need help!");
@ -232,10 +234,12 @@ sub on_public {
{ {
$self->privmsg([ @to ], "$nick: ok, I'll shut up!"); $self->privmsg([ @to ], "$nick: ok, I'll shut up!");
$::tagueule = 1; $::tagueule = 1;
$self->nick('vivivi[zzz]');
} }
else { else {
$self->privmsg([ @to ], "$nick: ok, I'm back!"); $self->privmsg([ @to ], "$nick: ok, I'm back!");
$::tagueule = 0; $::tagueule = 0;
$self->nick('vivivi');
} }
} else { } else {
# $self->privmsg([ @to ], "Yo!"); # $self->privmsg([ @to ], "Yo!");
@ -343,7 +347,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-admin"); $self->join("#april-monitoring");
} }
} }
@ -406,7 +410,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-admin'); my @channels = ('#april-monitoring');
while (defined (my $line = <NAGIOS>)) { while (defined (my $line = <NAGIOS>)) {
print $line; print $line;
chomp($line); chomp($line);
@ -485,6 +489,13 @@ while (1) {
close NAGIOS; close NAGIOS;
open NAGIOS, "<$nagioslog"; open NAGIOS, "<$nagioslog";
} }
open CMDPIPE,"-|","/usr/sbin/icingastats -m -d NUMSVCWARN,NUMSVCCRIT,NUMSVCUNKN";
my $count = 0;
while (<CMDPIPE>) {
$count += $_;
}
close CMDPIPE;
$conn->nick(sprintf('vivivi[%s]', $count)) if ( $count > 0 );
} }
} }
} }