Tutorial
7/4/2016

How to Monitor Zabbix via SMS Using NetPing SMS

How to monitor Zabbix via SMS using NetPing SMS

A difficult job of a network administrator is based on watching the status of a network equipment and servers. This task is complicated when there is no access to the Internet network at fingertips either a necessary equipment. The article describes how to solve this issue with a monitoring system Zabbix by using a phone with a possibility to send/receive SMS-messages and a NetPing SMS device.

Zabbix is a universal and flexible OpenSource solution for monitoring a network equipment (NMS) of a corporate scale. The system has a possibility to notify about events in different ways: E-mail, SMS, Jabber, user scripts. In the article, a method of using user scripts and a NetPing SMS device as an SMS gateway for sending SMS responses about a status of requested sensors in Zabbix monitoring system will be described. To receive SMS requests, a NetPing SMS device will be used as well. The device can transmit SMS requests in Zabbix in the form of SNMP traps. As a result, when organizing this method, a system administrator will always have an actual information about a status of the network equipment at any moment of time.

Requirements

To implement a represented solution, the next equipment will be necessary:

  • a gateway NetPing SMS with an installed SIM card to send and receive SMS commands;
  • a configured monitoring system Zabbix

 Zabbix monitoring system can be deployed on a virtual machine or a dedicated physical server, connected to a local network or the Internet network. If Zabbix works on a remote equipment in the Internet network, and a router with the NAT and/or Firewall function is used, then there is a need to allow incoming packages via UDP protocol (port 162) to Zabbix to have a possibility to receive SNMP TRAP from outside.There is a need to address a documentation for a router or ask a network administrator for the additional information. In this article a simplified scheme is examined, when a NetPing SMS device and a server with a Zabbix monitoring system are located in the same local network.

If necessary, NetPing SMS gateway can be connected to the network via wireless technology Wi-Fi through an adapter WiFi VAP11N. The adapter is purchased separately. See a user guide for additional information.

General Settings

The software of Zabbix monitoring system can be installed both in different systems of a virtual environment or as ready installation packages for various operating systems. Source codes of a system and official documentation on its installing and configuring are available as well. More detailed information can be learned on the links (1 and 2).

To make it simple, a ready official virtual machine image on the basis of openSUSE 12.3 (x86_64) with a preinstalled Zabbix 2.2.2 system will be used.

On default, to access a console and via ssh login is: root, password is: zabbix

Firewall configuration

At first, to have a possibility to receive SNMP TRAP notifications, there is a need to configure a network filter of packages built-in the openSUSE, which is well-known as a firewall. There is a need to edit the next line in the file /etc/sysconfig/SuSEfirewall2 with the aim to add 162 UDP-port:

FW_SERVICES_EXT_UDP="162"

Then, run a command:

# /sbin/SuSEfirewall2

See a documentation for additional information on configuring a firewall .

Net-SNMP Package

Then there is a need to continue to configuring a system on receiving and processing incoming SNMP TRAP notifications. To receive and transfer them into Zabbix, a preinstalled package of utilities Net-SNMP is already used as well as a Perl script zabbix_trap_receiver.pl.

If there is no package of utilities Net-SNMP, there is a need to install it. See a corresponding documentation for the used operating system for the information on installing additional software. The next packages will be required:

  • «net-snmp-utils»;
  • «net-snmp-perl»

Script zabbix_trap_receiver.pl

Perl script zabbix_trap_receiver.pl to transfer traps to Zabbix is available on the link given in this article or in the Zabbix source code. To do this, there is a need to download and extract an archive:

# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz/download

# tar -zxvf zabbix-2.2.2.tar.gz

Copy a script and provide rights to it for being executed:

# cp ./zabbix-2.2.1/misc/snmptrap/zabbix_trap_receiver.pl /usr/local/bin

# chmod a+x /usr/local/bin/zabbix_trap_receiver.pl

Script sendsms.sh

To use an external script for sending SMS messages in a configuration file of a Zabbix server /etc/zabbix_server.conf there is a need to indicate:

AlertScriptsPath = /usr/local/lib/zabbix/alertscripts

Put a script sendsms.sh in a specified directory and provide rights for execution tp it:

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

Daemon snmptrapd and Zabbix trapper

To receive incoming SNMP TRAP notifications, a daemon snmptrapd will be used from the set of utilities Net-SNMP. Its configuration file /etc/snmp/snmptrapd.conf must have the next appearance:

disableAuthorization yes

perl do "/usr/local/bin/zabbix_trap_receiver.pl"; 

Then run a daemon snmptrapd and add it to an autoload:

# systemctl restart snmptrapd

# chkconfig snmptrapd on

Then in a configuration file /etc/zabbix_server.conf of a Zabbix server there is a need to enable the option on processing traps:

StartSNMPTrapper=1

SNMPTrapperFile=/tmp/zabbix_traps.tmp

Restart Zabbix:

# systemctl restart zabbix_server

Therefore, when receiving an SNMP TRAP message, a daemon snmptrapd will send it to the script  zabbix_trap_receiver.pl for processing, and a script will record data into the file /tmp/zabbix_traps.tmp. Daemon Zabbix constantly checks this file for changes. If there are any, it sends data for processing.

Rotation zabbix_traps.tmp

If necessary, a rotation of the file /tmp/zabbix_traps.tmp can be configured to avoid overfilling /tmp. To do this, there is a need to create a directory:

# mkdir -p /var/log/zabbix_traps_archive

Add a file /etc/logrotate.d/zabbix_traps with the next content: 

/tmp/zabbix_traps.tmp {

    weekly

    size 10M

    compress

    compresscmd /usr/bin/bzip2

    compressoptions -9

    notifempty

    dateext

    dateformat -%Y%m%d

    missingok

    maxage 365

    rotate 10

}

Archive copies of the file /tmp/zabbix_traps.tmp will be moved into the directory /var/log/zabbix_traps_archive when reaching the size of 10 Mb. 

Configuring Zabbix Server

In the case of the example, authorizing as an administrator in a web interface of the monitoring system Zabbix is performed via the address: http://192.168.0.124/zabbix

A default username is: Admin, a default password is: zabbix

Incoming SNMP TRAP messages will be processed according to the content. To do this, there is a need to create templates (Templates): one template for processing faulty (error) SMS-requests and the second one for processing existing SMS commands.

In the article, handlers for two SMS-commands will be created, for the example:

  • ZABBIX show CPU status
  • ZABBIX show memory status

1. Template SNMP trap fallback

Go to the section «Configuration» (1), subsection «Templates» (2) and click «Create template» (3):

Creating a template in Zabbix

Specify a template name (1) and add it to the existing group or create a new group (2):

Configuring a template in Zabbix

  1. «Template SNMP trap fallback»
  2. «Templates»

Save settings. Afterward, the next record will appear in this section:

List of templates in Zabbix

Go to adding objects in the section «Items»:

Items in Zabbix

To create a new object, click the button «Create item»:

Creating a new object in Zabbix

And fill in corresponding fields the next way:

Filling in parameters for a new object in Zabbix

  1. «SNMP trap fallback»
  2. Select «SNMP trap»
  3. «snmptrap.fallback»
  4. Select «Log»

After saving the settings, a new object «SNMP trap fallback» will appear. Go back to the section «Template list»:

List of objects in Zabbix

Move to adding an object in the section «Triggers»:

Trigger List of Zabbix

To create a new object, click the button «Create trigger»:

Creating a new trigger in Zabbix

Fill in the fields the next way and save the settings:

Configuring a trigger in Zabbix

  1. «Umatched SNMP trap received {HOST.NAME}»
  2. «{Template SNMP trap fallback: snmptrap.fallback.nodata(60)}=0»

Hereinafter Zabbix macroses are used in braces {…}.

After saving the settings, a new object will appear in the section. Go back to the section «Template list»:

browsing a trigger in Zabbix

2. Template SNMP traps

The same as in the section «1. Template SNMP trap fallback», move to creating a new template:

Creating a new template in Zabbix

  1. «Template SNMP traps»
  2. Select «Templates» from the list on the right
  3. Go to the tab «Linked template»

Link a recorded template with the one created before:

Linking templates in Zabbix

In the field (1) there is a need to select the name of a template that has been created before «Template SNMP trap fallback» and click «Add» (2). Save settings.

The same for the section «1. Template SNMP trap fallback», move to creating two new objects «Item». The first object will process an SMS request «ZABBIX show CPU status»:

Creating an object in Zabbix

  1. «ZABBIX show CPU status»
  2. Select «SNMP trap»
  3. «snmptrap["ZABBIX show CPU status"]»
  4. Select «Log»

Save settings.

The second object will be processing an SMS-request «ZABBIX show memory status»:

Creating an object in Zabbix

  1. «ZABBIX show memory status»
  2. Select «SNMP trap»
  3. «snmptrap["ZABBIX show memory status"]»
  4. Select «Log»

Save settings.

The same for the section «1. Template SNMP trap fallback»: there is a need to go to creating new two objects «Triggers». One of them will work for «ZABBIX show CPU status»:

Creating a trigger in Zabbix

  1. «ZABBIX show CPU status from {HOST.NAME}»
  2. «{Template SNMP traps:snmptrap["ZABBIX show CPU status"].nodata(60)}=0»

The second one will work for «ZABBIX show memory status»:

Creating a trigger in Zabbix

  1. «ZABBIX show CPU status from {HOST.NAME}»
  2. «{Template SNMP traps:snmptrap["ZABBIX show memory status"].nodata(60)}=0»

As a result, the section «Items» for this template will have the next look:

Items in Zabbix

The section «Triggers» for this template will have the next look:

Browsing triggers in Zabbix

If you go to the section with all templates (Templates), then created objects must have the next lookBrowsing templates in Zabbix

3. Adding a host

To add a NetPing SMS device, from which SNMP TRAP messages will be received, there is a need to go to the section «Configuration» (1), subsection «Hosts» (2) and click the button «Create host»:

Adding a node to Zabbix

Indicate a hostname (1), a group (2) and an IP address (3):

Configuring a new node in Zabbix

  1. «NetPingSMS»
  2. «Trap servers»
  3. «192.168.0.123»

Then, go to the tab «Templates». In the field (1) select a name of a template «Template SNMP traps» that has been created before and click the button «Add» (2). Save the settings: 

Linking a template to a node in Zabbix

4. Adding a new method of notifying via SMS

To add a new method of notifying via SMS via a NetPing SMS device by the script sendsms.sh, there is a need to go to the section «Administaration», subsection «Media types» and click the button «Create media type»:

Creating a new method of notification in Zabbix

Fill in the fields the next way:

Configuring a method of notification in Zabbix

  1. «SendSMS»
  2. «Select «Script»
  3. «sendsms.sh»

Save settings.

5. Enabling a new method of notifying a Zabbix user

Enable a new notification method for one of Zabbix users, for example, a user Admin. To do this, go to the section «Administration» (1), subsection «Users» (2) and click «Admin (Zabbix Administrator)» (3):

Linking a method of users' notification in Zabbix

Go to the tab «Media» (1), and click the button «Add» (2):

Connecting a method of users' notification in Zabbix

Fill in the fields in the window that appeared:

Configuring a notification method in Zabbix

  1. Select a notification type SendSMS created before
  2. Indicate a number of a cell phone for sending responses to requests in the international format: +[country code][phone number]
  3. Specify days and time of notification operation.
  4. Indicate for what types of events this notification must be used: indicate for all.

Click the button «Add» and save settings.

6. Configuring actions (Action)

6.1 Wrong SMS command

To configure sending SMS-responses to working triggers, there is a need to go to the section «Configuration» (1), subsection «Actions» (2) and click the button «Create action» (3):

Adding a new action to Zabbix

Create an action for faulty (error) SMS requests:

Configuring the action in Zabbix

  1. «Wrong SMS command»
  2. «Wrong SMS command»
  3. «You sent a wrong SMS command»
  4. Go to the tab «Conditions»

On the tab «Conditions» do the next settings:

Configuring conditions in Zabbix

Select «New condition» (2) and add through «Add» (3) two conditions (4) for checking events by filling in the field nearby. Go to the tab «Operations» (5) and click «New»:

Configuring operation in Zabbix

For the «Operation type» (1) choose «Send message». Through «Add» (2) in «Sent to Users» add the user Admin «(Zabbix Administrator)», and in «Send only to» (3) select «SendSMS». Then click the button «Add» (4) and save the settings.

Operation type in Zabbix

Therefore, this operation will send an SMS response «You sent a wrong SMS command» for any SMS request different from:

  • «ZABBIX show CPU status»
  • «ZABBIX show memory status»

6.2 ZABBIX show CPU status

The same for the operation «Wrong SMS command», there is a need to create the action «ZABBIX show CPU status» on the corresponding SMS command:

Creating an operation in Zabbix

  1. «ZABBIX show CPU status»
  2. «Response: {TRIGGER.NAME}»
  3. «CPU load: {Zabbix server:system.cpu.load[percpu.avg1].avg(1m)};{Zabbix server:system.cpu.load[percpu.avg1].avg(5m)};{Zabbix server:system.cpu.load[percpu.avg1].avg(1m)}»
  4. Go to the tab «Conditions»

On the tab «Conditions» make the next settings:

Creating a condition in Zabbix

Select «New condition» (2) and fill in the field next to it, add two conditions (4) to check the events through «Add» (3). Adjust a configuration of the tab «Operations» the same as the action «Wrong SMS command».

6.3 Zabbix show memory status

There is a need to create the action «ZABBIX show memory status» for the corresponding SMS command the same as the action «Wrong SMS command»:

Creating an operation in Zabbix

  1. «ZABBIX show memory status»
  2. «Response: {TRIGGER.NAME}»
  3. «CPU load: {Zabbix server:vm.memory.size[available].last(0)}»
  4. Go to the tab «Conditions»

On the tab «Conditions» make the next settings:

Creating a condition in Zabbix

Choose «New condition» (2) and fill in the field next to it, add two conditions (4) for checking the events through «Add» (3). A configuration of the tab «Operations» adjust the same as the action «Wrong SMS command».

Configuring NetPing SMS

Bring a NetPing SMS device into operating condition according to the corresponding sections of the user guide and firmware description:

  • install the SIM card of the cellphone operator;
  • configure necessary parameters for working with a data network;
  • indicate IP address of a Zabbix server for sending SNMP TRAP notifications on the page «SETUP» of a NetPing SMS web interface

Configuring NetPing SMS

Result

Therefore, if a scheme described above was configured correctly, SMS responses of the next appearance will be sent to the phone in case of sending SMS requests to the monitoring system Zabbix:

How to monitor sensors in Zabbix via SMS using NetPing SMS


  • NetPing SMS

Main tags


All devices
All NetPing power
NetPing SMS
NetPing mini-UPS
NetPing 2/PWR-220 v1/SMS
UniPing server solution v3/SMS
UniPing server solution v3
NetPing /PWR-220 v3/ETH
NetPing IO v2
NetPing 4/PWR-220 v3/SMS
UniPing v3
Uniping server solution
NetPing 8/PWR-220 v3/SMS
NetPing 2/PWR-220 v2/SMS
NetPing 2/PWR-220 v3/ETH
NP-SM4
Temperature sensor T811, 2m
Temperature 1-wire, (THS), 2m
▼ All tags
New devices
Temperature sensor T811, 2m
Temperature sensor for measuring an ambient air temperature indoors from -40°C to +125°C. Avoid water details...

Price: 19 usd

UniPing server solution v3
A device for a remote monitoring of sensors via the Ethernet/Internet network. It allows to receive details...

Price: 180 usd

Humidity sensor WS-2
A relative humidity sensor for measuring relative humidity in % and a built-in temperature sensor.Plastic details...

Price: 42 usd

-+ usd usd
Subtotal usd

Your Order