Send push notifications from Naemon or Nagios using Pushover

[ Update ]

Last couple of months i’ve been using Naemon as an replacement for Nagios. This post is still valid and works just as well for Naemon. However i choose to follow the developers taking Nagios 3 to Nagios 4 with their new project at www.naemon.org when they where kicked out from the Nagios core-team for political reasons. They are doing a great job so take a look at their project and ideas and give it a spin!

[ /Update ]

So i’ve start using another push-service lately as i’ve been experiencing latency in Prowl when loading notifications. I use push for other things as well other than Nagios notifications such as weather-forecasts every morning, downloads, wordpress notifications, backup-jobs etc etc.

Pushover is more or less equal to Prowl in terms of features and plugins available for download but one thing it can do which Prowl cannot is to set icons/logos on an application and this makes the list-view nice and clear.

To set this up you first have to install the app on your iPhone or Android phone and register an account with pushover.net.

Then register your device and create a “Application” on their site. A application is just a way to tell which application is notifying basically and to set your own logos to the alarms etc. You’ll need 2 API keys, one Application key and the User key.

Download the Pushover notification plugin written by Jedda Wignall from github.

I modified the plugin slightly to include the device-parameter when calling the API as i like to send different notifications to different devices using the same user API key. Let me know if anyone is interested in those changes and i’ll publish them (very simple addition to the script)

Next create a new contact in Nagios that will receive the push notifications:

define contact{
        contact_name                    christian-pushover
        alias                           christian pushover notifications
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands   notify-service-by-pushover
        host_notification_commands      notify-host-by-pushover
        _pushover_userkey               qyR<YOURUSERKEY>iJCU
        _pushover_appkey                1My<YOURAPPKEY>Lm87
        _pushover_device                christian-iphone
        }

And add the necessary notification commands:

define command{
       command_name notify-host-by-pushover
       command_line /usr/local/bin/notify_by_pushover.sh -u "$_CONTACTPUSHOVER_USERKEY$" -a "$_CONTACTPUSHOVER_APPKEY$" -s "spacealarm" -t "$HOSTNAME$ is $HOSTSTATE$" -m "Status: $HOSTOUTPUT$"
       }
define command{
       command_name notify-service-by-pushover
       command_line /usr/local/bin/notify_by_pushover.sh -u "$_CONTACTPUSHOVER_USERKEY$" -a "$_CONTACTPUSHOVER_APPKEY$" -s "spacealarm" -t "$SERVICEDESC$ on $HOSTNAME$ is $SERVICESTATE$" -m "Status: $SERVICEOUTPUT$"
       }

And you’ll need to add your new contact to your hosts and services or contact-group to start getting the push-notifications to your phone.

/Christian

Monitor Synology DiskStation NAS (DS211J / DS415+) using SNMP and Nagios or Naemon Core

Why not add enterprise class monitoring of your Synology DiskStation NAS using Nagios or Naemon Core and the standard plugins packages included in most distributions or available in community repositories to simply get good control over your precious data?

This will help anyone who wants to set up the most important things to keep control of your data without the need for deep knowledge of SNMP to do so. However basic editing skills and basic knowledge of Linux as well as know how to configure Nagios is as must as this article won’t cover those steps.

All checks has been verified for DS211J and DS415+ and for the latter i needed to change disk integers a bit to get all the disks monitored.

The SNMP plugin used for most monitoring is check_snmp and available for most distributions “nagios-plugins / monitoring-plugins” and the plugin for monitoring interfaces is developed by op5 and available in the git repositories (needs to be compiled)

This will help you monitor:

  • CPU Usage
  • CPU Fan Status
  • Disk 1 & 2 Status (My NAS only has two drives)
  • Disk 1 & 2 Temperature
  • Memory Usage
  • Power Status (Maybe too much as my NAS only has one power supply and if it breaks.. well, i’ll know!)
  • Raid Status
  • Swap Usage
  • System Fan Status
  • System Status
  • Network card(s) / Interfaces

 

So first we’ll define the commands to use, check_snmp is the plugin of choice here so add the following to your checkcommands.cfg (or nagios-plugins conf.d directory)

 

define command{
command_name check_synology_disk_temperature
 command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -C $ARG1$ -o .1.3.6.1.4.1.6574.2.1.1.6.$ARG2$ -l "Temperature" -u C -w $ARG3$ -c $ARG4$
 }
define command{
 command_name check_snmp_process
 command_line $USER1$/check_snmp_process -H $HOSTADDRESS$ -C $ARG1$ -n "$ARG2$" -F
 }
define command{
command_name check_synology_cpu
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -o .1.3.6.1.4.1.9.2.1.58.0 -w $ARG1$ -c $ARG2$ -C$ARG3$ -u % -l "CPU load is" -m:
}
define command{
command_name check_synology_disk_status
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -C $ARG1$ -o .1.3.6.1.4.1.6574.2.1.1.5.$ARG2$ -l "Diskstatus" -s 1
}
define command{
command_name check_synology_raid_status
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -C $ARG1$ -o .1.3.6.1.4.1.6574.3.1.1.3.$ARG2$ -l "Raid status" -s 1
}
define command{
command_name check_synology_system_status
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -C $ARG1$ -o .1.3.6.1.4.1.6574.1.1.0 -l "System status" -s 1
}
define command{
command_name check_synology_power_status
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -C $ARG1$ -o .1.3.6.1.4.1.6574.1.3.0 -l "Power status" -s 1
}
define command{
command_name check_synology_fan_status
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -C $ARG1$ -o .1.3.6.1.4.1.6574.1.4.1.0 -l "System fan status" -s 1
}
define command{
command_name check_synology_cpufan_status
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -P 1 -C $ARG1$ -o .1.3.6.1.4.1.6574.1.4.2.0 -l "CPU fan status" -s 1
}
define command{
command_name    snmp_cpu_all
command_line    $USER1$/check_snmp -H '$HOSTADDRESS$' -C '$ARG1$' -o .1.3.6.1.4.1.2021.11.9.0,.1.3.6.1.4.1.2021.11.10.0,.1.3.6.1.4.1.2021.11.11.0 -w :'$ARG2$',:'$ARG3$',:'$ARG4$' -c :'$ARG5$',:'$ARG6$',:'$ARG7$' -l user,system,idle -u%,%,%
}
define command{
command_name    snmp_mem
command_line    $USER1$/check_snmp -H '$HOSTADDRESS$' -C '$ARG1$' -o .1.3.6.1.4.1.2021.4.6.0,.1.3.6.1.4.1.2021.4.5.0 -w '$ARG2$': -c '$ARG3$': -l available,total -u kb,kb
}
define command{
command_name    snmp_swap
command_line    $USER1$/check_snmp -H '$HOSTADDRESS$' -C '$ARG1$' -o .1.3.6.1.4.1.2021.4.4.0,.1.3.6.1.4.1.2021.4.3.0 -w '$ARG2$': -c '$ARG3$': -l free,total -u kb,kb
}

 

These commands uses the op5-plugin (info above)

define command{
 command_name check_traffic
 command_line $USER1$/check_snmpif traffic -H $HOSTADDRESS$ -C $ARG1$ -i $ARG2$ -b $ARG3$ -w $ARG4$ -c $ARG5$
 }
define command{
 command_name check_iferrors
 command_line $USER1$/check_snmpif errors -H $HOSTADDRESS$ -C $ARG1$ -i $ARG2$ -w $ARG3$ -c $ARG4$ -t 10
 }
define command{
 command_name check_ifoperstatus
 command_line $USER1$/check_snmpif status -H $HOSTADDRESS$ -C $ARG1$ -v 1 -k $ARG2$
 }

And when this is done, add the services to your configuration:

define service{
use generic-service; name of service template to use
host_name diskstation
service_description if 2: eth0 errors
check_command check_iferrors!public!2!1.5!2.5
}
define service{
use generic-service ; name of service template to use
host_name diskstation
service_description if 2: eth0 status
check_command check_ifoperstatus!public!2
}
define service{
use generic-service ; name of service template to use
host_name diskstation
service_description if 2: eth0 traffic
check_command check_traffic!public!2!1000mbit!70!90
}
define service{ 
use generic-service ; name of service template to use 
host_name diskstation 
service_description cpu usage 
check_command snmp_cpu_all!public!75!75!100!90!90!100
}
define service{
use generic-service ; name of service template to use
host_name diskstation
service_description memory usage
check_command snmp_mem!public!8000!4000
}
define service{
use generic-service ; name of service template to use
host_name diskstation
service_description swap usage
check_command snmp_swap!public!1202498!800000
}
define service{
use generic-service ; name of service template to use
host_name diskstation
service_description ping
check_command check_ping!20,40%!100,60%
}
define service{
use generic-service
host_name diskstation
service_description system status
check_command check_synology_system_status!public
}
define service{
use generic-service
host_name diskstation
service_description power status
check_command check_synology_power_status!public
}
define service{
use generic-service
host_name diskstation
service_description system fan status
check_command check_synology_fan_status!public
}
define service{
use generic-service
host_name diskstation
service_description cpu fan status
check_command check_synology_cpufan_status!public
}
define service{
use generic-service
host_name diskstation
service_description disk 1 temperature
check_command check_synology_disk_temperature!public!0!45!50
}
define service{
use generic-service
host_name diskstation
service_description disk 2 temperature
check_command check_synology_disk_temperature!public!1!45!50
}
define service{
use generic-service
host_name diskstation
service_description disk 1 status
check_command check_synology_disk_status!public!0
}
define service{
use generic-service
host_name diskstation
service_description disk 2 status
check_command check_synology_disk_status!public!1
}
define service{
use generic-service
host_name diskstation
service_description raid status
check_command check_synology_raid_status!public!0
}

This is pretty much it!

Here’s a screenshot with this config running:

Synology-Nagios-Screenshot

/Christian

Get calendar data using google-cli (Python) for easy scripting!

I needed to backup my Google Drive documents to my NAS at home and while i was at it i also used this stuff to export my calendar to a nice plain-text list for later scripting. So if anyone is interested this is how i did it on my mac to get all events from my calendar to a nice formatted list to create your own todo-list or motd message when open your terminal or whatever you like to do!

 

Get the needed files, assumed you have python already installed on your machine:

wget http://gdata-python-client.googlecode.com/files/gdata-2.0.14.tar.gz
wget http://googlecl.googlecode.com/files/googlecl-0.9.13.tar.gz

 

Unpack and install:

tar -zxvf gdata-2.0.14.tar.gz && cd gdata-2.0.14 && sudo python setup.py install
tar -zxvf googlecl-0.9.13.tar.gz && cd googlecl-0.9.13 && sudo python
setup.py install

 

Locate where google-cli ended up, on my mac:

/opt/local/Library/Frameworks/Python.framework/Versions/2.5/bin/google (On my linux box it ended up in /usr/local/bin/)

Create symlink or copy to /usr/local/bin/ (or add to PATH)

 

Next, make a test run, you’ll need to authenticate first time and allow your computer to access the calendar (or tasks, drive etc etc):

cn-macbook-w:~ christian$google calendar today

 

follow the instructions to authenticate and create tokens (very easy!) On osx the default browser pops up and wants you to authenticate, if no x-server it will print out a http-url you need to copy-paste in a browser and allow your computer to access the info.

 

run it again:

cn-macbook-w:~ christian$google calendar today
[christian@sodermalm.net]
testing,Oct 20 11:00 - Oct 20 12:00

 

Sweet, now i want to get the whole month of october as a list:

cn-macbook-w:~ christian$ google calendar list --date
2013-04-01,2013-04-30 --fields title,when,where
Admin,Oct 29 00:00 - Oct 30 00:00,Home
Massage,Oct 29 17:30 - Oct 29 18:30,Stockholm

… ETC …

 

Been using different methods of accessing googles APIs before (javascript directly from spreadsheets etc) but with these packages it makes scripting and automating stuff a breeze 🙂 If anyone have a better way of doing this i would like to know more so write me a comment! 🙂

/Christian

Send Prowl notifications from op5 Monitor or Nagios

Install the Prowl iPhone app and register for an API-key so you can associate your push-notifications to your phone.

Create a new contact (example):

define contact{
 contact_name <Your-name>-push
 alias <Your-name> push notifications
 service_notification_period 24x7
 host_notification_period 24x7
 service_notification_options w,u,c,r
 host_notification_options d,u,r
 service_notification_commands notify-service-by-prowl
 host_notification_commands notify-host-by-prowl
 _prowl_apikey <Your API key>
 }

Add following notification commands:

define command{
 command_name host-notify-by-prowl
 command_line /usr/bin/perl -w /usr/local/bin/prowl.pl -apikey="$_CONTACTPROWL_APIKEY$" -priority=1 -application="Nagios-RPI" -event="$HOSTNAME$ is $HOSTSTATE$" -notification="Status: $HOSTOUTPUT$"
 }
define command{
 command_name service-notify-by-prowl
 command_line /usr/bin/perl -w /usr/local/bin/prowl.pl -apikey="$_CONTACTPROWL_APIKEY$" -priority=1 -application="Nagios-RPI" -event="$SERVICEDESC$ on $HOSTNAME$ is $SERVICESTATE$" -notification="Status: $SERVICEOUTPUT$"
 }

And install the perl push-notification plugin from prowlapp.com https://www.prowlapp.com/static/prowl.pl

If you like me run Nagios on a Raspberry Pi and wish to avoid to execute perl-code to save resources there are a C version as well which more or less don’t have much overhead.

Not very detailed instructions but the main parts are there so good luck!

/Christian

Loopia DDNS in dd-wrt

There’s a few posts all over the internet when you try to find information about how to use DDNS in dd-wrt
with Loopia as your DNS provider. I found this post in one of the forums by “Codetracer” (Thanks!) pointing me in the right direction although didn’t manage to get it to work at first and the reason for that was that my build 16994 had a broken Inadyn daemon. Updated to 18024 and all worked fine.

For this to work your WAN interface needs to be your external interface and have your external
IP as we fetch that information from NVRAM. In other cases you need to fetch this information
using a external page (Example below).

Do the following (Copy paste from the forum):

– DDNS Service can be disabled. At least thats how I do it.

– Add your info to the code. Change *USERNAME*, *PASSWORD*, *FQDN_HOST_NAME* (zzz.yyy.com)
Where username usually is your primary domain

– Open DD-WRT web interface and go to “Administration” –> “Commands”

– Paste code in “Command Shell” and make sure the string is

– Click “Save Startup”

– Reboot router.

– Done!

– Check /tmp/ddns/ddns.log for messages about last update.

#DDNS(inadyn) for Loopia
sleep 10
mkdir /opt/tmp/ddns 
/usr/sbin/inadyn -u *USERNAME* -p *PASSWORD* --background --dyndns_system \
custom@http_svr_basic_auth -a *FQDN_HOST_NAME* --update_period_sec 600 \
--forced_update_period 864000 --log_file /tmp/ddns/ddns.log --cache_dir \
/tmp/ddns --exec ddns_success --dyndns_server_name dns.loopia.se \
--dyndns_server_url /XDynDNSServer/XDynDNS.php?system=custom\&myip=$(nvram get wan_ipaddr)\&hostname=

There are a few thing worth mentioning. As cache and logs are stored i /tmp this will be cleared when
the router reboots and this will force a update of your DNS at startup. Not sure about Loopia but several
other providers simply blocks your IP for a period of time. To be on the safe side use persistent storage
for example a USB stick to store cache data and logs.

If your WAN interface isn’t you external interface and doesn’t have your external ip (you are on LAN) add the following option to fetch the public IP

--ip_server_name dns.loopia.se/checkip/checkip.php

Over and out!

/Christian

Loopia DDNS på Synology ds211j

Finns så fantastisk lite info på webben om hur man kan få igång loopias DDNS i routers eller i mitt fall min Synology NAS.

Så som en reminder till mig själv när jag ska få in DDNS i min dd-wrt router så skriver jag ner hur jag fick igång det i min NAS.

Editera /etc.defaults/ddns_provider.conf och lägg till entry för loopia:

[Loopia.se]
 modulepath=DynDNS
 queryurl=dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname=__HOSTNAME__&myip=__MYIP__

gå sedan in i DDNS i Control panel och välj i listan “Loopia.se”
Hostname:mindomän.se
Username:mindomän.se
Password:lösenord

Håll koll på statusen under rutan så att det kommer upp “Normal” så är DNS:en uppdaterad.

Additional DDNS providers in Synology ds211j

Translated an old post so it will be easier to find for others who are interested in this topic.

This was actually a workaround when writing the original post. I didn’t manage to get Loopia DDNS updates to work on my DD-WRT so i added this to my NAS instead to update my domain.

It later turned out that Inady on the build i was using was broken and is corrected in later builds. I have written a post about that topic earlier.

As a reminder to self i’ll write down the information here for later use and for others interested in doing this.

Access your Synology NAS using SSH

Edit /etc.defaults/ddns_provider.conf and simply add the following entry (for Loopia in this case) :

[Loopia.se]
 modulepath=DynDNS
 queryurl=dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname=__HOSTNAME__&myip=__MYIP__

Now you can select Loopia.se option in the DDNS configuration in the control panel.

Add your information:

Hostname:mydomain.com
Username:yourusername
Password:yourpassword

Save and keep an eye on the status box and when it states “Normal” you DNS should be updated.