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:
- Using the features of NetPing SMS GSM gateway only (up to 32 ports).
- 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:
- A configured NetPing SMS modem.
- 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.
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:
- Go to the section «Setup» of a web interface.
- Implement a basic network configuration.
- Implement a basic configuration of access parameters (login and password to a web interface, community read-write, IP access filter) if necessary.
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:
- Go to the section «Agents» of a web interface.
- Click in the field for adding a new agent.
- Fill in parameters for connecting to an agent.
- Save changes.
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:
- Go to the section «Variables» of a web interface;
- Click in the field for adding a new element;
- Configure parameters of an SNMP variable;
- Save changes.
Then, similarly add 4 more variables for other ports correspondingly, changing a name according to the format «if1_cN» and «.1.2.3.1.2.1.2.2.1.8.N», N=1..5.
In this case, «.1.2.3.1.2.1.2.2.1.8.N» 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:
- 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;
- NetPing SMS gateway processes a received SMS notification by comparing it with set variables specified in its configuration.
- 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 «.1.2.3.1.2.1.2.2.1.8.1», with the aim to read information about the first port of a managed switch;
- NetPing SMS gateway hardware receives a response from the agent («1» or «2») and decodes it using a dictionary described in a variable;
- 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:
where:
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.
Technical Implementation № 2 (unlimited number of ports)
To implement this solution, we will need:
- 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 - installation, SNMP TRAP);
- NetPing SMS gateway;
- 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:
- A system administrator sends an SMS command to a NetPing SMS gateway;
- NetPing SMS receives an SMS command, processes it and sends SNMP TRAP to Zabbix that monitors switches in the network;
- Zabbix sends a response back to NetPing SMS;
- 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):
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):
Then, we will find the template created by us in «Configuration» (1), subsection «Templates» (2) and enter its settings (3).
Go to the section «Items» (1) and click «Create Item» (2).
Fill in the fields of a data element:
- Name - SNMP trap fallback
- Type - SNMP trap.
- Key - snmptrap.fallback.
- Type of information - Log.
- Log time format - hh:mm:ss yyyy/MM/dd.
- Add.
Then, go to triggers of a template (1), and create a new one (2).
Fill in the fields of a trigger:
- Name - Unmatched SNMP trap received {HOST.NAME};
- Severity - Information;
- 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.
- Click the button Add.
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.
- Template name - Template SNMP traps.
- Groups - Templates.
- Go to Linked templates.
Open a window for choosing templates (1), select a necessary template («Template SNMP trap fallback») in it, and add/save (2).
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».
Fill in the fields in a next way:
- Name - get c1 if1;
- Type - SNMP trap;
- 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;
- Type of information - Log;
- Click Add.
The same as «get c1 if1», create a data element for «get c1 if2», and, the same 5:
Then, the same as for «Template SNMP trap fallback», proceed to add triggers:
- Name - c1 if1.
- Severity - Information.
- 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.
- Click Add.
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):
Fill in the fields in a next way:
- Host name - MikroTik.
- New group - Template MikroTik.
- SNMP interface - Add.
- SNMP interface ip address - 192.168.0.51 (IP address of the MikroTik interface, at which an SNMP agent is located).
- SNMP intefface port - 161 (port, at which an SNMP agent gives incoming connections).
- Add Add.
We can find the added host in the section «Configuration» (1), subsection «Hosts» (2). Open its settings (3):
Go to the section «Items» (1) and click «Create item»:
Fill in the data element properties in a next way:
- Name - if1_status (a readable port status description);
- Type - SNMPv1 agent (using SNMPv1 is caused by technical characteristics of NetPing SMS SNMP-to-SMS gateway);
- Key - ifStatus[1] - is a key using which we can request information from this data element;
- Host interface - 192.168.0.51:161 (i.e. we have not only one, and it will be chosen by default);
- SNMP OID - .1.3.6.1.2.1.2.2.1.8.1 (.1.3.6.1.2.1.2.2.1.8.X - 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);
- SNMP community - public (is indicated when configuring SNMP on the target switch);
- Port - 161;
- Type of information - Text (a type of received information);
- Go to the tab «Preprocessing».
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 «1» and «2» 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 «1» or «2» will be converted in readable «up» or «down».
Add/save changes (3):
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 (.1.3.6.1.2.1.2.2.1.8.N), N=1..5.
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:
- Host name - NetPing SMS.
- Groups - Trap servers.
- SNMP interface - 192.168.0.124.
- SNMP interface port - 161.
- Go to the tab «Templates».
Select a template «Template SNMP traps» (1) that was created earlier. Add/save changes (2).
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):
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):
- 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]);
- Send to Users Add;
- Select the user «Admin»;
- Send only to - NetPing SMS;
- Click Add.
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:
- Go to the section «Setup» of a web interface of NetPing SMS SNMP-to-SMS gateway.
- Fill in «SNMP trap destination 1», and specify an IP address of a Zabbix server.
- Save changes.
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).
Conclusion
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.