On sending Zenoss events to an IRC channel

I mentioned on Twitter yesterday that I was working on integrating Zenoss with IRC, and it was requested that I write up how I did it.

While reading this tip of the month, I got the idea that instead of Twitter, which we don't use for internal purposes, we could set up a Zenoss event command to send a message to our NOC IRC channel, since that's where events and errors already get discussed. My boss thought this was a great idea and set me to work. ServerFault directed me to this Perl script, which I used as a starting point.

The first iteration of this, rather inaccurately named zenbot, was actually just a Perl script that would get called as an event command and then log into IRC, join the NOC channel, print the event details, and log out. The event command, for reference:

$ZENHOME/scripts/zenbot.pl "$ -- $"

The gist of the script was (with configuration and error checking and whatnot removed for simplicity):

my $sock = new IO::Socket::INET(PeerAddr => $server, 
                                PeerPort => 6667, 
                                Proto => 'tcp') or 
                                die "Can't connect\n";
print $sock "JOIN $channel\r\n"
my $cmd = "PRIVMSG $channel :";
my $event = $ARGV[0];
print $sock "$cmd$event\r\n";

It worked, but the overhead involved with opening a new connection on each event, not to mention the join/leave messages that would get spammed to the channel each time, were rather undesirable. So the next morning, armed with more coffee and less of a migraine, I set about finding a better solution. More research pointed me towards irccat. After a bit of arguing with the dependencies on my virtual Debian server, I was able to get irccat up and running. From there, I was able to get rid of having a separate script entirely and simply have the event command be:

echo "EVENT -- '$' -- '$'" | netcat -q0 localhost 12345

And from there I could just sit in the channel and watch my test events scroll by.

<irccat> EVENT -- 'zenoss-test' -- 'localhost zenping heartbeat failure'
<irccat> CLEAR -- 'zenoss-test' -- 'localhost zenping heartbeat failure'

No obnoxious logging in and out of the IRC server. Just a cat sending Zenoss events and clears to IRC. The irccat readme told me everything I needed to know about configuring it, and Zenoss documentation gave me the rest. So in summary:Zenoss + IRC server + irccat + event command + ??? = Profit!