Sending Any SMS Notifications from Zabbix Using NetPing

  • Published In: Tutorial
  • Created Date: 2015-08-11
  • Hits: 2612

Zabbix is a free monitoring system for tracking statuses of various services of a computer network, servers and network equipment. This system has got a possibility to adjust different ways to notify a user: e-mail, SMS, Jabber, Ez Texting, user scripts. These ways to notify a user are delivery channels in use to send notifications and alerts from Zabbix. According to the fact that Zabbix supports user scripts, it is possible to use devices NetPing SMS, UniPing server solution v4/SMS or NetPing 8/PWR-220 v4/SMS as an SMS gateway to send SMS notifications about events in the monitoring system Zabbix as one of the notification methods. As a result, organising this method of SMS notifications can significantly save funds due to using alternate services for sending SMS notifications, available on the Internet.

Requirements

To implement a functionality described above, there is a need to have the following:

  • a gateway for sending and receiving SMS commands UniPing server solution v4/SMS with an inserted SIM card, or a device for remote controlling power supply sockets NetPing 8/PWR-220 v4/SMS with an installed SIM card;
  • a prepared script for sending random SMS notifications about the events in the monitoring system Zabbix;
  • a configured monitoring system Zabbix (in this example Zabbix is installed at the OS CentOS 6.5);
    To get an information about configuring a monitoring system Zabbix, kindly see the official documentation

To send SMS notifications as an example (i.e. using the devices NetPing SMS, UniPing server solution v4/SMS or NetPing 8/PWR-220 v4/SMS that are used as an SMS gateway), there is a need to perform only a part of a basic configuration (configure network parameters for accessing the network) of the devices NetPing SMS, UniPing server solution v4/SMS or NetPing 8/PWR-220 v4/SMS and install the working SIM card with a positive balance to a slot of a built-in GSM modem. It is possible to read about a basic and auxiliary configuration of devices in the next documentation:

Implementing Sending SMS Notifications from the Zabbix Monitoring System of the Version 2.2

Configuring Zabbix 2.2 Server

To have a possibility to use user scripts, there is a need to implement a light configuration of a Zabbix server. Doing a light configuration means to specify a parameter «AlertScriptsPath» in a configuration file «/etc/zabbix/zabbix_server.conf». This parameter determines a directory, where a script for SMS notifications will be saved.

To edit a configuration file, there is a need to go to a directory with a file and open it in a text editor: 

[ zabbix@zabbix ~]$ cd /etc/zabbix/

[ zabbix@zabbix zabbix]$ vi zabbix_server.conf

Add a directory for a parameter «AlertScriptsPath»:

Configuring the Zabbix configuration file to define a directory for user scripts

After a parameter is changed, save the settings in the configuration file and restart the service «services-zabbix» (a service is restarted by the user root):

[ zabbix@zabbix zabbix]# service service-zabbix restart

The script for sending SMS notification needs to be placed into the directory specified in the parameter «AlertScriptsPath», and permissions must be defined to perform the script (permissions are specified by the user root):

[ zabbix@zabbix zabbix]# chmod +x /usr/lib/zabbix/alertscripts/sendsms.sh

Ready script file can be downloaded from here: sendsms.sh

Parameters that are necessary to be changed when using a script in the own monitoring system Zabbix:

visor29 – is a user name for authorisation on a NetPing device.ping29 – is a password for authorisation on a NetPing device.
192.168.0.29 – is a current IP address of a NetPing device.

Configuring SMS Notifications in a Web Interface of Zabbix 2.2

Get authorized as an administrator into a web interface of the monitoring system Zabbix.

There is a need to create a new notification method to implement sending SMS notifications. To do that, go to the tab «Administration», select the menu item «Media types» and click the button «Create media type»:

Create a new notification method in Zabbix

In the window for setting a new notification method indicate parameters similar to represented ones at the screenshot below and save them by clicking the button «Save»:

Setting up a new notification method for sending SMS notifications from Zabbix using a script

where:

Name is a name for a notification method.

Type is a type of a notification method. The next types are available: «Email», «Script», «SMS», «Jabber», «Ez Texting». There is a need to choose a type «Script».

Script name is a name for a script file to send SMS notifications, which is located by the path: «/usr/lib/zabbix/alertscripts».

Enabled is a check-box for activating this notification method.

After creating a new notification method «Sendsms», it will appear in the table of all configured notifications in Zabbix:

A page with a list of configured Zabbix notification methods

Now a user or a group of users in Zabbix needs to link a created notification method. In the example below you will see a process of configuring for a user Admin. To do this, go to the tab «Administration», select a menu item «Users» and click a link  «Users» in a row of a group of Zabbix administrators in the table «User groups»:

Binding a new notification method to the Zabbix user

Choose a user Admin in a group «Zabbix administrators»:

Select a user to bind a new notification method to Zabbix

Go to the tab «Media» and click the button «Add» to link a new notification method:

Add an alert in the user's settings in Zabbix

In the window «New media» fill in parameters similar to the ones shown in the screenshot below and save them by clicking the button «Save»

Configuring the notification method for the user by sending SMS notifications using a custom script

where:
Type is a parameter for choosing notification methods, created before in the monitoring system Zabbix (a tab «Administration», a menu item «Media types»). As an example, select «Sendsms».
Send to is a phone number for sending SMS notifications.When active is time for triggering a notification method.Use if severity is an importance of a trigger. Checkboxes determine, for which importance of a trigger the notification will work. In the example, all checkboxes are checked for a better visualisation of the parameter.
Status is a parameter for enabling or disabling a notification.

In the window for setting parameters of a user Admin, a created notification for sending SMS notifications «Sendsms» will appear at the tab «Media». Afterwards, there is a need to click the button «Save» to save all settings:

Saving user settings in Zabbix

Now there is a need to configure an action, as a result of which, an SMS notification will be sent to an administrator of the monitoring system Zabbix. Let's suppose that an administrator needs to receive an SMS notification about an availability of the device for remote controlling a power supply NetPing 2/PWR-220 v4/SMS. I.e. when a device stops responding to ICMP requests, an SMS notification is sent about this device being unavailable. When a device starts responding to ICMP requests, an SMS notification is sent again indicating this device being available now.

To implement such algorithm of SMS notifications, there is a need to go to the tab «Configurations», select a menu item «Actions» and click the button «Create action» to create a necessary action, which will implement sending SMS notifications:

Creating an action in Zabbix

In the configuration window for actions, fill in parameters similar to the ones indicated at the screenshot below:

Setting up the action and text of the SMS notification in Zabbix

where:
Name is a unique name of the action.
Default subject is a default subject of a message. A subject can contain macros. It is not used in the SMS notification.
Default message is a default message. A message can contain macros.
Recovery message if a checkbox is checked, Zabbix will send a notification about recovery when the issue is solved. Notifications will be sent only to those ones, who received some messages about the issue before.
Recovery subject is a subject of a notification on default recovery. A subject can contain macros. It is not used in this SMS notification.
Recovery message is a message about recovery. A message can contain macros.
Enabled is a checkbox for enabling the action.

Therefore, this action will be sending SMS notifications with the text «{HOSTNAME}: ping is {STATUS}», when a device NetPing 2/PWR-220 v2/SMS is lost and then becomes available again.
where:
{HOSTNAME} is a unique name of a device in Zabbix.
{STATUS} is a current status of a device in Zabbix.

Now there is a need to specify a condition, within which an action will be triggered. Conditions are specified at the tab «Conditions». On default, a system already has two conditions: «А» and «В». For an example, let's add a condition «С», which determines a specific node in the network. If unavailable, SMS notifications will be sent. To do this, choose a parameter  «Host», condition «=» from a dropdown list in a row «New condition» and enter a unique name of a device «NetPing 2PWR-220v2SMS», added to Zabbix (a device NetPing 2/PWR-220 v2/SMS was previously added into Zabbix and configured to check availability via a network). Afterwards click the link «Аdd»:

Adding conditions for an action in Zabbix

As a result of the configuration, the third condition «С» will appear:

Configured conditions in the action settings window for SMS notifications in Zabbix

The last step of the configuration is to choose a notification method for this action. A notification method is configured at the tab «Operations» when clicking the link «New»:

Adding an alert method in the Zabbix action settings

In the window, represented at the screenshot below, choose a notification method «Sendsms» from a dropdown menu «Send only to». Afterwards click the button «Save» to save configuration:

Selecting the method of notification in the settings of the action in Zabbix

At the tab «Operations» the operation «Send message to users: Admin (Zabbix Administrator) via Sendsms» will appear, which initiates starting a script for sending SMS notifications for a configured action. It is necessary to save all settings for the action «Ping_status» by clicking the button «Save»:

Selecting the notification type in the Zabbix action settings

Eventually, a created action «Ping_status» will appear at the page «Actions» with a status «Enabled», which will initiate sending SMS notifications when necessary conditions are fulfilled:

New action in Zabbix for sending SMS notifications via NetPing devices

Implementing Sending SMS Notifications from the Zabbix Monitoring System of the Version 3.4

In August 2017, a new version of Zabbix, 3.4, was issued. The new version is somewhat different from Zabbix of the version 2.2. Let's examine a configuration of sending SMS notifications from new version of Zabbix. In our example, we use Zabbix of the version 3.4.8 that is installed on CentOS Linux release 7.4.1708 (Core).

Configuring a Zabbix 3.4 Server

The first step of a configuration is preparing a Zabbix server. There is a need to locate script for sending SMS notifications on a server. The script can be downloaded here and located in the directory /usr/lib/zabbix/alertscripts/ or created manually. Let's create a script file using the next command:

mcedit /usr/lib/zabbix/alertscripts/sendsms.sh

Creating a script file

And write the text of a script for sending SMS on a script language Bash: 

#!/bin/bash

curl --user visor:ping --data "[$1] $3" http://192.168.1.204/sendsms.cgi?utf8

Example of a script for sending SMS notifications from Zabbix 3.4

where: 
visor – is a username for authorization on a NetPing device. 
ping – is a password for authorization on a NetPing device. 
192.168.1.204 – is a current IP address of a NetPing device. 
[$1] – is a variable to which a destination phone number for a notification is sent. Square brackets are a must! 
$3 – is a variable to which a text of an SMS notification is sent.

Save and make a file executable using the next command:

chmod a+x /usr/lib/zabbix/alertscripts/sendsms.sh

Changing rights for a script file

Now, edit a configuration file of a Zabbix server:

mcedit /etc/zabbix/zabbix_server.conf

Opening a configuration file Zabbix 3.4

In a configuration file of a Zabbix server, the next parameter must be uncommented/specified:

AlertScriptsPath=/usr/lib/zabbix/alertscripts

Zabbix 3.4 configuration file

After changing a configuration of a Zabbix server, it must be restarted to apply these changes. To do this, execute the next command:

systemctl restart zabbix-server

A command to restart a Zabbix 3.4 server

Configuring SMS Notifications in a Web Interface of Zabbix 3.4

Then, let's go to a web interface of a Zabbix server and continue configuring. In a web interface of Zabbix, let's create a new notification type (Administration → Media Types) with the next parameters:

Creating a new notification type in Zabbix 3.4

where:
Name – is a name of a notification type. In our example, the name is «NetPing SMS»;Type – is a notification type. The next types are available: «Email», «Script», «SMS», «Jabber», «Ez Texting». It is necessary to choose a type «Script»;
Script name – is a name of a script file for sending SMS notifications that is located on the next path: «/usr/lib/zabbix/alertscripts». In our example, it is «sendsms.sh»;
Script parameters – is script parameters, i.e. specify parameters the same as in the example. A parameter {ALERT.SENDTO} is sent to a variable $1 of the script sendsms.sh. A parameter {ALERT.MESSAGE} is sent to a variable $3 of the script sendsms.sh;
Enabled – is a checkbox for activating this notification type.

Then, continue to the settings of a user Admin (Administration → Users) and add a new notification type on the tab «Media». Click the link «Add», and in a pop-up window «Media» that appears, specify the parameters as in the example below:

Adding a new notification type for a Zabbix 3.4 user

Parameters of a new notification type for a user in Zabbix 3.4

where:
Type – is a parameter for choosing a notification type, created before in a Zabbix monitoring system (Administration → Media Types). In our case, we select a notification type from the list - a notification type «NetPing SMS»;.
Send to – is a destination number to which SMS notifications will be sent. A destination number is specified in the international format, starting from «+7»;When active – is a time of triggering of this notification. A configuration can be left default;Use if severity – is an significance of a trigger, checkboxes determine at which significance of a trigger this notification will operate. In the example, all checkboxes are checked for increasing a visuality of the parameter.
Enabled – is a parameter for enabling and disabling this notification.

Save the changes by clicking the buttons «Add» and «Update».

Then we go to creating the action which execution triggers sending our SMS notifications. In the article we will examine sending SMS notifications when changing a logic level of an IO line at NetPing devices, connected to the monitoring. It is possible to plug any sensors of a dry contact type to IO lines of NetPing devices in the «input» mode:  

Go to the section «Configuration → Action» and click the button «Create Action»:

Creating the action in Zabbix 3.4

In a window that opens, on the «Action» tab, fill in the fields as in our example. Here, we need to sort out triggers that will cause sending SMS notifications when operating. 

Adding rules at which the action operates in Zabbix 3.4

where:
Name – is a unique name of the action. In out example it is «IO_line_status»;
Type of calculation – is a type of a logic rule for triggers. In our example, «Or» (logic OR), the action is executed when one of triggers operated;Conditions – are conditions, within which the action will be triggered. Names of triggers that will cause sending SMS notification when operating must contain phrases «Level:FRONT» and «Level:DECAY»;
New condition – is a field for creating a new action. Adding rules is confirmed by clicking the link «Add» in the field «New condition»;
Enabled – is a parameter for switching on and switching off the action.

Then, go to the tab «Operations» and specify the text of an SMS notification that will be sent when a trigger that is described at the tab «Action» operates.

SMS text when a trigger operates in Zabbix 3.4

where:
Default operation step duration – is a duration of a one step of the operation. For example, a step duration of one hour means that if the first operation in this action is executed, then the next operation will be started in an hour. In our example, the operation of sending a notification is the only one, therefore it is possible to leave a default value. 
Default subject – is a default subject. A subject cannot contain macros. In this SMS notification it is not used.
Default message – is a default message. A message can contain macros. In this field, we write a text of an SMS notification that will be received by the administrator of a monitoring system when a logic level is changed on the IO lines of a NetPing device.

In the field «Operations», we click the link «New», and fill in an opened form of an action description as in our example. Add a user «Admin» in the field «Sent to Users». In the field «Send only to», choose a notification type «NetPing SMS» from the list. Confirm the changes by clicking the link «Add» (1):

Filling in the field in Operations in Zabbix 3.4

Confirm creating a new action by clicking the button «Add» (2).

Now, when a logic level of an IO line of a NetPing device that is connected to the monitoring system is changed, Zabbix, network administrator, will receive such SMS notifications: 

Example of SMS notifications from Zabbix 3.4

On the screenshot below, you can see a common view of a Dashboard with executed triggers for changing a logic level of IO lines. In the table «Actions», we may see it because the action is connected to trigger, and the action was successfully executed.

Common view of Dashboard Zabbix 3.4

In this article, the simplest examples of configuring notifications are shown. Zabbix monitoring helps to configure complex solutions with complicated conditions of triggering actions. More detailed information about this can be read in the official Zabbix documentation.


Tags: All devices
comments powered by Disqus