diff --git a/galanga/nagios-irc-bot.pl b/nagios-irc-bot.pl similarity index 96% rename from galanga/nagios-irc-bot.pl rename to nagios-irc-bot.pl index a691898..1701105 100755 --- a/galanga/nagios-irc-bot.pl +++ b/nagios-irc-bot.pl @@ -19,21 +19,26 @@ # Contributor(s): David Miller # Mark Smith # - use strict; use Net::IRC; use POSIX "sys_wait_h"; use Term::ANSIColor qw/ :constants /; use Data::Dumper; use Time::HiRes qw(usleep nanosleep); +use Config::Simple; + +# +# Get configuration file. +# +my $viviviConf = new Config::Simple("/etc/vivivi/vivivi.conf") or die "Missing configuration file."; +print "Configuration file loaded.\n"; # # Create the IRC and Connection objects # - my $version = "BZBot v1.3 - Modified for use with Nagios."; my $irc = new Net::IRC; -my $channel = '#april-admin'; +my $channel = $viviviConf->param("irc.channel"); #open IPADDR, "; @@ -41,8 +46,8 @@ my $channel = '#april-admin'; #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"; +my $nagioslog = $viviviConf->param("nagios.log"); +my $nagioscmd = $viviviConf->param("nagios.cmd"); open NAGIOS, "<$nagioslog" or die "failed to open $nagioslog: $!\n"; seek NAGIOS, 0, 2; # seek to end @@ -60,12 +65,12 @@ 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') + $conn = $irc->newconn(Server => $viviviConf->param("irc.server"), + Port => $viviviConf->param("irc.port"), + SSL => $viviviConf->param("irc.ssl"), + Nick => $viviviConf->param("irc.nick"), + Ircname => $viviviConf->param("irc.name"), + Username => $viviviConf->param("irc.username")) or print "Redialing...\n"; sleep 1; } @@ -90,7 +95,7 @@ sub on_connect { # 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 DyDJXzkqG3jbNMoceysm"); + $self->privmsg('nickserv', $viviviConf->param("irc.password")); # $self->privmsg('nickserv',"VERIFY REGISTER vivivi kwvxbsmjjiam"); # CONFIG: channels you want us to announce to ... @@ -284,7 +289,7 @@ sub on_public { my $state = $2; my $msg = $resume { $_ }; $msg =~ s/^, //; - my $msg = sprintf ( "[%02d] %s: %s %s %s", + $msg = sprintf ( "[%02d] %s: %s %s %s", ($id++), $svc, $msg, ( index( $msg, ',' ) > -1 ? 'are' : 'is' ), $state ); diff --git a/vivivi.conf b/vivivi.conf new file mode 100644 index 0000000..78f9573 --- /dev/null +++ b/vivivi.conf @@ -0,0 +1,16 @@ +# Configuration file for vivivi on Debian. + +[irc] +channel=#april-admin +server=irc.freenode.net +port=6667 +ssl=0 +nick=vivivi +name=April Nagios alerts +username=vivivi +password=xxxxxxxxxxxxxxxxxx + +[nagios] +log=/var/log/icinga/icinga.log +cmd=/var/lib/icinga/rw/icinga.cmd + diff --git a/vivivi.initd b/vivivi.initd new file mode 100755 index 0000000..2fe7a8f --- /dev/null +++ b/vivivi.initd @@ -0,0 +1,48 @@ +#! /bin/sh +# +### BEGIN INIT INFO +# Provides: vivivi +# Required-Start: $remote_fs $syslog $local_fs $network +# Required-Stop: $remote_fs $syslog $local_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Bot irc de l'April. +# Description: vivivi est un bot irc, il est ici pout avertir des alertes icinga +### END INIT INFO + +PATH=/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/srv/nagios-irc-bot/bot.sh +NAME=vivivi +DESC=vivivi + +test -f $DAEMON || exit 0 + +set -e + +case "$1" in + start) + echo -n "Starting $DESC: " + start-stop-daemon --start --quiet --make-pidfile --pidfile /var/run/$NAME.pid \ + --chuid nagios --exec $DAEMON -- --daemon $DAEMON \ + || return 2 + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + rm -f /var/run/$NAME.pid + pkill -9 -f nagios-irc-bot.pl + echo "$NAME." + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart}" >&2 + exit 1 + ;; +esac + +exit 0 + + diff --git a/vivivi.service b/vivivi.service new file mode 100644 index 0000000..4554acb --- /dev/null +++ b/vivivi.service @@ -0,0 +1,14 @@ +[Unit] +Description=APRIL IRC bot for Icinga activity +After=network-online.target + +[Service] +Type=simple +ExecStart=/srv/vivivi/vivivi.pl +User=nagios +Group=nagios +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target