Notification by IRC script

Tedman Eng teng at dataway.com
Sat Jun 21 08:36:05 CEST 2003


I whipped up a script that will notify our helpdesk's IRC chatserver, since
that's instant feedback vs. trying to wade through a spam-filled inbox for
an alert.   Everyone is free to do what they want with the script, stick it
into the contrib if they think it's useful, or include it in their own code,
etc.  NO WARRANTY.  If it breaks, you keep all the pieces.


Description:
notify_irc looks at both piped stdin or a command line argument, and passes
that as a private message to an IRC channel or user, similar to how
/bin/mail works for notifications.


Example:
notify_irc $OUTPUT
or
echo "$OUTPUT" | notify_irc


Requires:
Perl 5.0xxx or higher
NET::IRC Perl module


Installation:
First, set up the notification commands (in misccommands.cfg)
-------------------------------------------------------------------------
# 'host-notify-by-irc' command definition
define command{
        command_name    host-notify-by-irc
        command_line    /usr/bin/printf "%b" "HOST $HOSTSTATE$ ALERT **
HOST: $HOSTNAME$ INFO:$OUTPUT$" | /usr/local/nagios/libexec/notify_irc
        }

# 'notify-by-irc' command definition
define command{
        command_name    notify-by-irc
        command_line    /usr/bin/printf "%b" "SERVICE $SERVICESTATE$ ALERT
** HOST: $HOSTNAME$ SERVICE: $SERVICEDESC$ INFO:$OUTPUT$" |
/usr/local/nagios/libexec/notify_irc
        }


Second, paste this into a file named "notify_irc" in your executables
directory
Change settings to suit your environment.
-------------------------------------------------------------------------
#!/usr/bin/perl -w
#  Based on irctest by the author of Net::IRC module
use strict;
use Net::IRC;

my $irc = new Net::IRC;
my $ircserver="your.irc.com";
my $ircchannel="#HELPDESK";
my $ircname="NAGIOS";

my $conn = $irc->newconn(Server   => ($ircserver),
                         Port     => 6667,
                         Nick     => "$ircname",
                         Ircname  => 'Nagios',
                         Username => "$ircname")
    or die "irctest: Can't connect to IRC server.\n";
my $alertmessage=($ARGV[0] || <STDIN>);

sub on_connect {
        my $self = shift;
        print "Sending privmsg to $ircchannel...\n";
        $self->privmsg("$ircchannel", $alertmessage);
        $self->quit;
        exit 0;
}

print "Connecting...\n";
$conn->add_global_handler(376, \&on_connect);
$irc->start;
-------------------------------------







-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list