Improve vivivi

This commit is contained in:
root 2016-10-18 23:09:00 +02:00
parent 5bd8fa7daa
commit 806790e4c3

View File

@ -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, "</etc/ipaddr";
#my $ipaddr = <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 ( <FILE> )
{
if ( /^servicestatus/ )
{
my %keys;
do
{
$_ = <FILE>;
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 = <NAGIOS>)) {
print $line;
chomp($line);