I thought it’s a good idea to use Nabaztag also for a regular status message about the host and service state.
Based on my other script notify-by-nabaztag.php (see this post) i’ve wrote another little PHP-Script which gets the Nagios/Icinga Status from the nagiostats/icingastats utility and use my notify-by-nabaztag.php to send out a status message. Here it is: status2nabaztag.php
There are just a few steps to get up and running:
1. Grap my notify-by-nabaztag.php and the status2nabaztag.php scripts
2. Change, if required, paths to the binaries. Specially $stats & $php
3. Test it
php /usr/local/icinga/bin/status2nabaztag.php
4. Assuming everything worked as expected you can add an entry to your crontab to regulary executes the script. I know, it would be a nicer to use the Nagios/Icinga timeperiod-definitions, but the crontab-entry is easier
This cron entry will executes the script every day between 6am and 11pm.
It’s just a short post, but i think the script should be self explaining too. Furthermore it’s quite late/early, so i’ll try to get some sleep because i have to get up in 3hours
Hope this script is useful too. Please let me know if you have any troubles to get it running.
Since i have my Nabaztag-Bunny i ever wanted to use it for my Icinga notifications. I’ve found a perl script on the internet. But that one just sent out a message and not used LED flashing or ear movements also provided by the Nabaztag-API.
So I’ve wrote my own notification script in PHP. You can download it here: notify-by-nabaztag.php
You can watch a video demonstrating it in action here in the following embedded Windows Media Player or at YouTube
The script is quite simple. It’s need two arguments. The first one is the message for the TTL (text-to-speech) and the second one is the “notification type”. The notification type is either the service or host state (OK, WARNING, CRITICAL, UNKNOWN, UP, DOWN, UNREACHABLE).
Depending on the notification type the bunny is flashing in a different color and moves it’s ears to another position:
OK/UP:
flashing green, ears going up
WARNING:
flashing yellow, both ears are moved to the front with an angle of 45°
CRITICAL/DOWN:
flashing red, ears going down
UNKNOWN/UNREACHABLE:
flashing blue, one ear to the front, one to the back, each with an angle of 45°
You can configure the voice which should be used inside the script. I propose to use a US/UK one because the states are in English too. I think the script should be self-explaining. If not, just leave an comment.
When you already have Nagios/Icinga up and running you should also know how to add an new notification command. Otherwise here are the basic steps (assuming you are running Icinga within /usr/local/icinga):
1. We need php-cli installed so we can run the script on the CLI. Depending on your distro run on of the following commands
# ‘notify-service-by-nabaztag’ command
define command{
command_name notify-service-by-nabaztag
command_line /usr/bin/php $USER1$/notify-by-nabaztag.php “Monitoring Notification: $NOTIFICATIONTYPE$ on $HOSTNAME$ (Hostalias is $HOSTALIAS$) with Service: $SERVICEDESC$. Current servicestate is $SERVICESTATE$” $SERVICESTATE$
}
# ‘notify-host-by-nabaztag’ command
define command{
command_name notify-host-by-nabaztag
command_line /usr/bin/php $USER1$/notify-by-nabaztag.php “Monitoring Notification: $NOTIFICATIONTYPE$ on $HOSTNAME$ (Hostalias is $HOSTALIAS$). Hoststate is $HOSTSTATE$” $HOSTSTATE$
}
4. I’ve created a new time period, because I don’t want that my bunny is talking to me during the night
vim /usr/local/icinga/etc/objects/timeperiods.cfg
# ‘nabazhours’
define timeperiod{
timeperiod_name nabazhours
alias Where my nabaztag is active
monday 06:00-23:00
tuesday 06:00-23:00
wednesday 06:00-23:00
thursday 06:00-23:00
friday 06:00-23:00
saturday 08:00-23:00
sunday 08:00-23:00
}
5. After that a new contact is created which use the above added notification commands and the right time period
vim /usr/local/icinga/etc/objects/contacts.cfg
define contact{
contact_name nabaztag
use generic-contact
alias My Bunny
service_notification_commands notify-service-by-nabaztag
host_notification_commands notify-host-by-nabaztag
service_notification_period nabazhours
host_notification_period nabazhours
}
6. We should have enough time to run a config-check
Ever wanted to deleted (or move, copy, what else) all files in a directory? It’s quite easy:
egrep -l NEEDLE * | xargs rm
This command will find all files with NEEDLE in it, pipes the filename (that’s because we need the parameter L) to xargs which then use the STDIN (our filename) and put’s it to rm.
Just play around with it the possible parameters. It would save you a lot of time.