nagibot.pl - A XMPP robot for Nagios(tm) notifications and interaction.
nagibot.pl [options] JID
This program acts as a XMPP bot and forwards Nagios(tm) notifications to XMPP destinations. XMPP destinations may be one or more JIDs or one or more XMPP chatrooms.
The Nagios(tm) process writes the notifications to a pipe where the bot reads and processes them. The requirements are shown in PREREQUISITES.
You can also send messages to the bot (either directly or in a multi user chatroom). The bot accepts a few commands as shown in ACCEPTED COMMANDS.
Print a brief help message and exit.
Print the manual page and exit.
Print version number and exit.
Be verbose. You can specify this more than once to increase verbosity.
Set verbosity to zero. Error messages are printed but no warnings or informational messages will be shown.
Fork and run in background.
Configuration file to use. See CONFIGUATION FILE for details.
The logon password for the JID. You can also set the password via the configuration file.
The configutation file is a three document YAML file. The first part contains a list of multi user chatrooms the bot should join and send messages to. The syntax is:
roomname: Nick in this room
The second part is a list of XMPP IDs (Jabber IDs) the bot should send the notifications to.
- myself@example.com - anotherone@example.com
The last part contains a list of configuration variables (in YAML notation):
If this option is set to one (1), a notification will be sent out to contacts indicating that the current service problem has been acknowledged. The default is 1.
If this option is set to one (1), the comment associated with the acknowledgement will survive across restarts of the Nagios process. If not, the comment will be deleted the next time Nagios restarts. The default is 0.
If this option is set to one (1), the acknowledgement will remain until the host/service return to UP/OK state. Otherwise the acknowledgement will automatically be removed when the service changes state. The default is 1.
XMPP resource of the bot. Defaults to nagibot.pl
Number of minutes before the bot sends an idle presence. The counter is resetted each time a nagios or user message arrives. The default is 5.
XMPP status of the bot. This should be one of 'available', 'away', 'chat', 'dnd' and 'xa'.
XMPP status priority of the bot
XMPP status text of the bot.
Nagios(tm) command file. This file accepts the external Nagios(tm) commands (defaults to /usr/local/nagios/var/rw/nagios.cmd).
The pipe for the communication with the Nagios(tm) process.
Nagios(tm) status file. This file contains the current state of all Nagios(tm) objects (defaults to /usr/local/nagios/var/status.dat).
Logon password of the bot's JID.
Name of the pid file if the bot forks into background. (defaults to /var/run/nagibot/<local-part-of-jid>.pid)
Here is my configuration file:
--- # Rooms to join noc@conference.ruhr-uni-bochum.de: NagiBot
--- # JIDs to inform (none in my case)
--- # Configuration nagios_status_log_file: /opt/nagios/ver/status.log nagios_cmd_file: /opt/nagios/var/rw/nagios.cmd nagios_msg_fifo: /opt/nagios/var/rw/nagibot.fifo bot_status: available bot_status_text: Ich bin ein bot, holt mich hier raus ... bot_status_priority: 0 password: geHa!m ---
That's all.
The bot also reacts to some simple commands sent to it. In a MUC (Multi User Chat) the command has to be preceded by @nagibot.
Here is a list of commands:
The bot reports a list of available commands and a short description of each command.
The bot reports the current Nagios(tm) status. It reports how many services are OK and how many services are in WARNING, CRITICAL or UNKNOWN state.
The bot reports details about the services that are in a state other than OK. It reports the hostname, the name of the service and its last state followed by a new line and the last plugin output.
If <host> is given only the problems for the given host are displayed. You can add an 'all' the the command to display the status of all services of <host>.
The bot reports some information about the system. Currently, only the CPU load of the Nagios(tm) host system is reported.
The bot will acknowledge the given host or service problem.
The bot will schedule a check of the given host or service.
For the bot to work you have to establish a communication channel with the Nagios(tm) process. Since the bot reads from a pipe you have to create one. You can do this with the following command:
mkfifo -m 0660 /path/to/the/pipe
Now you have to instruct the Nagios(tm) process to write to this pipe. An easy way to do this is to define a "notification command". In my installation I've done this with the following definition (the file nagios-misccommands contains a complete example):
# 'service-notify-by-pipe' command definition define command { command_name service-notify-by-pipe command_line /usr/bin/printf "%b" "*$NOTIFICATIONTYPE$* $SERVICEDESC$ \ on $HOSTALIAS$ $SERVICESTATE$\n" \ >> /opt/nagios/var/rw/nagibot.fifo 2>&1 }
If you then configure this command to be one of the contacts' notification command, the bot will be able to get the notifications if Nagios(tm) notifies that contact. Be sure to add this command only to one contact or you will get multiple notification messages. And remember: the command_line MUST be on ONE line!