Hardware SMS Gateway for Monit Monitoring System

  • Published In: Tutorial
  • Created Date: 2019-01-11
  • Hits: 221

This article is a logic sequel to the article «Example of Server Room Monitoring on the Basis of MONIT, INFLUXDB, GRAFANA, and NetPing Monitoring Units». Within this article, a feature of configuring SMS notifications from the Monit monitoring system using NetPing SMS gateway will be examined (hardware SMS gateway for Monit).

For sending SMS, it is possible to use the next devices of the NetPing company:

A feature of SMS notifications will allow the IT personnel to react to events in the network urgently and thus minimize business downtime caused by failures in the operation of the IT equipment. Also, a company can significantly save on third-party services for SMS-sending because in this case, the cost of SMS will correspond to the tariff provided by the cell operator with no additional commissions.

Requirements to the Equipment

  • One of the NetPing devices listed above with the installed SIM card – 1 pc;
  • PC/server with Ubuntu OS and already installed Monit monitoring system  – 1 pc;
  • Local network – 1 pc.

In our example, we use Monit v 5.25.2 that is installed at Ubuntu Server 16.04.3 LTS. For receiving information on configuring Monit monitoring system, it is possible to address the official documentation. Also, deployment and configuration are described in details in this article of our blog.

Configuring NetPing Devices

NetPing SMS device is a hardware GSM gateway

In our case, for sending SMS notifications, there is a need to perform only a part of a basic configuration (configure network parameters for network access) for devices NetPing SMSUniPing server solution v4/SMSNetPing 8/PWR-220 v4/SMS, and install a working SIM card with a positive balance in the slot of the built-in GSM modem. It is possible to read about the basic and auxiliary configuration of devices in the next documentation:

Implementing Sending SMS Notifications from the Monit Monitoring System

Monit. Homepage of the system web interface

Let's consider that the gateway for sending and receiving SMS notifications NetPing SMS is accessible in the local network with the next parameters:

  • IP address – 192.168.1.200;
  • Login – visor;
  • Password – ping

Directories for saving user files and scripts in the Monit monitoring system are the next:

  • /home/user/monit/conf/user/
  • /home/user/monit/conf/script/

For implementing the feature of sending SMS, let's write a script on the script programming language BASH. The script uses the feature of sending SMS notifications using URL-encoded commands. More detailed information about variants of sending SMS can be read in the documentation.

#!/bin/bash
curl --user visor:ping --data "[$1] $2" http://192.168.1.200/sendsms.cgi?utf8

Parameters that should be changed when using the script in your Monit monitoring system are as follows:

  • visor – is a user name for authorizing at a NetPing device;
  • ping – is a password for authorizing at a NetPing device;
  • 192.168.1.200 – is a current IP address of a NetPing device

A prepared script file is sendsms.sh

Let's locate the script file in the script directory (in our example /home/user/monit/conf/script/ ) and make the file executable using the next command:

chmod +x /home/user/monit/conf/script/sendsms.sh

For the script to work, there is a need to install the CURL utility (if it had not been installed before) using the next command:

sudo apt-get install curl

Then, open the file with monitoring configurations in the Monit system for editing. (In our example, /home/user/monit/conf/user/netping) and indicate the action «Run the script» for each monitoring object which state is going to be tracked using SMS notifications:

exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Locst conenction with the device NetPing_8_PWR-220_v3SMS"

The first argument to pass to the script parameters is the receiver's phone number (it is possible to indicate different receivers for various event types), the second argument is the text of the SMS notification (Cyrillic is supported, quotes are a must). A sample file code with monitoring parameters is given below:

check host NetPing_SMS with address 192.168.1.200
if failed ping then alert

check host NetPing_8_PWR-220_v3SMS with address 192.168.1.210
if failed ping then
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Lost connection with device NetPing_8_PWR-220_v3SMS"

check program Temperature_1 with path "/root/monit/conf/scripts/get_temp1w.sh 1"
if status == 1 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Data from the temperature sensor #1 is not received. SNMP failure"
if status == 2 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Temperature sensor #1 is not connected or not working"
if status == 3 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "The temperature on the sensor #1 below normal"
if status == 4 then
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "The temperature on the sensor #1 above normal"
if status == 9 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Unidentified error. Check the #1 temperature sensor manually"

check program Humudity_1 with path "/root/monit/conf/scripts/get_relhumtemp1w.sh 1"
if status == 1 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Data from the humidity sensor #1 is not received. SNMP failure"
if status == 2 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Humidity sensor #1 is not connected or not working"
if status == 3 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Humidity on the sensor #1 below normal"
if status == 4 then
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Humidity on the sensor #1 above normal"
if status == 9 then 
exec /home/user/monit/conf/script/sendsms.sh +70000000000 "Unidentified error. Check the #1 humidity sensor manually"

A prepared file with monitoring configurations for the Monit system can be downloaded here.

As a result of all the configurations described above, the Monit monitoring system will send SMS notifications as follows:

Example of SMS notifications from the Monit monitoring system and NetPing SMS gateway

Thus, we implemented the sending of random SMS notifications from the Monit monitoring system using hardware GSM gateway for sending and receiving SMS notifications NetPing SMS.


comments powered by Disqus