telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

Actual real-world examples of SNMP

Open kiler129 opened this issue 6 years ago • 13 comments

Feature Request

SNMP is hard... and annoying. I looked at telegraf to add it to my stack hopefully improving the experience. However, so far all the "ancient" tools seems way easier to configure and use, probably because of the lack of documentation for telegraf snmp input plugin.

  • There's some documentation at https://www.influxdata.com/integration/snmp/ which references "Cookbook Directory" and other seemingly useful things which are nowhere to be found
  • There's another part of the docs in the repo itself: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/snmp
  • A lot of information is scattered around GH issues

I think the documentation lacks a one fundamental thing: a real-world example. The second documentation starts talking about that topic mentioning input_juniper_srx.<device_hostname>.toml.conf. For example: input_juniper_srx.core-fw-1.toml.conf part, but no further information is available.

Proposal:

A single example configuration file (files?) should be provided with the SNMP plugin. The usage of TOML doesn't exactly make things easier. The 30+ years protocol is hard on its own ;)

In a real world there isn't gonna be one host with one set of fields.

Current behavior:

After literally 3h of googling and trying, as a person with well over ten years of experience, I gave up. This is not exactly encouraging.

What I wanted to achieve is seemingly simple:

  • Grab data from 5 devices
    • 1 of them is unique (i.e. all snmp parameters are different)
    • 2 of them are exactly the same (i.e. all field/table related stuff shouldn't be shared while stuff related to the connection like agents or retries must be different)
    • 3 of them are from the same vendor but with differences (i.e. there's a base set of field/table entries with additional ones per specific device type or even that specific device, or in simpler words how extension of "templates" should be handles)
  • Push all data to InfluxDB

From what I see now fields can be just dumped into one bucket. This is literally impossible to handle since all devices will have different MIBs.

Desired behavior:

Provide examples of real-world configs.

Use case:

Making the barrier of entry lower - currently the bar is set so high that I'm having a hard time convincing myself to the stack, not to even mention the company :)

kiler129 avatar Apr 29 '20 10:04 kiler129

First of all, I definitely agree with you that it can be quite difficult to setup this plugin and that there is plenty of room for improvement. I'd love to see hear more about configuring with other tools, maybe we can adopt some of their ideas.

I'll raise the issues mentioned on https://www.influxdata.com/integration/snmp/ with the appropriate team, but I feel like there is some confusion in that document between the bare Telegraf plugin and https://github.com/robcowart/influx_snmp example setup.

I'd be happy to include some examples in the plugin documentation, perhaps we can work through your configuration and then add it as the first real world example.

As a bare minimum, you might try the example configuration here. TOML is a bit of a hurdle at first, and this plugin make heavy use of tables and arrays of tables. It may be useful to consult the TOML spec. I think it would be helpful if we created a quick start guide for using TOML with Telegraf, that doesn't require prior knowledge of the format.

I think it would also make sense to add some additional documentation around handling multiple devices. I can give you a bit of advice here. You will likely want to setup multiple plugins for this, generally one per device type:

[[inputs.snmp]]
  agents = ["device1"]
  # ... all the options/fields/tables

[[inputs.snmp]]
  agents = ["device2", "device3"]
  # ... all the options/fields/tables

You can even split some devices over multiple plugins, doing the base variables in one and additional ones in a separate configuration:

[[inputs.snmp]]
  agents = ["device1", "device2"]
  # ... all the base options/fields/tables

[[inputs.snmp]]
  agents = ["device1"]
  # ... all the extra options/fields/tables

[[inputs.snmp]]
  agents = ["device2"]
  # ... all the extra options/fields/tables

Let me know what other sort of issues you are running into and we can work through them.

From what I see now fields can be just dumped into one bucket. This is literally impossible to handle since all devices will have different MIBs.

I would recommend writing all the data into a single bucket, unless you need differing access controls, but potentially with different measurement names for the different devices. You can control the measurement name on a per plugin basis by using the name_override option.

danielnelson avatar Apr 29 '20 20:04 danielnelson

Hi Daniel!

Thank you for your thoughtful explanation. I was able to get some understanding of TOML, I think a gentle introduction to TOML will be great to have in the docs, especially showing people "hey, this is the TOML and here's how it looks like as a parsed tree" (with no specific format in mind, just a bare ascii tree).

Basic setup

Coming back to the configuration itself I started with a simpler part of the setup - two devices from the same vendor (Synology DSM cluster). For simplicity let's say we're pulling two the same things from both: FQDN as a tag and uptime.

For the basic config:

[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  flush_jitter = "0s"
  precision = ""

  hostname = "mon-1.example.com"
  omit_hostname = false

  debug = true

# Just to have something other than SNMP
[[inputs.cpu]]
  totalcpu = true

[[outputs.influxdb]]
  urls = ["http://influxdb:8086"]
  database = "telegraf"
  skip_database_creation = false
  timeout = "2s"

[[processors.printer]]

SNMP setup - single device

Then the harder part - SNMP. The configuration for a single host is rather simple and straight forward:

[[inputs.snmp]]
    name = "snmp.dsm"
    agents = ["udp://sysdev-dsm-1.example.com:161"]

    timeout = "3s"
    retries = 5

    version = 3
    sec_name = "dsm-1-user"
    sec_level = "authPriv"
    auth_protocol = "SHA"
    auth_password = "dsm-1-pwd"
    priv_protocol = "AES"
    priv_password = "dsm-1-key"

    [[inputs.snmp.field]]
        name = "sysName"
        oid = "RFC1213-MIB::sysName.0"
        is_tag = true

    [[inputs.snmp.field]]
        name = "sysUpTime"
        oid = "RFC1213-MIB::sysUpTime.0"

SNMP setup - two devices

...and here's where it gets nasty or confusing. You cannot simply change agents to ["udp://sysdev-dsm-1.example.com:161", "udp://sysdev-dsm-2.example.com:161"] since for security reasons no two systems can share the same authentication data. I attempted to configure this in the following way:

[[inputs.snmp]]
    name = "snmp.dsm"
    timeout = "3s"
    retries = 5

    version = 3

    [[inputs.snmp.field]]
        name = "sysName"
        oid = "RFC1213-MIB::sysName.0"
        is_tag = true

    [[inputs.snmp.field]]
        name = "sysUpTime"
        oid = "RFC1213-MIB::sysUpTime.0"

[[inputs.snmp]]
    agents = ["udp://sysdev-dsm-1.example.com:161"]
    sec_name = "dsm-1-user"
    sec_level = "authPriv"
    auth_protocol = "SHA"
    auth_password = "dsm-1-pwd"
    priv_protocol = "AES"
    priv_password = "dsm-1-key"

[[inputs.snmp]]
    agents = ["udp://sysdev-dsm-2.example.com:161"]
    sec_name = "dsm-2-user"
    sec_level = "authPriv"
    auth_protocol = "SHA"
    auth_password = "dsm-2-pwd"
    priv_protocol = "AES"
    priv_password = "dsm-2-key"

As you probably guessed this doesn't work at all :) Telegraf produces the following log:

2020-05-01T04:29:55Z I! Starting Telegraf 1.14.2
2020-05-01T04:29:55Z I! Using config file: /etc/telegraf/telegraf.conf
2020-05-01T04:29:55Z I! Loaded inputs: snmp snmp snmp cpu
2020-05-01T04:29:55Z I! Loaded aggregators:
2020-05-01T04:29:55Z I! Loaded processors: printer
2020-05-01T04:29:55Z I! Loaded outputs: influxdb
2020-05-01T04:29:55Z I! Tags enabled: host=mon-1.example.com
2020-05-01T04:29:55Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"mon-1.example.com", Flush Interval:10s
2020-05-01T04:29:55Z D! [agent] Initializing plugins
2020-05-01T04:29:55Z D! [agent] Connecting outputs
2020-05-01T04:29:55Z D! [agent] Attempting connection to [outputs.influxdb]
2020-05-01T04:29:55Z D! [agent] Successfully connected to outputs.influxdb
2020-05-01T04:29:55Z D! [agent] Starting service inputs
2020-05-01T04:30:00Z D! [inputs.snmp] executing "snmptranslate" "-Td" "-Ob" "RFC1213-MIB::sysName.0"
2020-05-01T04:30:00Z D! [inputs.snmp] executing "snmptranslate" "-Td" "-Ob" "RFC1213-MIB::sysUpTime.0"
2020-05-01T04:30:10Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
cpu,cpu=cpu0,host=mon-1.example.com usage_guest_nice=0,usage_iowait=0.1000000000002001,usage_irq=0,usage_softirq=0,usage_steal=0,usage_user=0.40000000000193725,usage_system=0.3000000000008845,usage_idle=99.20000000012573,usage_nice=0,usage_guest=0 1588307410000000000
cpu,cpu=cpu-total,host=mon-1.example.com usage_user=0.40000000000193725,usage_system=0.3000000000008845,usage_softirq=0,usage_guest_nice=0,usage_idle=99.20000000012573,usage_nice=0,usage_iowait=0.1000000000002001,usage_irq=0,usage_steal=0,usage_guest=0 1588307410000000000
cpu,cpu=cpu0,host=mon-1.example.com usage_iowait=0.2997002997000322,usage_irq=0,usage_steal=0,usage_guest=0,usage_guest_nice=0,usage_idle=99.30069930063017,usage_nice=0,usage_softirq=0,usage_user=0.29970029969974826,usage_system=0.09990009989991609 1588307420000000000
cpu,cpu=cpu-total,host=mon-1.example.com usage_user=0.29970029969974826,usage_softirq=0,usage_irq=0,usage_steal=0,usage_guest=0,usage_guest_nice=0,usage_system=0.09990009989991609,usage_idle=99.30069930063017,usage_nice=0,usage_iowait=0.2997002997000322 1588307420000000000
2020-05-01T04:30:20Z D! [outputs.influxdb] Wrote batch of 2 metrics in 8.805952ms
2020-05-01T04:30:20Z D! [outputs.influxdb] Buffer fullness: 2 / 10000 metrics
cpu,cpu=cpu0,host=mon-1.example.com usage_idle=99.10089910093483,usage_nice=0,usage_steal=0,usage_guest_nice=0,usage_user=0.39960039959966437,usage_system=0.2997002997000322,usage_iowait=0.19980019980011612,usage_irq=0,usage_softirq=0,usage_guest=0 1588307430000000000
cpu,cpu=cpu-total,host=mon-1.example.com usage_softirq=0,usage_steal=0,usage_guest=0,usage_user=0.39960039959966437,usage_nice=0,usage_iowait=0.19980019980011612,usage_guest_nice=0,usage_system=0.2997002997000322,usage_idle=99.10089910093483,usage_irq=0 1588307430000000000
2020-05-01T04:30:30Z D! [outputs.influxdb] Wrote batch of 2 metrics in 9.518067ms
2020-05-01T04:30:30Z D! [outputs.influxdb] Buffer fullness: 2 / 10000 metrics
2020-05-01T04:30:33Z D! [agent] Stopping service inputs
2020-05-01T04:30:33Z D! [agent] Input channel closed
2020-05-01T04:30:33Z D! [agent] Processor channel closed
2020-05-01T04:30:33Z I! [agent] Hang on, flushing any cached metrics before shutdown
2020-05-01T04:30:33Z D! [outputs.influxdb] Wrote batch of 2 metrics in 5.919415ms
2020-05-01T04:30:33Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2020-05-01T04:30:33Z D! [agent] Closing outputs
2020-05-01T04:30:33Z D! [agent] Stopped Successfully

Possible solution

I don't think Telegraf is lacking here - I think the TOML ~~(or lack of understanding on my side?)~~ is. => Update: it's definitely TOML being... limited, see https://github.com/toml-lang/toml/issues/77#issuecomment-14274593.

In YAML, a format which I'm more familiar with, there's a cool party trick where you can do a syntax-assisted copy-paste. After all ultimately we don't care how big the config is - we care how much of it we have to write, right?

__commonFields: &allCommon
  sysName: &commSysName
    oid: RFC1213-MIB::sysName.0
    isTag: true
  
  sysUpTime: &commSysUpTime
    oid: RFC1213-MIB::sysUpTime.0  

inputs:
  snmp: 
    -
      agents: ["a", "b"]
      field:
        <<: *allCommon
        sysFoo: [oid: abc]

    -
      agents: ["c", "d"]
      field:
        sysSnowflake: *commSysName
        sysFoo: { oid: abc }

(In case you're not familiar with YAML you can see how such code translates to plain JSON)

I wonder if something like that can be done in TOML, or maybe if the Telegraf input.snmp has some sane way of handling this? Repetition in the config parsed by the Go is ultimately actually good - less logic to handle there, however you definitely don't want to have that repetition done in the actual file.

Data Categorization

I would recommend writing all the data into a single bucket, unless you need differing access controls (...)

You're actually right - I can drop devices into sane buckets (e.g. SANs / routers / switches / endpoints) and tag them by hostname. This will actually make dashboards easier, since within the category the variety is relatively small.

You're not alone! :)

If we figure it out I will be happy to contribute to the docs. Unlike most of the tech people I actually don't mind writing docs.


p.s. I believe I also hit #2590 / #4979 while testing with the snippet below (but that's a discussion for another issues):

    [[inputs.snmp.field]]
        name = "upsCharge"
        #oid = "SYNOLOGY-UPS-MIB::upsBatteryChargeValue" => used with newest MIBs mapped to the docker container from host
        oid = ".1.3.6.1.4.1.6574.4.3.1.1" # => ultimately this doesn't work either with no MIBs loaded
        #conversion = "float" => doesn't change the outcome
        #is_tag = true

The snmptranslate but after that metrics are simply not being collected at all like they were never in the file. This is something which I think should be improved overall: the plugin swallows errors instead of screaming about them.

kiler129 avatar May 01 '20 04:05 kiler129

@kiler129 @danielnelson just trying to get any output at the moment. ive ansibled 90% of the install just trying to get config done now

  • The idea we wanted was each device recording data into its own time series, so we can pull it out easily for granfana & so that if a device goes EOL we can just remove the time series.
  • if you give advice or help me get to that position that be fantastic

do you see anything wrong here?

[agent]

  interval = "5s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = ""
  omit_hostname = false
  logfile = "logs/log.conf"

[[inputs.snmp]]
    agents = [ "10.242.43.3:161", "10.242.42.3:161"]
    version = 3
    interval = '60s'
    timeout = '20s'
    retries = 3

    ## SNMPv3 authentication and encryption options.
    sec_name = "user"
    auth_protocol = "SHA"
    auth_password = "pw"
    sec_level = "authPriv"
    priv_protocol = "DES"
    priv_password = "pw"

    [[inputs.snmp.field]]
    name = "Octets Received"
    oid = "IF-MIB::ifInOctets.50"
    is_tag = true


[[outputs.influxdb]]
  username = "user"
  password = "pw"
  urls = ["http://127.0.0.1:8086"]

all im getting out of logs is

2020-05-01T08:52:36Z I! [agent] Config: Interval:5s, Quiet:false, Hostname:"hidden", Flush Interval:10s
2020-05-01T09:03:59Z I! [agent] Hang on, flushing any cached metrics before shutdown
2020-05-01T09:12:47Z I! Loaded inputs: snmp
2020-05-01T09:12:47Z I! Loaded aggregators:
2020-05-01T09:12:47Z I! Loaded processors:
2020-05-01T09:12:47Z I! Loaded outputs: influxdb
2020-05-01T09:12:47Z I! Tags enabled: host=hidden
2020-05-01T09:12:47Z I! [agent] Config: Interval:5s, Quiet:false, Hostname:"hidden", Flush Interval:10s
2020-05-01T09:15:34Z I! [agent] Hang on, flushing any cached metrics before shutdown

running telegraf -config /apps/monitor/influxdb/telegraf.conf, just sits their with this forever 2020-05-01T09:16:54Z I! Starting Telegraf 1.14.0

smogsy avatar May 01 '20 08:05 smogsy

@danielnelson I got the Telegraf snmp plugin working

  • Tags do not work if only one check is enabled. This was not documented clearly. wasted hours of my time :(
  1. Now what would you recommend for recording hundreds of devices into a Time Series? Should we create a Series per device or just use tags?

  2. Currently have this [[outputs.influxdb]] database = "ukb_testlab" username = "{{ user }}" password = "{{ password }}" urls = ["http://127.0.0.1:8086"]

it's saving in time series name of snmp,agent_host=10.242.43.3,host=hostname.com

how can i get to me more useful? like just 10.242.43.3 for example

  1. how do i pull a entire field data? im using this, all i want if the ifnames to be stored in time series & its pulling the entire table [[inputs.snmp.table]] name = "cmts" inherit_tags = [ "hostname" ] oid = "IF-MIB::ifXTable"

    [[inputs.snmp.table.field]] name = "ifName" oid = "IF-MIB::ifName" is_tag = true

smogsy avatar May 01 '20 12:05 smogsy

As you have found, TOML doesn't have anything built-in for referencing shared data, so currently it is required to duplicate this information. We have quite a few users who generate their configurations from templates, often using ansible, for this reason.

It still isn't ideal, when you get into the hundreds or thousands of plugins it can be a bit slow to parse the massive configuration. Ultimately we could design a reference syntax on top of TOML, however, we are wary when it comes to custom extensions to what TOML provides since it would be non-standard.

It seems like we need to report a few configuration issues as errors in the plugin:

  • Error when no fields/tables are defined.
  • Error if only tags are defined, we may not be able to detect this in all cases at startup so this may need to be a runtime error.
  • Error if version=3 snmp is not fully configured.

I would also have expected a timeout error for the first plugin without a sec_name, so this needs looked into as well.


@smogsy

  1. I suggest using a tag for the device, and naming the measurement based on the type of data you collect.
  2. Sorry, I don't udnerstand what you would like to do here.
  3. If you leave off the oid for the table, and then only the fields defined will be collected. Make sure you always collect at least one field, this is a requirement of our data model.
[[inputs.snmp.table]]
  name = "cmts"
  inherit_tags = [ "hostname" ]

  [[inputs.snmp.table.field]]
    name = "ifName"
    oid = "IF-MIB::ifName"

danielnelson avatar May 01 '20 20:05 danielnelson

@danielnelson the documentation may not be great but your support has been excellent, thank you ever so much. going to post on theinfluxdb board going forward however,

question 1 - i have current done the following in the config (before you suggestion) agents = [ "ip", "ip" , "ip" ] is it possible to tag these inside agents or do i require to spilt these agents up and duplicate checks just for tagging purposes.

question 2. when you go to SELECT SERIES inside influx it comes back with the series name snmp,agent_host=10.242.43.3,host=hostname.com wondered if their was a way to name this SERIES netgear-model for example

question 3 - that makes sense thankyou!

much appericate all your help

smogsy avatar May 03 '20 06:05 smogsy

As you have found, TOML doesn't have anything built-in for referencing shared data, so currently it is required to duplicate this information. We have quite a few users who generate their configurations from templates, often using ansible, for this reason.

It still isn't ideal, when you get into the hundreds or thousands of plugins it can be a bit slow to parse the massive configuration. Ultimately we could design a reference syntax on top of TOML, however, we are wary when it comes to custom extensions to what TOML provides since it would be non-standard.

It seems like we need to report a few configuration issues as errors in the plugin:

* Error when no fields/tables are defined.

* Error if only tags are defined, we may not be able to detect this in all cases at startup so this may need to be a runtime error.

* Error if version=3 snmp is not fully configured.

I would also have expected a timeout error for the first plugin without a sec_name, so this needs looked into as well.

@smogsy

1. I suggest using a tag for the device, and naming the measurement based on the type of data you collect.

2. Sorry, I don't udnerstand what you would like to do here.

3. If you leave off the oid for the table, and then only the fields defined will be collected.  Make sure you always collect at least one field, this is a requirement of our data model.
[[inputs.snmp.table]]
  name = "cmts"
  inherit_tags = [ "hostname" ]

  [[inputs.snmp.table.field]]
    name = "ifName"
    oid = "IF-MIB::ifName"

added to this is an OID is not valid no error is returned on --test cli.

example Working: ifHCOutOctets does not work: ifHCoutOctets (no error is produced)

smogsy avatar May 04 '20 07:05 smogsy

question 1 - i have current done the following in the config (before you suggestion) agents = [ "ip", "ip" , "ip" ] is it possible to tag these inside agents or do i require to spilt these agents up and duplicate checks just for tagging purposes.

Telegraf automatically tags the series with the device address, but if you want to add additional tags you have two choices:

  1. Split each device into a separate plugin. This may be more verbose but has some advantages with respect to error handling, as each plugin is fully independent (see #7470):

    [[inputs.snmp]]
      agents = ["10.0.0.1"]
      ## all other options
      [inputs.snmp.tag]
        taga = "a"
        tagb = "b"
    
    [[inputs.snmp]]
      agents = ["10.0.0.2"]
      ## all other options again
      [inputs.snmp.tag]
        taga = "a"
        tagb = "b"
    
  2. Add additional tags in a processor:

    [[processors.override]]
      [processor.override.tagpass]
        agent_host = ["10.0.0.1"]
      [processor.override.tag]
        taga = "a"
        tagb = "b"
    
    [[processors.override]]
      [processor.override.tagpass]
        agent_host = ["10.0.0.2"]
      [processor.override.tag]
        taga = "a"
        tagb = "b"
    

question 2. when you go to SELECT SERIES inside influx it comes back with the series name snmp,agent_host=10.242.43.3,host=hostname.com wondered if their was a way to name this SERIES netgear-model for example

I believe you are referring to what InfluxDB calls the "measurement", in your example it is snmp. You can change this in Telegraf with the name_override option on any plugin, or for tables you can set the name of the table:

[[inputs.snmp]]
  name_override = "netgear-model"

  [[inputs.snmp.table]]
    oid = "IF-MIB::ifTable"
    name = "netgear-model-mytable"

added to this is an OID is not valid no error is returned on --test cli.

:+1: thanks

danielnelson avatar May 07 '20 00:05 danielnelson

thanks i got it how i like it in the end. got config file per device & templated with ansible dictionary function :)

smogsy avatar May 07 '20 06:05 smogsy

Hey @kiler129 and @smogsy! There is a lot in here but I'd like to see if we can find somewhere to include more inputs.snmp examples. Is there examples you found particularly use for common scenarios? What i'm seeing from the thread: adding tags for device management, using separate plugins for a "class" of SNMP devices.

Let me know and we can get some stuff added to either the README or the InfluxData documentation

sjwang90 avatar Sep 24 '20 22:09 sjwang90

I just ran into this as well and found myself incredibly confused. Here's what I think would be helpful:

  1. Fix https://www.influxdata.com/integration/snmp/ and either remove the references the cookbook, devices, and OIDs directories or provide links to the real locations.
  2. Update https://github.com/influxdata/telegraf/blob/master/plugins/inputs/snmp/README.md to include the following examples:
    1. Complete example of a single device and retrieving an entire SNMP table
    2. Example of retrieving several OIDs (example already exists in docs)
    3. Provide link(s) to documentation to help new users understand SNMP tables and fields
    4. Provide link(s) to documentation to help new users understand OIDs
    5. Simple but complete example of at least 2 different devices with different community strings and tags

organicveggie avatar Feb 04 '21 02:02 organicveggie

Thanks for you feedback. I think what you laid out @organicveggie is really good.

  1. Working with the appropriate team to get the existing integration information removed. Doesn't seem like there actual locations of these directories.
  2. Let's use your list as a checklist of getting real world example configurations into this testdata folder.

If anyone has any examples they would like to add to the "Real-world Configuration Examples" section please open a PR

sjwang90 avatar Feb 04 '21 20:02 sjwang90

It looks like there have been some more examples added to the readme so I am going to close this for now. If you still think the documentation could be improved please open another ticket. Thank you!

MyaLongmire avatar Jan 11 '22 19:01 MyaLongmire