Externalized configurtion in /etc/vivivi/vivivi.conf.

This commit is contained in:
Christian P. MOMON 2019-08-23 05:37:15 +02:00 committed by root
parent 83aae98c7a
commit d59a3b8c46
4 changed files with 96 additions and 13 deletions

View File

@ -19,21 +19,26 @@
# Contributor(s): David Miller <justdave@syndicomm.com>
# Mark Smith <mark@qq.is>
#
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, "</etc/ipaddr";
#my $ipaddr = <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 );

16
vivivi.conf Normal file
View 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
View 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
View 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