Externalized configurtion in /etc/vivivi/vivivi.conf.
This commit is contained in:
parent
83aae98c7a
commit
d59a3b8c46
@ -19,21 +19,26 @@
|
|||||||
# Contributor(s): David Miller <justdave@syndicomm.com>
|
# Contributor(s): David Miller <justdave@syndicomm.com>
|
||||||
# Mark Smith <mark@qq.is>
|
# Mark Smith <mark@qq.is>
|
||||||
#
|
#
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Net::IRC;
|
use Net::IRC;
|
||||||
use POSIX "sys_wait_h";
|
use POSIX "sys_wait_h";
|
||||||
use Term::ANSIColor qw/ :constants /;
|
use Term::ANSIColor qw/ :constants /;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Time::HiRes qw(usleep nanosleep);
|
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
|
# Create the IRC and Connection objects
|
||||||
#
|
#
|
||||||
|
|
||||||
my $version = "BZBot v1.3 - Modified for use with Nagios.";
|
my $version = "BZBot v1.3 - Modified for use with Nagios.";
|
||||||
my $irc = new Net::IRC;
|
my $irc = new Net::IRC;
|
||||||
my $channel = '#april-admin';
|
my $channel = $viviviConf->param("irc.channel");
|
||||||
|
|
||||||
#open IPADDR, "</etc/ipaddr";
|
#open IPADDR, "</etc/ipaddr";
|
||||||
#my $ipaddr = <IPADDR>;
|
#my $ipaddr = <IPADDR>;
|
||||||
@ -41,8 +46,8 @@ my $channel = '#april-admin';
|
|||||||
#close IPADDR;
|
#close IPADDR;
|
||||||
|
|
||||||
# CONFIG: point this where your Nagios configuration files live
|
# CONFIG: point this where your Nagios configuration files live
|
||||||
my $nagioslog = "/var/log/icinga/icinga.log";
|
my $nagioslog = $viviviConf->param("nagios.log");
|
||||||
my $nagioscmd = "/var/lib/icinga/rw/icinga.cmd";
|
my $nagioscmd = $viviviConf->param("nagios.cmd");
|
||||||
|
|
||||||
open NAGIOS, "<$nagioslog" or die "failed to open $nagioslog: $!\n";
|
open NAGIOS, "<$nagioslog" or die "failed to open $nagioslog: $!\n";
|
||||||
seek NAGIOS, 0, 2; # seek to end
|
seek NAGIOS, 0, 2; # seek to end
|
||||||
@ -60,12 +65,12 @@ print "Creating connection to IRC server...\n";
|
|||||||
my $conn;
|
my $conn;
|
||||||
while (!$conn) {
|
while (!$conn) {
|
||||||
# CONFIG: you have to tell us where to get on IRC
|
# CONFIG: you have to tell us where to get on IRC
|
||||||
$conn = $irc->newconn(Server => 'irc.freenode.net',
|
$conn = $irc->newconn(Server => $viviviConf->param("irc.server"),
|
||||||
Port => 6667,
|
Port => $viviviConf->param("irc.port"),
|
||||||
SSL => 0,
|
SSL => $viviviConf->param("irc.ssl"),
|
||||||
Nick => 'vivivi',
|
Nick => $viviviConf->param("irc.nick"),
|
||||||
Ircname => 'April Nagios alerts',
|
Ircname => $viviviConf->param("irc.name"),
|
||||||
Username => 'vivivi')
|
Username => $viviviConf->param("irc.username"))
|
||||||
or print "Redialing...\n";
|
or print "Redialing...\n";
|
||||||
sleep 1;
|
sleep 1;
|
||||||
}
|
}
|
||||||
@ -90,7 +95,7 @@ sub on_connect {
|
|||||||
# 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.
|
||||||
#print "Identifying to NickServ...\n";
|
#print "Identifying to NickServ...\n";
|
||||||
$self->privmsg('nickserv',"identify DyDJXzkqG3jbNMoceysm");
|
$self->privmsg('nickserv', $viviviConf->param("irc.password"));
|
||||||
# $self->privmsg('nickserv',"VERIFY REGISTER vivivi kwvxbsmjjiam");
|
# $self->privmsg('nickserv',"VERIFY REGISTER vivivi kwvxbsmjjiam");
|
||||||
|
|
||||||
# CONFIG: channels you want us to announce to ...
|
# CONFIG: channels you want us to announce to ...
|
||||||
@ -284,7 +289,7 @@ sub on_public {
|
|||||||
my $state = $2;
|
my $state = $2;
|
||||||
my $msg = $resume { $_ };
|
my $msg = $resume { $_ };
|
||||||
$msg =~ s/^, //;
|
$msg =~ s/^, //;
|
||||||
my $msg = sprintf ( "[%02d] %s: %s %s %s",
|
$msg = sprintf ( "[%02d] %s: %s %s %s",
|
||||||
($id++), $svc, $msg,
|
($id++), $svc, $msg,
|
||||||
( index( $msg, ',' ) > -1 ? 'are' : 'is' ),
|
( index( $msg, ',' ) > -1 ? 'are' : 'is' ),
|
||||||
$state );
|
$state );
|
16
vivivi.conf
Normal file
16
vivivi.conf
Normal file
@ -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
|
||||||
|
|
48
vivivi.initd
Executable file
48
vivivi.initd
Executable file
@ -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
|
||||||
|
|
||||||
|
|
14
vivivi.service
Normal file
14
vivivi.service
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user