Nagios/checks/IRC

No, this is not the usual "check_irc" to monitor an IRCd, it is about:

How to monitor with Nagios if a nick is on a IRC channel
If you want to have a check in Nagios to monitor if a certain nickname is on certain IRC channel, for example to monitor if your bot is not only running its process, but actually on the channel, which can be a difference, you can do something like this:


 * 1) Use a script/bot to join the channel and log the current list of users to a textfile every 5 minutes
 * 2) Create a second script, a Nagios check command, to search that textfile for a given nickname and return OK or CRITICAL
 * 3) Put that script in the Nagios plugins directory and define it as a NRPE command in nrpe.cfg on the server running the bot
 * 4) Define the command and a service on your Nagios host to execute that command via NRPE on the remote host
 * 5) Get a Nagios check like "OK. Mybot is on #mychannel (23 nicks online)" or "CRITICAL. Mybot is not on #mychannel (17 nicks online)

Log the current user list to a logfile
For this we could make a new "nagios" script, based on Edgar or something, but since we already have a running Eggdrop we use that. So we create a simple TCL script to do the job and load it on an existing bot (Antisect).

So we need to know in TCL how to:


 * 1) Get the list of current users in channel  ( set myvar [chanlist #mychan] )
 * 2) Write to an external file (set filename.., set fileId.. ,puts..., close...)
 * 3) Start a function every 5 minutes by timer (timer.. )

Goes like this...



if {![info exists myproc_running]} { timer 1 channelnicklist set myproc_running 1 }

proc channelnicklist {} { set userlist [chanlist #seti23] set filename "nicklist_seti23.log" set fileId [open $filename "w"] puts -nonewline $fileId $userlist close $fileId

timer 1 channelnicklist return 1 } 

So load this on your Eggdrop as channelnicks.tcl or nagios.tcl or whatever and .rehash it.

You should then get a 'nicklist_seti23.log' file in the same dir your eggdrop is running. Use a "tail -f" on it and watch if it changes (after max. 1 minute) when a nick joins or parts the channel.

Create a check command to parse that logfile
We are still on the server running your Eggdrop now, its not the Nagios server but we have Nagios plugins installed because its a monitored client anyways. So we go to  or wherever you have your Nagios plugins. We create a new Bash script "check_irc_nicks" like this:

 NICK=$1 CHANNEL="seti23" NICKLIST=`cat /home/antisect/egg/nicklist_seti23.log` numbernicks=`wc -w /home/antisect/egg/nicklist_seti23.log | cut -d " " -f1` if $NICKLIST =~ $NICK then echo "OK - $NICK is in #$CHANNEL ($numbernicks nicks online)|nicks=$numbernicks" exit 0 else echo "CRITICAL - $NICK is not in #$CHANNEL ($numbernicks nicks online)|nicks=$numbernicks" exit 2 fi 
 * 1) !/bin/bash

Since NICK is $1, it means you can pass the nickname you want to check as variable and start it like this:

What you have to change is your channel name and the path to your logfile of course. I additionally count the number of users in the channel, that is optional.

Try to run it manually from the shell and see if it works. Try it as user nagios and make sure permissions are right for that user to execute this command and read the logfile.

Define your command in NRPE config
Now you need to define your new plugin as a command in the local NRPE config, so that it can later be executed by the remote Nagios server.

 command[check_irc_nick_mutante=/usr/lib/nagios/plugins/check_irc_nicks mutante command[check_irc_nick_Edgar23=/usr/lib/nagios/plugins/check_irc_nicks Edgar23 

You can add just one line for one nick here or multiple ones. I define one command per nickname and dont keep it flexible at this point because there were issues with NRPE passing commandline arguments.

Don't forget to restart NRPE now. Something like

Now this server should be ready to answer remote checks from Nagios.

Add a command and service on the Nagios server
Now we switch to the actual Nagios server. First we need to add a check command corresponding to the command we defined on the host running NRPE, like:


 * 1) IRC nick checks

define command{ command_name check_irc_nick_mutante command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_irc_nick_mutante }

define command{ command_name check_irc_nick_Edgar23 command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_irc_nick_Edgar23 } 

Depending on your Nagios config in someting like checkcommands.cfg.

Again, you can add just one or multiple commands, reason for not passing the nickname as argument, see above.

Now we can finally add the actual service check, in f.e. services.cfg:


 * 1) IRC nick checks

define service{ use                            s23-service host_name                      geist service_description            IRC_#seti23_mutante check_command                  check_irc_nick_mutante notifications_enabled          1 }

define service{ use                            s23-service host_name                      geist service_description            IRC_#seti23_Edgar23 check_command                  check_irc_nick_Edgar23 notifications_enabled          1 } 

Again, just examples, but you should be able to figure it out if you have used Nagios before.

Result: