Difference between revisions of "Testing Trap With Linux Operating System"

From Teltonika Networks Wiki
 
(11 intermediate revisions by the same user not shown)
Line 15: Line 15:
 
  $ sudo apt-get install snmp-mibs-downloader
 
  $ sudo apt-get install snmp-mibs-downloader
  
'''Important note:''' before continuing make sure that SNMP Trap package is configured. SNMP configuration example can be found here [[SNMP configuration example]].
+
'''Important note:''' before continuing make sure that SNMP Trap package is configured. SNMP configuration example can be found [[SNMP configuration example | here]].
  
 
==Editing configuration files==
 
==Editing configuration files==
Line 21: Line 21:
 
===Snmpd.conf===
 
===Snmpd.conf===
  
This is not required for Trap listening service, but with this configuration '''snmpget''' command will be able to establish connection without requiring port number in the command line.
+
This is not required for Trap listening service, but with this configuration '''snmpget''' command will be able to establish connection without requiring port number in the command line. If you want to configure SNMP so it would listen to the port globally, not locally follow these steps:
  
 
Edit snmpd.conf file, it can be found in ''' ''/etc/snmp/'' '''directory. Example of the command:
 
Edit snmpd.conf file, it can be found in ''' ''/etc/snmp/'' '''directory. Example of the command:
Line 27: Line 27:
 
  $ sudo nano /etc/snmp/snmpd.conf
 
  $ sudo nano /etc/snmp/snmpd.conf
  
Find a line containing '''"agenAddress udp:127.0.0.1:161"''' and comment it by adding '''#''' symbol at the beginning of the line. Uncomment line '''"agenAddress udp:161,udp6[::1]:161"'''. If you chose different SNMP port change '''161''' into your chosen port. '''Make sure to use exactly the same port as in SNMP package configuration on Teltonika device'''.
+
Find a line containing '''"agenAddress udp:127.0.0.1:161"''' and comment it by adding '''#''' symbol at the beginning of the line. Then find the line '''"agenAddress udp:161,udp6[::1]:161"''' and uncomment it. If you chose different SNMP port change '''161''' into your chosen port. '''Make sure to use exactly the same port as in SNMP package configuration on Teltonika device'''.
  
[[File:Networking device configurationexample traps with terminal snmpd config v1.png]]
+
[[File:Networking device configurationexample traps with terminal snmpd config v3.png]]
 
----
 
----
 
===Snmptrapd.conf===
 
===Snmptrapd.conf===
Line 51: Line 51:
 
'''Also''' you can change first line to '''disableAuthorization yes'''. This will disable all authorizations and any group will be able to send traps to the SNMP Manager.
 
'''Also''' you can change first line to '''disableAuthorization yes'''. This will disable all authorizations and any group will be able to send traps to the SNMP Manager.
  
[[File:Networking device configurationexample traps with terminal snmptrapd config v1.png]]
+
[[File:Networking device configurationexample traps with terminal snmptrapd config v2.png]]
 
----
 
----
 
===Creating Trap listening service===
 
===Creating Trap listening service===
Line 71: Line 71:
 
This configuration will write the log of caught Trap messages into ''' ''/var/log/'' ''' folder and into ''' ''snmptrapd.log'' ''' file. You can change the log file directory and file name.
 
This configuration will write the log of caught Trap messages into ''' ''/var/log/'' ''' folder and into ''' ''snmptrapd.log'' ''' file. You can change the log file directory and file name.
  
[[File:Networking device configurationexample creating snmptrapd service v1.png]]
+
[[File:Networking device configurationexample traps with terminal snmptrapd service v2.png]]
 
----
 
----
  
Line 77: Line 77:
 
MIB file will be used to translate OID codes to more readable format.
 
MIB file will be used to translate OID codes to more readable format.
  
If you dont have the MIB file, download it from SNMP packge WebUI window [[SNMP configuration example#SNMP Configuration]]
+
If you dont have the MIB file, download it from SNMP packge WebUI window, example [[SNMP configuration example#SNMP Configuration | here]]
  
 
After downloading the MIB file, place it in ''' ''/usr/share/snmp/mib'' ''' directory, you can use this command:
 
After downloading the MIB file, place it in ''' ''/usr/share/snmp/mib'' ''' directory, you can use this command:
Line 93: Line 93:
 
to load all existing MIB files in ''/usr/share/snmp/mibs'' directory.
 
to load all existing MIB files in ''/usr/share/snmp/mibs'' directory.
  
[[File:Network device configurationexample traps with terminal snmp config v1.png]]
+
[[File:Networking device configurationexample traps with terminal snmp config v2.png]]
  
 
----
 
----
 +
 
===Launching Trap listening service===
 
===Launching Trap listening service===
  
Line 104: Line 105:
 
  $ sudo /etc/init.d/snmptrapd start
 
  $ sudo /etc/init.d/snmptrapd start
  
[[File:Networking device configurationexample traps with terminal snmptarpd start v1.png]]
+
To stop the service use this command:
 +
 
 +
$ sudo /etc/init.d/snmptrapd stop
  
 
To restart or launch the service you can use this command:
 
To restart or launch the service you can use this command:
Line 110: Line 113:
 
  $ sudo /etc/init.d/snmptrapd restart
 
  $ sudo /etc/init.d/snmptrapd restart
  
[[File:Networking device configurationexample traps with terminal snmptarpd restart v1.png]]
+
[[File:FileNetworking device configurationexample traps with terminal snmptrap commands v2.png]]
 
 
To stop the service use this command:
 
 
 
$ sudo /etc/init.d/snmptrapd stop
 
 
 
[[File:Networking device configurationexample traps with terminal snmptarpd stop v1.png]]
 
  
 
To read service status use this command:
 
To read service status use this command:
Line 122: Line 119:
 
  $ sudo /etc/init.d/snmptrapd status
 
  $ sudo /etc/init.d/snmptrapd status
  
[[File:Networking device configurationexample traps with terminal)snmptrapd status v1.png]]
+
[[File:Networking device configurationexample traps with terminal snmptrapd status v2.png]]
  
 
If SNMP manager caught any traps, connection information can be represented with service status information.
 
If SNMP manager caught any traps, connection information can be represented with service status information.
Line 129: Line 126:
  
 
==Testing if SNMP Trap listening service works==
 
==Testing if SNMP Trap listening service works==
First make sure that SNMP Trap package has Trap rules configured in order to test if listening service works correctly. More information here [[SNMP configuration example#Trap Configuration]]
+
First make sure that SNMP Trap package has Trap rules configured in order to test if listening service works correctly. More information [[SNMP configuration example#Trap Configuration | here]]
  
 
If any Trap was triggered, you can check, if Trap message was caught and logged. Check service '''status''' to see if any connections were established.
 
If any Trap was triggered, you can check, if Trap message was caught and logged. Check service '''status''' to see if any connections were established.
Line 139: Line 136:
  
  
snmptrapd.log file after triggering ''' ''trapDigitalRelayOutputStatus'' ''' by changing '''Digital relay output''' value in WebUI (Services -> Input/Output, Output tab -> ON/OFF tab, using RUT955).
+
snmptrapd.log file after triggering some trap rules:
 
 
[[File:Networking device configurationexample traps with terminal log file after catching trap v1.png]]
 
 
 
 
 
After triggering more Trap rules:
 
  
[[File:Networking device configurationexample traps with terminal caught more traps v1.png]]
+
[[File:Networking device configurationexample traps with terminal snmptrapd log v3.png]]

Latest revision as of 10:28, 23 September 2019

Summary

This chapter is a guide on configuring SNMP Trap listening service on Linux OS.

Preconditions

To configure Trap listening service these packages are required: snmp , snmpd, snmptt, snmptrapd.

To install these packages run command for each package:

$ sudo apt install <package_name>

Also you need to download and load MIB files. Use this command:

$ sudo apt-get install snmp-mibs-downloader

Important note: before continuing make sure that SNMP Trap package is configured. SNMP configuration example can be found here.

Editing configuration files

Snmpd.conf

This is not required for Trap listening service, but with this configuration snmpget command will be able to establish connection without requiring port number in the command line. If you want to configure SNMP so it would listen to the port globally, not locally follow these steps:

Edit snmpd.conf file, it can be found in /etc/snmp/ directory. Example of the command:

$ sudo nano /etc/snmp/snmpd.conf

Find a line containing "agenAddress udp:127.0.0.1:161" and comment it by adding # symbol at the beginning of the line. Then find the line "agenAddress udp:161,udp6[::1]:161" and uncomment it. If you chose different SNMP port change 161 into your chosen port. Make sure to use exactly the same port as in SNMP package configuration on Teltonika device.

Networking device configurationexample traps with terminal snmpd config v3.png


Snmptrapd.conf

This is required to specify community you described in SNMP Trap package configuration, to describe Trap port and how to handle caught Trap messages.

Edit snmptrapd.conf file, it can be found in /etc/snmp/ directory. Example of the command:

$ sudo nano /etc/snmp/snmptrapd.conf

Add these lines at the beginning of the file:

authcommunity log,execute,net public

snmpTrapdAddr udp:1110

traphandle default /usr/sbin/snmptt

In the first line change public to your community group described in SNMP Trap package configuration. In the second line change 1110 port number to your described port number in SNMP Trap package of the Teltonika device.

Also you can change first line to disableAuthorization yes. This will disable all authorizations and any group will be able to send traps to the SNMP Manager.

Networking device configurationexample traps with terminal snmptrapd config v2.png


Creating Trap listening service

This is required for launching Trap listening service with extra configurations, we will use it to describe the log file to which all traps will be recorded.

Use this command:

$ sudo systemctl edit snmptrapd.service

Write these lines into the file:

[Service]

ExecStart=

ExecStart=/usr/sbin/snmptrapd -Ln -f -Lf /var/log/snmptrapd.log

This configuration will write the log of caught Trap messages into /var/log/ folder and into snmptrapd.log file. You can change the log file directory and file name.

Networking device configurationexample traps with terminal snmptrapd service v2.png


Loading MIB file

MIB file will be used to translate OID codes to more readable format.

If you dont have the MIB file, download it from SNMP packge WebUI window, example here

After downloading the MIB file, place it in /usr/share/snmp/mib directory, you can use this command:

$ sudo cp Downloads\TLT-MIB.txt /usr/share/snmp/mibs/TLT-MIB.txt

Now edit file /etc/snmp/snmp.conf . Example of the command:

$ sudo nano /etc/snmp/snmp.conf

Find this line: mibs : and change it to: mibs +ALL to load all existing MIB files in /usr/share/snmp/mibs directory.

Networking device configurationexample traps with terminal snmp config v2.png


Launching Trap listening service

Important note: Trap listening service will stop on system shutdown or restart.

To launch SNMP Trap listening service use this command:

$ sudo /etc/init.d/snmptrapd start

To stop the service use this command:

$ sudo /etc/init.d/snmptrapd stop

To restart or launch the service you can use this command:

$ sudo /etc/init.d/snmptrapd restart

FileNetworking device configurationexample traps with terminal snmptrap commands v2.png

To read service status use this command:

$ sudo /etc/init.d/snmptrapd status

Networking device configurationexample traps with terminal snmptrapd status v2.png

If SNMP manager caught any traps, connection information can be represented with service status information.

Important note: if status shows failed message, one solution could be changing the SNMP Trap port, some other process might be using the described port.

Testing if SNMP Trap listening service works

First make sure that SNMP Trap package has Trap rules configured in order to test if listening service works correctly. More information here

If any Trap was triggered, you can check, if Trap message was caught and logged. Check service status to see if any connections were established.

Open /var/log/snmptrapd.log . If you specified different directory and file name, open it. Example commands:

$ sudo cat /var/log/snmptrapd.log
$ sudo more /var/log/snmptrapd.log
$ sudo nano /var/log/snmptrapd.log


snmptrapd.log file after triggering some trap rules:

Networking device configurationexample traps with terminal snmptrapd log v3.png