wol nagios pluging

Here is yet another useful nagios pluging that check to see if a target is alive, by sending a continuous ping.
when the target is down the script send the magic packet frame to turn on the machine.
You can download it here

For installing the pluging follow the same step in openvpn nagios pluging article.

At last define the wol service like this

$ sudo cat >> /etc/nagios3/conf.d/services_nagios2.cfg

define service {
hostgroup_name wol
service_description Wake on LAN
check_command check_wol!host!broadcast!mac address!mode
use generic-service
notification_interval 0
}

replace “host” by the ip address or the hostname of your target, “broadcast” by the broadcast ip address, “mac address” by the mac address of your target and mode by “LAN” if your host reside in the local area and by “WAN” if it is in the other side of internet.

Example:

define service {
hostgroup_name wol
service_description Wake on LAN
check_command check_wol!192.168.0.1!192.168.0.255!00:19:db:d5:0d:2d!LAN
use generic-service
notification_interval 0
}

Advertisements

Openvpn nagios pluging

You can use Nagios to monitor all sorts of hardware and software. The opportunity to write your own plug-ins makes it possible to monitor everything that your Nagios server can communicate with. As you can use any computing language that manages command-line arguments and exit status.
Here you find a nagios pluging developed with python.
The pluging named check_openvpn, it connects to the management OpenVPN server checks for actives connection and return the amount connected OpenVPN clients. it’s forked from openvpn-status scripts.

First of all download the check_openvpn script into your pluging directory on debian it’s /usr/lib/nagios/plugins/.

To use the new plug-in, you have to register it first, create the file command called openvpn.cfg with contents as below:

$ sudo cat > /etc/nagios-plugins/config/openvpn.cfg

define command {
command_name check_openvpn
command_line /usr/lib/nagios/plugins/check_openvpn -t $ARG1$ -p $ARG2$ -n $ARG3$
}

Let’s create some hostgroups – say openvpn-server

$ sudo cat >> /etc/nagios3/conf.d/hostgroups_nagios2.cfg

define hostgroup {
hostgroup_name openvpn-server
alias openvpn servers
members myhost
}

replace vpn.example.com by your openvpn server address, and myhost by the openvpn server name.
Now let’s define those hosts:

$ sudo cat >> /etc/nagios3/conf.d/hosts.cfg

define host {
use generic-host;
host_name myhost;
address vpn.example.com;
}

Now we can define services that run in the new hostgroups

$ sudo cat >> /etc/nagios3/conf.d/services_nagios2.cfg

define service {
hostgroup_name opevpn
service_description OPENVPN
check_command check_openvpn!host!port!passwd
use generic-service
notification_interval 0
}

replace “host” by the address of your openvpn server, “port” by the openvpn management server port and “passwd” by the openvpn nanagement server password.

Don’t forget to check your configuration
$ sudo nagios3 -v /etc/nagios3/nagios.cfg

Then restart the daemon
$ sudo /etc/init.d/nagios3 restart

If all that went well, you should be able to go back to the Hostgroup Overview page on your Nagios install and see the new hostgroups and hosts.

How to configure Nagios to send sms to your mobile

Nagios is an open source host, service and network monitoring program. The official homepage is http://nagios.org/, and i use it with cacti to monitor my network.
Nagios sends you an alert via email, sms when a service is down, the sms solution is very usefull when your smtp server is unreachable.
You can drive a GSM mobile by your favorite operating system. With an usb data cable connect it to your monitoring server.
On debian there are a too packages for communicating with mobile phones (gnokii and gsm-utils), at first we’ll use gsm-utils you can get it like:
$ sudo apt-get install gsm-utils
Verify first that your GSM is connected to your server
$ sudo ls -al /dev/ttyUSB*
You can now test it by sending a sms to your mobile number +3299999999.
$ sudo gsmsendsms -d /dev/ttyUSB0 +3299999999 “Nagios – Test SMS OK”
If the test is OK, that mean you will be able to configure nagios to send sms to your phone.
Add a pager to your contact info in /etc/nagios3/conf.d/contacts_nagios2.cfg and set up sms notification mode like:

define contact{
contact_name mezgani
alias Ali MEZGANI
service_notification_period 24×7
host_notification_period 24×7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms
email mezgani@secufox.org
pager +329999999999
}

Now you have to define a command, which talks to our sms-notification-software,
so add these lines to your /etc/nagios3/commands.cfg

define command{
command_name notify-service-by-sms
command_line /usr/bin/gsmsendsms -d /dev/ttyUSB0 $CONTACTPAGER$ “Nagios – $NOTIFICATIONTYPE$ : $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ ($OUTPUT$)”
}

define command{
command_name notify-host-by-sms
command_line /usr/bin/gsmsendsms -d /dev/ttyUSB0 $CONTACTPAGER$ “Nagios – $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)”
}

At this point, you’ve done.
For gnokii users, you can also get it by aptitude as:
$ sudo aptitude install gnokii

Send you a sms test by:
$ echo “Hello world!” | gnokii –sendsms +329999999999 -r

Later, add these lines to your /etc/nagios3/commands.cfg

define command {
command_name notify-service-by-sms
command_line /usr/bin/printf “%.120s” “Nagios – $NOTIFICATIONTYPE$ : $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ ($OUTPUT$)” | /usr/local/bin/gnokii –sendsms $CONTACTPAGER$ -r
}

define command {
command_name notify-host-by-sms
command_line /usr/bin/printf “%.120s” “Nagios – $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)” | /usr/local/bin/gnokii –sendsms $CONTACTPAGER$ -r
}

Well, i can not get a dedicated GSM for my monitoring server right now, in my country there are some providers that purpose some sms services like sending free sms via web to mobile for example meditel.
in the suite we will focus on how to configure nagios to send sms to meditel mobile via a python script.
If your operators is meditel, get meditelsms package :
$ git clone git://github.com/mezgani/meditelsms.git.
and now add this following lines to your commands.cfg, change the path of your script in our example i used /home/mezgani/script/sms.py

define command{
command_name notify-host-by-sms
command_line /usr/bin/printf “%.120s” “Nagios – $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)” |/usr/bin/python /home/mezgani/script/sms.py $CONTACTPAGER$
}

define command{
command_name notify-service-by-sms
command_line /usr/bin/printf “%.120s” “Nagios – $NOTIFICATIONTYPE$ : $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ ($OUTPUT$)” |/usr/bin/python /home/mezgani/script/sms.py $CONTACTPAGER$
}