Category: Linux

Nabaztag tells you your Nagios/Icinga status

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

wget http://www.sperrgebiet.org/wp-content/uploads/2010/02/notify-by-nabaztag.txt -O /usr/local/icinga/libexec/notify-by-nabaztag.php

wget http://www.sperrgebiet.org/wp-content/uploads/2010/02/status2nabaztag.txt -O /usr/local/icinga/bin/status2nabaztag.php

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 ;)

vim /etc/crontab

0 6-23 * * * root /usr/bin/php /usr/local/icinga/bin/status2nabaztag.php

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.

Remember: In god we trust, the rest we monitor :)

Nagios/Icinga meets Nabaztag

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

 aptitude install php-cli
or
yum install php-cli

2. Download the script to your libexec-Directory:

wget http://www.sperrgebiet.org/wp-content/uploads/2010/02/notify-by-nabaztag.txt -O /usr/local/icinga/libexec/notify-by-nabaztag.php

 

 

3. Add a host and service notification command. If you want a more detailed output just add it to the right position. You’ll find all available Macros at http://nagios.sourceforge.net/docs/3_0/macrolist.html

vim /usr/local/icinga/etc/objects/commands.cfg

# ‘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 ;)

/usr/local/icinga/bin/icinga -v /usr/local/icinga/etc/icinga.cfg

7. When no errors or warnings appear reload Nagios/Icinga and wait till problem occur ;)

/etc/init.d/icinga reload

Hope everything works as expected and you’ll find this script useful. Have fun with Nagios/Icinga and your Bunny. J

Automatic SSH logon

Host1:

  1. ssh-keygen
  2. No PassPhrase (so automatic logon works)
  3. Default filename and path is ok
  4. cat ~/.ssh/id_rsa.pub
  5. Copy content of id_rsa.pub

 

Host2:

  1. Create ~/.ssh
  2. Create ~/.ssh/authorized_keys
  3. Paste content of clipboard into authorized_keys

 

Both steps vice vera

 

At the first logon a warning appears that the hostkey is added

to know_hosts. Yes to proceed.

 

That’s it ;)

Find and delete files with specific content

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.

WordPress Themes