Telegraf_SNMP_Trap

Hi Team,

I am trying to setup a snmp_trap input in Telegraf Plugin, but I do have a multiple files within telegraf folder, hence need to understand the following details.

  1. I have 5 different config files(test1.conf, test2.conf, test3.conf), do I need to enable inputs.snmp_trap for each file, since 162 is the default port enabled for all Source IPs

  2. How to enable traps only for specific agent within file, in the example it shows # ## example: “udp://127.0.0.1:1234”, but if I enable like “udp://127.0.0.1:1234” it wont run the telegraf file

  3. How to setup traps for specific is below example correct?

[[inputs.snmp_trap]]
    oid = "HOST-RESOURCES-MIB::hrStorageTable"
    name = "hrStorageTable"
   inherit_tags = ["source"]

[[inputs.snmp_trap]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”

inherit_tags = [“source”]

Hi,

You can define multiple snmp traps, but if they are going to run on the same system, then you will need to define them on different ports.

It is not clear how you intended to use those different configuration files. Do you plan to run multiple telegraf or just one? Do you want to have multiple traps?

Thank you @jpowers for your response on this.

Yes I am using more than 5 telegraf.conf file in getting data from multiple servers.
Port 162 is opened by default for all servers, so do I need to enable trap in all 5 telegraf.conf files, or any one file is enough to get the data from all servers.

Also how do I enable trap specifically for single agent in telegraf.conf file?

Telegraf is config driven, so whatever config you pass to telegraf is what is used. For example --config test1.conf

If you are running as a service, telegraf will look at /etc/telegraf/telegraf.conf and the files under /etc/telegraf/telegraf.conf.d/ by default.

Could you please provide the answer for below query?

  1. I have 5 different config files(test1.conf, test2.conf, test3.conf), do I need to enable inputs.snmp_trap for each file, since 162 is the default port enabled for all Source IPs

  2. How to enable traps only for specific agent within file(I have more than 5 agents added in the file), in the example it shows # ## example: “udp://127.0.0.1:1234”, but if I enable like “udp://127.0.0.1:1234” it wont run the telegraf file

I don’t understand why you want to enable it in each file. What is your scenario and what are you trying to do? Do you plan to run multiple telegraf instances or a single one? How many snmp traps do you need?

I have 5 different config files and each file monitoring different type of product with 10 agents, traps are enabled with default port 162. So do I need to enable traps in only test1.conf file or for all .conf file need to enable?

If you are running a single telegraf, then you will only be able to run a single trap plugin on port 162. Otherwise as my original message said you will get errors about conflicting ports.

ok thank you for your response.
I believe if I enable traps in any one .conf file all agents(10 agents configured in 5 .conf file) will start sending the traps right?

Additionally can you please confirm how to add specific agent in the .conf file? In below example if I want to add only 3 agents example 10.10.10.1, 10.10.10.2, 10.10.10,3?

# [[inputs.snmp_trap]]
#   ## Transport, local address, and port to listen on.  Transport must
#   ## be "udp://".  Omit local address to listen on all interfaces.
#   ##   example: "udp://127.0.0.1:1234"

Please checkout the snmp trap readme:

It only allows for a single interface to listen on. If by agetn you mean an snmp trap listener then you need to define multiple plugins.

Thanks for your response on this

Currently I have added 10 agents in single .conf file with multiple plugins of inputs.snmp.
But if I enable Inputs.snmp.trap as per below configuration then it stopped getting all inputs.snmp data from same file.

[[inputs.snmp_trap]]
service_address = "udp://:162
path = ["/usr/share/snmp/mibs"]
#version = "2c"

Please provide your config and logs

Here is the configuration file. If I disable the snmp version in the inputs.snmp.trap then it works fine, however it doesn’t provide any trap data. If I keep snmp version the inputs.snmp.trap then entire file not providing an output to influxdb.

# # Retrieves SNMP values from remote agents
[[inputs.snmp]]
agents = ["udp://10.10.10.1"]
tags = {alias = "SUBb_a"}

#   ## Timeout for each request.
timeout = "25s"
#
#   ## SNMP version; can be 1, 2, or 3.
version = 2
#
#   ## Unconnected UDP socket
#   ## When true, SNMP reponses are accepted from any address not just
#   ## the requested address. This can be useful when gathering from
#   ## redundant/failover systems.
#   # unconnected_udp_socket = false
#
#   ## Path to mib files
#   ## Used by the gosmi translator.
#   ## To add paths when translating with netsnmp, use the MIBDIRS environment variable
path = ["/usr/share/snmp/mibs"]
#
#   ## SNMP community string.
community = "ciscotest"
#
#   ## Agent host tag
#agent_host_tag = "agent_host"
#
#   ## Number of retries to attempt.
retries = 3
interval = "60s"
#
#   ## The GETBULK max-repetitions parameter.
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”

inherit_tags = [“source”]


[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRegisteredPhones.0"
name = "Cisco-RegisteredPhones"
# inherit_tags = ["source"]

#####################################################################################################################

[[inputs.snmp]]
agents = ["udp://10.10.10.2"]
tags = {alias = "SUBb_b"}
timeout = "25s"
version = 2
path = ["/usr/share/snmp/mibs"]
community = "ciscotest"
retries = 3
interval = "60s"
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”

inherit_tags = [“source”]


[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRegisteredPhones.0"
name = "Cisco-RegisteredPhones"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRejectedPhones.0"
name = "Cisco-RejectedPhones"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRegisteredGateways.0”
name = “Cisco-RegisteredGateways”

inherit_tags = [“source”]

``

##########################################################################################################

[[inputs.snmp]]
agents = ["udp://10.10.10.3"]
tags = {alias = "SUBb_c"}
timeout = "25s"
version = 2
path = ["/usr/share/snmp/mibs"]
community = "ciscotest"
retries = 3
interval = "60s"
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”

inherit_tags = [“source”]


[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRegisteredPhones.0"
name = "Cisco-RegisteredPhones"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRejectedPhones.0"
name = "Cisco-RejectedPhones"
# inherit_tags = ["source"]

################################################################################################

[[inputs.snmp]]
agents = ["udp://10.10.10.4"]
tags = {alias = "SUBb_d"}
timeout = "25s"
version = 2
path = ["/usr/share/snmp/mibs"]
community = "ciscotest"
retries = 3
interval = "60s"
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRegisteredPhones.0"
name = "Cisco-RegisteredPhones"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”

inherit_tags = [“source”]

################################################################################################

[[inputs.snmp]]
agents = ["udp://10.10.10.5"]
tags = {alias = "SUBb_e"}
timeout = "25s"
version = 2
path = ["/usr/share/snmp/mibs"]
community = "ciscotest"
retries = 3
interval = "60s"
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRegisteredPhones.0"
name = "Cisco-RegisteredPhones"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”

inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRejectedPhones.0"
name = "Cisco-RejectedPhones"
# inherit_tags = ["source"]

# Receive SNMP traps

[[inputs.snmp_trap]]
#   ## Transport, local address, and port to listen on.  Transport must
#   ## be "udp://".  Omit local address to listen on all interfaces.
#   ##   example: "udp://127.0.0.1:1234"
#   ##
#   ## Special permissions may be required to listen on a port less than
#   ## 1024.  See README.md for details
#   ##
service_address = "udp://:162"
#   ##
#   ## Path to mib files
#   ## Used by the gosmi translator.
#   ## To add paths when translating with netsnmp, use the MIBDIRS environment variable
path = ["/usr/share/snmp/mibs"]
#   ##
#   ## Deprecated in 1.20.0; no longer running snmptranslate
#   ## Timeout running snmptranslate command
#   # timeout = "5s"
#   ## Snmp version
version = "2c"

If you could please put ``` above and after your config it will make it much easier to read.

@hipska does anything stand out about the versions?

[[inputs.snmp]]
agents = ["udp://10.10.10.1"]
tags = {alias = "SUBb_a"}

#   ## Timeout for each request.
timeout = "25s"
#
#   ## SNMP version; can be 1, 2, or 3.
version = 2
#
#   ## Unconnected UDP socket
#   ## When true, SNMP reponses are accepted from any address not just
#   ## the requested address. This can be useful when gathering from
#   ## redundant/failover systems.
#   # unconnected_udp_socket = false
#
#   ## Path to mib files
#   ## Used by the gosmi translator.
#   ## To add paths when translating with netsnmp, use the MIBDIRS environment variable
path = ["/usr/share/snmp/mibs"]
#
#   ## SNMP community string.
community = "ciscotest"
#
#   ## Agent host tag
#agent_host_tag = "agent_host"
#
#   ## Number of retries to attempt.
retries = 3
interval = "60s"
#
#   ## The GETBULK max-repetitions parameter.
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”

inherit_tags = [“source”]
[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRegisteredPhones.0"
name = "Cisco-RegisteredPhones"

[[inputs.snmp]]
agents = [“udp://10.10.10.2”]
tags = {alias = “SUBb_b”}
timeout = “25s”
version = 2
path = [“/usr/share/snmp/mibs”]
community = “ciscotest”
retries = 3
interval = “60s”
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “HOST-RESOURCES-MIB::hrSystemProcesses.0”
name = “Cisco-SystemProcesses”

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”

inherit_tags = [“source”]
[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRegisteredPhones.0”
name = “Cisco-RegisteredPhones”

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRejectedPhones.0”
name = “Cisco-RejectedPhones”

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRegisteredGateways.0”
name = “Cisco-RegisteredGateways”
inherit_tags = [“source”]

``

[[inputs.snmp]]
agents = [“udp://10.10.10.3”]
tags = {alias = “SUBb_c”}
timeout = “25s”
version = 2
path = [“/usr/share/snmp/mibs”]
community = “ciscotest”
retries = 3
interval = “60s”
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “HOST-RESOURCES-MIB::hrSystemProcesses.0”
name = “Cisco-SystemProcesses”

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRegisteredPhones.0”
name = “Cisco-RegisteredPhones”

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRejectedPhones.0”
name = “Cisco-RejectedPhones”

[[inputs.snmp]]
agents = ["udp://10.10.10.4"]
tags = {alias = "SUBb_d"}
timeout = "25s"
version = 2
path = ["/usr/share/snmp/mibs"]
community = "ciscotest"
retries = 3
interval = "60s"
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”

[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmRegisteredPhones.0"
name = "Cisco-RegisteredPhones"


[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”
inherit_tags = [“source”]

[[inputs.snmp]]
agents = [“udp://10.10.10.5”]
tags = {alias = “SUBb_e”}
timeout = “25s”
version = 2
path = [“/usr/share/snmp/mibs”]
community = “ciscotest”
retries = 3
interval = “60s”
max_repetitions = 10

[[inputs.snmp.field]]
oid = “DISMAN-EVENT-MIB::sysUpTimeInstance”
name = “Cisco-Uptime”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “HOST-RESOURCES-MIB::hrSystemProcesses.0”
name = “Cisco-SystemProcesses”

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmSystemVersion.0”
name = “Cisco-SystemVersion”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRegisteredPhones.0”
name = “Cisco-RegisteredPhones”

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmUnregisteredPhones.0”
name = “Cisco-UnRegisteredPhones”
inherit_tags = [“source”]

[[inputs.snmp.field]]
oid = “CISCO-CCM-MIB::ccmRejectedPhones.0”
name = “Cisco-RejectedPhones”


# Receive SNMP traps
[[inputs.snmp_trap]]
#   ## Transport, local address, and port to listen on.  Transport must
#   ## be "udp://".  Omit local address to listen on all interfaces.
#   ##   example: "udp://127.0.0.1:1234"
#   ##
#   ## Special permissions may be required to listen on a port less than
#   ## 1024.  See README.md for details
#   ##
service_address = "udp://:162"
#   ##
#   ## Path to mib files
#   ## Used by the gosmi translator.
#   ## To add paths when translating with netsnmp, use the MIBDIRS environment variable
path = ["/usr/share/snmp/mibs"]
#   ##
#   ## Deprecated in 1.20.0; no longer running snmptranslate
#   ## Timeout running snmptranslate command
#   # timeout = "5s"
#   ## Snmp version
version = "2c"

Yes, please put your config in a code block so we can correctly investigate it. The way it is now, we can’t see if any problems are in it…

What are you getting when running telegraf --test with your config file?

Note that the snmp_trap input is for receiving traps. All your agents can send to that input, there is no need to specify multiple inputs for that.

Thanks Hipska and @jpowers

After reviewing the documents and configuration, I have enabled the accurate parameter for inputs.snmp.trap configuration within .conf file. Currently the same file with 10 agents running with inputs.snmp and inputs.snmp.trap plugin.

But in influxdb, I am unable to see the inputs.snmp.trap output. Can you please confirm how to execute test only for trap in telegraf and ensure we are good?

You can run telegraf --test-wait 60 on your config, then send a test trap within a minute and see in the output if you find it, or if you receive an error…

Thank you, I will do the test, before that if I try adding the community name under input.snmp.trap plugin I am getting following error whilst restart the telegraf plugin.

the same .conf file has both inputs.snmp and input.snmp.trap plugin

[root@hnctrv01 telegraf.d]# systemctl restart telegraf
Job for telegraf.service failed because the control process exited with error code. See “systemctl status telegraf.service” and “journalctl -xe” for details.

[[inputs.snmp]]
agents = ["udp://10.10.10.05"]
tags = {alias = "SUB-suba"}
timeout = "25s"
version = 2
path = ["/usr/share/snmp/mibs"]
community = "ciscodwtest"
retries = 3
interval = "60s"
max_repetitions = 10

[[inputs.snmp.field]]
oid = "DISMAN-EVENT-MIB::sysUpTimeInstance"
name = "Cisco-Uptime"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = "HOST-RESOURCES-MIB::hrSystemProcesses.0"
name = "Cisco-SystemProcesses"
# inherit_tags = ["source"]

[[inputs.snmp.field]]
oid = "CISCO-CCM-MIB::ccmSystemVersion.0"
name = "Cisco-SystemVersion"
# inherit_tags = ["source"]


[[inputs.snmp_trap]]
service_address = "udp://:162"
path = ["/usr/share/snmp/mibs"]
version = "2c"
community = "ciscodwtest"

community is not a valid config option for snmp_trap input, see documentation. You would have seen that if you checked the actual error with journalctl as suggested…