Nagios – is an open source program, designed for monitoring computer systems and networks, namely: monitoring, controlling the status of calculation nodes and services, and alerting system administrators in case of stopping or continuing of operation of any services.
Together with sending e-mail notifications to notify system administrators, it is possible to use SMS notifications, which increases the reaction speed to the issues that appear during the service operation. To send SMS, it is possible to use the next devices of the NetPing company:
This allows to significantly minimize the use of third-party services of SMS sending because in this case the price of an SMS will correspond to the rates of the cell operator without additional commissions.
Let us consider the example of sending SMS notifications from the monitoring system Nagios with the use of NetPing devices.
Requirements to Equipment
- NetPing device with a preinstalled SIM card – 1 pc.;
- PC/server with Ubuntu OS and a preinstalled Nagios system – 1 pc;
- Local network – 1 pc.
In our example, we use Nagios Core 4.3.4, installed at Ubuntu Server 16.04.3 LTS
To get the information on configuring a minotoring system Nagios, it is possible to address the official documentation.
Preparing a Script for Sending SMS
To implement the feature of sending SMS, let us write a script on a script programming language BASH:
#!/bin/bash
curl --user visor:ping --data "[$1] $2" http://192.168.0.100/sendsms.cgi?utf8
Parameters that need to be changed when using a script in your monitoring system Nagios are as follows:
visor – is a user name for authorization on a NetPing device;
ping – is a password for authorization on a NetPing device;
192.168.0.100 – is a current IP address of a NetPing device
Prepared file of a script: sendsms.sh
Let's locate a file of a script in the operating directory Nagios (in our example /usr/local/Nagios/etc/objects/) and assign rights to launch the script to a Nagios user:
sudo chown nagios:nagios /usr/local/nagios/etc/objects/sendsms.sh
sudo chmod 776 /usr/local/nagios/etc/objects/sendsms.sh
Then, continue to configuring Nagios.
Configuring Nagios
A web-interface of the Nagios system is designed only for viewing a status of devices. All configurations are saved in configuration files.
In the file commands.cfg, specify commands for sending notifications (in our example /usr/local/nagios/etc/objects/command.cfg):
# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/nagios/etc/objects/sendsms.sh $CONTACTPAGER$ "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ "
}
# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/local/nagios/etc/objects/sendsms.sh $CONTACTPAGER$ "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ "
}
Close the file with saved changes.
Now, to make it convenient, let's create a new contact that will receive SMS-notifications from Nagios, and specify commands for it to execute when receiving a signal about the activation of nodes under control.
Let's open the file /usr/local/nagios/etc/objects/contacts.cfg for editing:
define contact{
contact_name smsrecipient
alias Sms Recipient
email nagios@localhost
pager 79000000000
service_notification_period 24x7
service_notification_options w,u,c,r
service_notification_commands notify-service-by-sms
host_notification_period 24x7
host_notification_options d,u,r
host_notification_commands notify-host-by-sms
}
A phone number to receive notifications should be indicated in the line «Pager»:
To enable sending notifications to the created user smsrecipient, let's add it to the group Nagios Administrators. It can be done in the same file /usr/local/nagios/etc/objects/contacts.cfg a little below:
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin, smsrecipient
}
Close a file with saving changes.
Nagios has a built-in means for checking configuration files or errors. It can be launched from terminal.
Check configuration files by a command (1):
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
And, if everything is normal (2), restart Nagios (3):
sudo systemctl restart nagios.service
Configuring Devices NetPing SMS, UniPing server solution v4/SMS, NetPing 8/PWR-220 v4/SMS
In our case, to send SMS notifications, it is enough to perform only a part of a basic configuration (configure network parameters to access the network) of devices NetPing SMS, UniPing server solution v4/SMS, NetPing 8/PWR-220 v4/SMS and install a working SIM card with a positive balance into the slot of a built-in GSM modem. It is possible to read about a basic and additional configuration of devices in the next documentation:
- NetPing SMS – firmware description;
- UniPing server solution v4/SMS – firmware description;
- NetPing 8/PWR-220 v4/SMS – firmware description
Result
As a result of using the configuration of sending SMS notifications on events in the monitoring system Nagios described above and using an SMS gateway on the basis of NetPing SMS, UniPing server solution v4/SMS, NetPing 8/PWR-220 v4/SMS devices, system administrators will receive SMS notifications of the next appearance: