Example of Receiving a Port Status of a Switch in a Network through an SMS Notification via NetPing SMS

  • Published In: Tutorial
  • Created Date: 2018-06-25
  • Hits: 5182

By following this article, you will get a tool for monitoring managed switches through SMS notifications. A described solution will be useful for network administrators, technical support staff and other employees, whose responsibilities include monitoring and servicing of networks of all levels. Now, technical staff will get the opportunity to receive information about a port status of a managed switch  (up/down) rapidly without accessing the network with target switches.

The solution will be represented in two variants:

  1. Using the features of NetPing SMS GSM gateway only (up to 32 ports).
  2. Using the features of NetPing SMS GSM gateway and a Zabbix server (unlimited number of ports).

Technical Implementation № 1 (up to 32 ports)

This limit is caused by limiting the number of variables in the NetPing SMS gateway: one variable corresponds to one SNMP OID, which, in turn, corresponds to requesting information from one port of a managed switch according to an SNMP protocol.

To implement this solution, you will need:

  1. A configured NetPing SMS modem.
  2. A managed switch.

A router MikroTik 951Ui 2HnD will be used as a managed switch. Considering communication via an SNMP protocol and receiving a port status, there is no significant difference, only SNMP OID will be different.

Mikrotik as a controlled switch

A basic configuration of a NetPing SMS gateway

First, there is a need to perform a basic configuration of NetPing SMS, for doing which, there is a need to:

  1. Go to the section «Setup» of a web interface.
  2. Implement a basic network configuration.
  3. Implement a basic configuration of access parameters (login and password to a web interface, community read-write, IP access filter) if necessary.

NetPing SMS basic settings

Adding an SNMP agent to a gateway configuration of a NetPing SMS gateway

Then, there is a need to add an SNMP agent (our managed switch). To do this, there is a need to:

  1. Go to the section «Agents» of a web interface.
  2. Click in the field for adding a new agent.
  3. Fill in parameters for connecting to an agent.
  4. Save changes.

NetPing SMS agents

Adding SNMP variables to a GSM gateway configuration of NetPing SMS

Then, there is a need to set variables, these are SNMP OIDs, using which we will request information about a status of ports:

  1. Go to the section «Variables» of a web interface;
  2. Click in the field for adding a new element;
  3. Configure parameters of an SNMP variable;
  4. Save changes.

NetPing SMS SNMP variables

Then, similarly add 4 more variables for other ports correspondingly, changing a name according to the format «if1_cN» and «.», N=1..5.

In this case, «.» is an  SNMP OID variable of a port status for MikroTik switches and routers. Returned values may be «1» (corresponds to a port status «up») or «2» («down»).

A scheme works according to the next algorithm:

  1. An administrator sends an SMS notification in the format «np snmp c1_if1? public», where np snmp is a prefix of a command, c1_if1 is a variable (c1 is a symbol of the first switch, if1 is a symbol of the first port), «public» - is a value of SNMP Read Community that is specified in the settings of a switch;
  2. NetPing SMS gateway processes a received SMS notification by comparing it with set variables specified in its configuration.
  3. After finding a requested variable, NetPing SMS GSM modem connects to the agent to which it is linked to. I.e. it sends an SNMP GET command with a specified SNMP OID, in our example «.», with the aim to read information about the first port of a managed switch;
  4. NetPing SMS gateway hardware receives a response from the agent («1» or «2») and decodes it using a dictionary described in a variable;
  5. Then, NetPing SMS gateway device sends a decoded SMS response to an administrator using the format «NP SNMP REPLY c1_if1=Up(1)».

A format of an SMS notification for requesting a port status

A value of an SNMP variable is requested using the next template:

np snmp variable? password


np snms is a prefix of a command

variable is a name of a variable that is specified on the page «Variables» of a web interface of a NetPing SMS modem with Ethernet.

password is a value of a parameter «Community» specified in the settings of an agent on the page «Agents» of a web interface of a NetPing SMS GSM module.

An example of requesting the information about a status of the second and the fourth ports of a managed switch is shown in the screenshot below. In a similar way, it is possible to receive any information that a switch can provide via an SNMP protocol, from loading a port to loading a central processor of a switch.

Example of receiving a port status of a switch in a network through SMS notification via NetPing SMS

Technical Implementation № 2 (unlimited number of ports)

To implement this solution, we will need:

  1. A server with a Zabbix monitoring system (also a similar solution can be built on the basis of any other monitoring system, such as Nagios, OpenNMS, PRTG Network Monitor, etc.) with configured receiving of SNMP TRAP notifications and a script for sending SMS notifications through NetPing SMS (official documentation - installationSNMP TRAP);
  2. NetPing SMS gateway;
  3. Managed switches configured in Zabbix for monitoring them.

As a managed switch, let's take MikroTik 951Ui 2HnD from the first variant. A short scheme of component interactions will be the next:

  1. A system administrator sends an SMS command to a NetPing SMS gateway;
  2. NetPing SMS receives an SMS command, processes it and sends SNMP TRAP to Zabbix that monitors switches in the network;
  3. Zabbix sends a response back to NetPing SMS;
  4. NetPing SMS receives a response and redirects it to a system administrator as an SMS notification.

Configuring Zabbix

First, there is a need to configure a reaction of Zabbix to receiving SNMP TRAP notifications. The way how to implement this is described below.

Template for processing unknown SNMP TRAP notifications

Let's create a template for processing unknown SNMP TRAP notifications. To do this, go to the section «Configuration» (1), subsection «Templates» (2) and click «Create template» (3):

Zabbix template creation

Set a name for a template «Template SNMP trap fallback» (1) and add it to the existing group or create new «Templates» (2) and save changes (3):

Zabbix template settings

Then, we will find the template created by us in «Configuration» (1), subsection «Templates» (2) and enter its settings (3).

Zabbix template

Go to the section «Items» (1) and click «Create Item» (2).

Zabbix Item template

Fill in the fields of a data element:

  1. Name - SNMP trap fallback
  2. Type - SNMP trap.
  3. Key - snmptrap.fallback.
  4. Type of information - Log.
  5. Log time format - hh:mm:ss yyyy/MM/dd.
  6. Add.

Zabbix Item SNMP fallback

Then, go to triggers of a template (1), and create a new one (2).

Zabbix trigger creation

Fill in the fields of a trigger:

  1. Name - Unmatched SNMP trap received {HOST.NAME};
  2. Severity - Information;
  3. Expression - {Template SNMP trap fallback:snmptrap.fallback.nodata(60)}=0, where «Template SNMP trap fallback:snmptrap.fallback» processes unknown SNMP Trap notifications, «nodata(60)» - is a function of testing the absence of received data during the last 60 seconds (returns 1 in case if there is no data, returns 0 otherwise), «{...}=0» - is testing of receiving data.
  4. Click the button Add.

Creating a trigger in Zabbix

Template for processing unknown SNMP TRAP notifications with a request for a port status

The same as in the section «Template for processing unknown SNMP TRAP notifications», go to creating a new template.

  1. Template name - Template SNMP traps.
  2. Groups - Templates.
  3. Go to Linked templates.

Zabbix related templates

Open a window for choosing templates (1), select a necessary template («Template SNMP trap fallback») in it, and add/save (2).

Zabbix adding a linked template

The same, in «Template SNMP trap fallback», proceed with adding elements to the data of a template. In the list, we see one already existing data element, it is inherited from a template «Template SNMP trap fallback». Click «Create item».

Zabbix data item creation

Fill in the fields in a next way:

  1. Name - get c1 if1;
  2. Type - SNMP trap;
  3. Key - snmptrap["get c1 if1"]. This parameter will process SNMP TRAP notification «get c1 if1» (this SNMP TRAP notification is formed by NetPing SMS IP GSM gateway when receiving an SMS notification «get c1 if1»), i.e. a status request of the first port of the first switch;
  4. Type of information - Log;
  5. Click Add.

Zabbix data item settings

The same as «get c1 if1», create a data element for «get c1 if2», and, the same 5:

Zabbix data item settings

Then, the same as for «Template SNMP trap fallback», proceed to add triggers:

  1. Name - c1 if1.
  2. Severity - Information.
  3. Expression - {Template SNMP traps:snmptrap["get c1 if1"].nodata(60)}=0, where «Template SNMP traps:snmptrap["get c1 if1"]» - is testing of a received notification for corresponding to a regular expression «get c1 if1», «nodata(60)» - is a function of testing the absense of received data for the last 60 seconds (returns 1 if there are no data, 0 otherwise), «{...}=0» - testing the receiving of data.
  4. Click Add.

Zabbix trigger settings

In a similar way, create the second trigger, with changes in the name «c1 if2» and the expression «{Template SNMP traps:snmptrap["get c1 if2"].nodata(60)}=0», and the same 5.

Adding a host (managed switch)

Now, we have to configure monitoring of a managed switch that is interesting to us. Go to the section «Configuration» (1), subsection «Hosts» (2), and click «Create host» (3):

Zabbix adding a new host

Fill in the fields in a next way:

  1. Host name - MikroTik.
  2. New group - Template MikroTik.
  3. SNMP interface - Add.
  4. SNMP interface ip address - (IP address of the MikroTik interface, at which an SNMP agent is located).
  5. SNMP intefface port - 161 (port, at which an SNMP agent gives incoming connections).
  6. Add Add.

Zabbix host settings

We can find the added host in the section «Configuration» (1), subsection «Hosts» (2). Open its settings (3):

Zabbix host list

Go to the section «Items» (1) and click «Create item»:

Zabbix create a data item for the host

Fill in the data element properties in a next way:

  1. Name - if1_status (a readable port status description);
  2. Type - SNMPv1 agent (using SNMPv1 is caused by technical characteristics of NetPing SMS SNMP-to-SMS gateway);
  3. Key - ifStatus[1] - is a key using which we can request information from this data element;
  4. Host interface - (i.e. we have not only one, and it will be chosen by default);
  5. SNMP OID - . (. - OID statuses of a port for MikroTik switches, where X - is a port number, returned values are «1» (Up), «2» (Down). A full list of OIDs supported by a device can be taken from the official website of a manufacturer);
  6. SNMP community - public (is indicated when configuring SNMP on the target switch);
  7. Port - 161;
  8. Type of information - Text (a type of received information);
  9. Go to the tab «Preprocessing».

Zabbix data item settings for the host

Add two fields for regular expressions (1), and fill in these fields in a next way (2):

Regular expression(.*)\1:1=up:2=down
Regular expression(1|2)(?=:.*\1=(up|down))\2

Using these regular expressions, we will turn received statuses of a switch port « and « into readable «up» and «down». In this example, the logic is as follows: 

  • During the first iteration, «1=up:2=down» will be added to the line, which will help us to decode a value on the next iteration;
  • During the second iteration, a status value of a port « or « will be converted in readable «up» or «down».

Add/save changes (3):

Zabbix regular expressions

In the same way, add data elements for other ports (their number depends on a model of a switch, in this example there are 5 of them). For every consequent data element, only Name (ifN_status) is changed, Key (ifStatus[N]), OID (., N=1..5.

Zabbix list of host data items

Adding NetPing SMS modem to Zabbix as an SNMP TRAP server

Now, we have to add NetPing SMS modem as an SNMP TRAP server, from which Zabbix will accept SNMP TRAP notifications. Go to the section «Configuration», subsection «Hosts», click «Create host» and fill in the fiends in a next way:

  1. Host name - NetPing SMS.
  2. Groups - Trap servers.
  3. SNMP interface -
  4. SNMP interface port - 161.
  5. Go to the tab «Templates».

Zabbix adding NetPing SMS as SNMP TRAP server

Select a template «Template SNMP traps» (1) that was created earlier. Add/save changes (2).

Zabbix template selection for NetPing SMS SNMP TRAP server

Actions of a Zabbix server after receiving SNMP TRAP notifications requesting a port status

Now, we have to configure a reaction of a Zabbix server to SNMP TRAP notifications received from NetPing SMS SNMP-to-SMS gateway. To do this, go to «Configuration» (1), «Action» (3), and click «Create action» (3):

Zabbix add action

Set a name of the action (1), fill in conditions for triggering (2) (in this example, the action will be performed when a trigger «c1 if1» worked, that, in turn, works when receiving an SNMP TRAP notification from NetPing SMS), add them (3), and go to the section «Operations» (4):

Zabbix Configuring the Action to accept the trap message

  1. Default message - «if status - {Test_MikroTik:ifStatus[1].last()}» (using a macros, we get the last received value of a data element with a key ifStatus[1]);
  2. Send to Users Add;
  3. Select the user «Admin»;
  4. Send only to - NetPing SMS;
  5. Click Add.

Zabbix Configuring the Action to accept the trap message

Then, repeating the same actions for each of five ports, we will create the actions that will be performed by a Zabbix server when receiving an SNMP TRAP notification from NetPing SMS with a request on the information about a port status: get c1 ifN status, {Test_MikroTik:ifStatus[N].last()}. N=1..5.

Configuring NetPing SMS SNMP-to-SMS gateway for sending SNMP TRAP notifications to a Zabbix server

To do this:

  1. Go to the section «Setup» of a web interface of NetPing SMS SNMP-to-SMS gateway.
  2. Fill in «SNMP trap destination 1», and specify an IP address of a Zabbix server.
  3. Save changes.

NetPing SMS basic settings

Now, when sending an SMS in the format «get cN ifM» to a gateway NetPing SMS, we will receive a readable port status «M», a switch «N» (up/down).

Example of receiving a port status of a switch in a network through SMS notification via NetPing SMS


The solution appeared to be compact but easily scaled. In the second variant, it is possible to receive any information that is gathered by a Zabbix server, In turn, this allows to coordinate actions of a system administrator on the go in case of emergency even without accessing the network with switches.

Tags: NetPing SMS
comments powered by Disqus