In our previous post, we have seen how to configure sms gateway server on your environment. With the help of the sms gateway server, we can able to receive the nagios alert. Please follow the below steps.
Assumption:
– Nagios server and clients are configured and running
– Mobile tethering is enabled and support unlimited SMS
– Ozeki NG SMS gateway server is running
All above three assumptions have been explained in this blog previously. Kindly do visit and start monitoring your infrastructure efficiently.
Step 1: Install SMS plugin in nagios server
[root@server.local ~]# vi /usr/local/nagios/libexec/nagios_sms.sh
Copy and paste the below lines
#!/bin/bash
url1="http://127.0.0.1:9501/api?action=sendmessage&username=admin&password= abc123&recipient=0123456789&messagetype=SMS:TEXT&messagedata="
url2="$@"
url2+=$(php -r "echo rawurlencode('$(sed "s/'/\\\\'/g" <<< )');")
url=$url1+$url2
wget -O- "$url"
where,
http://127.0.0.1:9501 — the computer Ozeki NG SMS Gateway has been installed
username=admin — username you use to log into Ozeki NG SMS Gateway
password=abc123 — password of the user
recipient=0123456789 — recipient’s phone number
Step 2: Define command for nagios sms plugin
[root@server.local ~]# vi /usr/local/nagios/etc/objects/commands.cfg
Copy and paste the below lines
# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/local/nagios/libexec/nagios_sms.sh "--Nagios Service Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$ Service $SERVICEDESC$ Description: $SERVICESTATE$ Time: $LONGDATETIME$"
}
# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/nagios/libexec/nagios_sms.sh "--Nagios Host Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$, Time: $LONGDATETIME$"
}
Save and Exit (:wq!)
Step 3: Define contacts
[root@server.local ~]# vi /usr/local/nagios/etc/objects/contacts.cfg
Copy and insert the below lines in nagiosadmin template
service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms
It looks like below changes;
define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms
email nagios@localhost
}
Save and Exit (:wq!)
Step 4: Restart the nagios
[root@server.local ~]# /etc/init.d/nagios restart
That’s it.. Now nagios alerts are triggered to SMS gateway server and finally recipient start receiving alerts.
Cool š