From 7c9f6d224d9bf66bc1c69b1baa066f98b9302999 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Tue, 14 Dec 2010 15:14:54 -0500 Subject: Add nagios IRC bot Koumbit is using an IRC bot that Micah provided. It is a pair of perl scripts that send Nagios notifications as messages in an IRC channel. Add a class to make installing this IRC bot easy. It also defines commands 'notify-by-irc' and 'host-notify-by-irc' that can be used with checks to send notifications via the bot. Signed-off-by: Gabriel Filion --- files/irc_bot/riseup-nagios-client.pl | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 files/irc_bot/riseup-nagios-client.pl (limited to 'files/irc_bot/riseup-nagios-client.pl') diff --git a/files/irc_bot/riseup-nagios-client.pl b/files/irc_bot/riseup-nagios-client.pl new file mode 100644 index 0000000..fd28996 --- /dev/null +++ b/files/irc_bot/riseup-nagios-client.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w + +# ############################################################################## +# Infrabot-Client - a simple Infrabot client which sends it's whole command +# line arguments to a local UNIX domain socket. +# ############################################################################## + +use strict; +use IO::Socket; + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# >> CONFIGURATION >> + +my $SOCKET = '/var/run/nagios/nsa.socket'; + +# << CONFIGURATION << +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +if (@ARGV == 0) { + print "Hey - specify a message, sucker!\n"; + exit(1); +} + +unless (-S $SOCKET) { + die "Socket '$SOCKET' doesn't exist or isn't a socket!\n"; +} + +unless (-r $SOCKET) { + die "Socket '$SOCKET' can't be read!\n"; +} + +my $sock = IO::Socket::UNIX->new ( + Peer => $SOCKET, + Type => SOCK_DGRAM, + Timeout => 10 +) || die "Can't open socket '$SOCKET'!\n"; + +print $sock "@ARGV"; +close($sock); -- cgit v1.2.3 From ef76d11b5712e9c4cdc3a7454904ddbdecfdd868 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 7 Feb 2011 01:41:12 +0100 Subject: make the client config aware --- files/irc_bot/riseup-nagios-client.pl | 46 +++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'files/irc_bot/riseup-nagios-client.pl') diff --git a/files/irc_bot/riseup-nagios-client.pl b/files/irc_bot/riseup-nagios-client.pl index fd28996..2467058 100644 --- a/files/irc_bot/riseup-nagios-client.pl +++ b/files/irc_bot/riseup-nagios-client.pl @@ -12,7 +12,39 @@ use IO::Socket; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # >> CONFIGURATION >> -my $SOCKET = '/var/run/nagios/nsa.socket'; +# Read a configuration file +# The arg can be a relative or full path, or +# it can be a file located somewhere in @INC. +sub ReadCfg +{ + my $file = $_[0]; + + our $err; + + { # Put config data into a separate namespace + package CFG; + + # Process the contents of the config file + my $rc = do($file); + + # Check for errors + if ($@) { + $::err = "ERROR: Failure compiling '$file' - $@"; + } elsif (! defined($rc)) { + $::err = "ERROR: Failure reading '$file' - $!"; + } elsif (! $rc) { + $::err = "ERROR: Failure processing '$file'"; + } + } + + return ($err); +} + +# Get our configuration information +if (my $err = ReadCfg('/etc/nagios_nsa.cfg')) { + print(STDERR $err, "\n"); + exit(1); +} # << CONFIGURATION << # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -22,19 +54,19 @@ if (@ARGV == 0) { exit(1); } -unless (-S $SOCKET) { - die "Socket '$SOCKET' doesn't exist or isn't a socket!\n"; +unless (-S $CFG::Nsa{'socket'}) { + die "Socket '$CFG::Nsa{'socket'}' doesn't exist or isn't a socket!\n"; } -unless (-r $SOCKET) { - die "Socket '$SOCKET' can't be read!\n"; +unless (-r $CFG::Nsa{'socket'}) { + die "Socket '$CFG::Nsa{'socket'}' can't be read!\n"; } my $sock = IO::Socket::UNIX->new ( - Peer => $SOCKET, + Peer => $CFG::Nsa{'socket'}, Type => SOCK_DGRAM, Timeout => 10 -) || die "Can't open socket '$SOCKET'!\n"; +) || die "Can't open socket '$CFG::Nsa{'socket'}'!\n"; print $sock "@ARGV"; close($sock); -- cgit v1.2.3