by Ras
4. October 2012 22:04
Follow the below steps to set up Nagios to send SMS notifications with a GSM modem
1) ############## Install the GSM modem ##############################
Physically connect your GSM modem and find out if it is installed and which tty it is using.
Check if it is installed properly:
lsusb # you should see your device is listed
dmesg | grep tty # will help you to find the proper tty for your device
2) ############## Install gammu #######################################
use yum to install gammu
yum install gammu
3) ############### Specify device in gammu config file /etc/gammurc ######################
[gammu]
port= /dev/ttyS0 #or /dev/ttyUSB0 #or /dev/ttyACM0
connection = at115200
4) ############### Check and set the permissions on the device #####################################
ls -l /dev/ttyS0
crw-rw---- 1 root dialout 4, 64 2008-05-21 14:23 ttyS0
You can notice the usergroup is "dialout" and the owner is root.
You need to add www-data (or apache) and nagios to the dialoutgroup
sudo usermod -a -G dialout nagios
sudo usermod -a -G dialout www-data
5) ################### Test it! #########################################
You can now try to send an SMS :
su nagios
echo "sms test" | /usr/bin/gammu --sendsms TEXT +336xxxxxxxxx
6) ############### Commands on Nagios #########################
define command{
command_name notify-host-by-sms
command_line /usr/bin/printf "%b" "Nagios Notification: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nTime: $LONGDATETIME$\n" | /usr/bin/gammu --sendsms text $CONTACTPAGER$
}
define command{
command_name notify-service-by-sms
command_line /usr/bin/printf "%b" "Nagios Notification: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nTime: $LONGDATETIME$\n" | /usr/bin/gammu --sendsms text $CONTACTPAGER$
}
7) ################## Set up Contacts #################################
define contact{
contact_name SMSUser
alias SMS User
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-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms
email rassoulg@sbs.com.au
pager 0413771358
}
8) ############# Add contacts and notifications to Objects ########################
define host{
use linux-server ; Name of host template to use
host_name nitrogen
alias nitrogen
address 10.21.160.106
contacts SMSUser
first_notification_delay 0
notification_interval 30
notification_period 24x7
}
define service{
use local-service ; Name of service template to use
host_name nitrogen
service_description PING
check_command check_ping!100.0,20%!500.0,60%
contacts SMSUser
first_notification_delay 0
notification_interval 30
notification_period 24x7
}