snmp_exporter. server returned HTTP status 500 Internal Server Error

4,126 views
Skip to first unread message

Hemedi Salim

unread,
Feb 28, 2022, 7:48:20 AM2/28/22
to Prometheus Users
Hi all,

I am babie to this world(prometheus, snmp_exporter).Ā  I recently configure Prometheus/snmp_exporter to monitors swithes. I want to monitor 5 switchesĀ  but Prometheus scrap metrics form 2 switches and the other three shows an error ( server returned HTTP status 500 Internal Server Error).

am using the default smnp.yml which I generate form snmp generator. and my Prometheus.yml setting look like this:

Ā job_name: snmp
metrics_path: /snmp params: module: [if_mib] static_configs: - targets: - 127.0.0.1 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 127.0.0.1:9116 # URL as shown on the UI


I tried to do snmp walk to troubleshout with command (snmpwalk -v2c -c public x.x.x.x) the x.x.x.x represent switch ip. but it gives me time out error.

then I figure out the switches which gives error has snmp community string set up. so I tried to run snmpwalk again replacing default public communit string with the community string set on this switches and I was able to snmpwalk on these swathes.

my question is, how can I make the Prometheus scrape from these remaining switches, is there any setting am missing to facilitate that?

please help.

Brian Candler

unread,
Mar 1, 2022, 2:57:45 AM3/1/22
to Prometheus Users
Aside: curl is useful for debugging:

However in your case, you've found the problem: you need to set a community string.

Unfortunately, snmp_exporter makes it hard to set this, because the MIB and the device authentication are bundled together in the "module".Ā  Here's the easiest way I've found to do this:

1. Edit snmp.yml (that was supplied with snmp_exporter, or that you generated)

2. Find the MIB that you're interested in using: in this case if_mib.Ā  Modify the first line like this:

if_mib:

becomes

if_mib: &if_mib

(this is called an "anchor" in YAML)

3. Add to the very *end* of the file:

if_mib_secret:
Ā  <<: *if_mib
Ā  version: 2
Ā  auth:
Ā  Ā  community: BlahBlah123


What you're doing is taking a copy of the "if_mib" section, and then overriding some of the parameters (the 'auth' and 'version' keys) without changing anything else.

[Aside: you should be able to do steps 1-3 using the snmp generator instead, but you'll have to duplicate the if_mib section in generator.yml instead, and then run the generator]

4. Restart snmp_exporter, and check this works using curl:


5. Change your scrape job for these devices to use module if_mib_secret instead of if_mib.

Oddly, your scrape job shows a static target of only 127.0.0.1, i.e. it looks like you're sending queries to the snmpd running on prometheus itself, not to any remote devices.Ā  I would suggest that you use the file_sd mechanism, and also that you pick up the module from this, so that a single scrape job can handle any combination of targets and SNMP modules.

Ā  - job_name: snmp
Ā  Ā  metrics_path: /snmp
Ā  Ā  file_sd_configs:
Ā  Ā  Ā  - files:
Ā  Ā  Ā  Ā  Ā  - /etc/prometheus/targets.d/snmp_targets.yml
Ā  Ā  relabel_configs:
Ā  Ā  Ā  - source_labels: [__address__]
Ā  Ā  Ā  Ā  target_label: instance

Ā  Ā  Ā  - source_labels: [__address__]
Ā  Ā  Ā  Ā  target_label: __param_target
Ā  Ā  Ā  - source_labels: [module]
Ā  Ā  Ā  Ā  target_label: __param_module
Ā  Ā  Ā  - target_label: __address__
Ā  Ā  Ā  Ā  replacement: 127.0.0.1:9116 Ā # SNMP exporter


then in snmp_targets.yml you can put:

- labels:
Ā  Ā  module: if_mib
Ā  targets:
Ā  Ā  - foo
Ā  Ā  - bar
- labels:
Ā  Ā  module: if_mib_secret
Ā  targets:
Ā  Ā  - baz
Ā  Ā  - qux



Hemedi Salim

unread,
Mar 1, 2022, 10:58:48 AM3/1/22
to Brian Candler, Prometheus Users
HiĀ 

Thanks for the reply.
I follow the steps as you showed me, but problem still exist. I run the command to debug (curl -g `http://127.0.0.1:9116/snmp?module=if_mib&target=x.x.x.x&debug=true`) and it give me request timeout error:

error collecting metric Desc{fqName: "snmp_error", help: "Error scraping target", constLabels: {}, variableLabels: []}: error getting target x.x.x.x: request timeout (after 3 retries)

and the on the prometheus targetĀ shows:
image.png


just few questions:

do those changes have to be done in snmp generator ? and then generate a snmp.yml? or it can be added straight away in snmp.yml?

What should I need to add, if for exampleĀ the switch snmp version is V3?

Is it possible to have more than one string for snmp authentication in snmp.yml?


Thanks


--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/aa9f124e-e927-4ad6-91c5-e261d3c52312n%40googlegroups.com.

Hemedi Salim

unread,
Mar 1, 2022, 11:14:16 AM3/1/22
to Brian Candler, Prometheus Users
also, if I edit generator.ymlĀ  please which part exactly on generator.yml need to be duplicated?Ā Ā 

generator.yml

modules:
Ā  # Default IF-MIB interfaces table with ifIndex.
Ā  if_mib:
Ā  Ā  walk: [sysUpTime, interfaces, ifXTable]
Ā  Ā  version: 2Ā  # SNMP version to use. Defaults to 2.
Ā  Ā  auth:
Ā  Ā  Ā  # Community string is used with SNMP v1 and v2. Defaults to "public".
Ā  Ā  Ā  community: aspire-lan
Ā  Ā  lookups:
Ā  Ā  Ā  - source_indexes: [ifIndex]
Ā  Ā  Ā  Ā  lookup: ifAlias
Ā  Ā  Ā  - source_indexes: [ifIndex]
Ā  Ā  Ā  Ā  # Uis OID to avoid conflict with PaloAlto PAN-COMMON-MIB.
Ā  Ā  Ā  Ā  lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr
Ā  Ā  Ā  - source_indexes: [ifIndex]
Ā  Ā  Ā  Ā  # Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
Ā  Ā  Ā  Ā  lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
Ā  Ā  overrides:
Ā  Ā  Ā  ifAlias:
Ā  Ā  Ā  Ā  ignore: true # Lookup metric
Ā  Ā  Ā  ifDescr:
Ā  Ā  Ā  Ā  ignore: true # Lookup metric
Ā  Ā  Ā  ifName:
Ā  Ā  Ā  Ā  ignore: true # Lookup metric
Ā  Ā  Ā  ifType:
Ā  Ā  Ā  Ā  type: EnumAsInfo

# Cisco Wireless LAN Controller
Ā  cisco_wlc:
Ā  Ā  walk:
Ā  Ā  Ā  - interfaces
Ā  Ā  Ā  - ifXTable
Ā  Ā  Ā  - 1.3.6.1.4.1.14179.2.1.1.1.38Ā  Ā # bsnDot11EssNumberofMobileStations
Ā  Ā  Ā  - 1.3.6.1.4.1.14179.2.2.2.1.2Ā  Ā  # bsnAPIfType
Ā  Ā  Ā  - 1.3.6.1.4.1.14179.2.2.2.1.4Ā  Ā  # bsnAPIfPhyChannelNumber
Ā  Ā  Ā  - 1.3.6.1.4.1.14179.2.2.2.1.15Ā  Ā # bsnApIfNoOfUsers
Ā  Ā  Ā  - 1.3.6.1.4.1.14179.2.2.6.1Ā  Ā  Ā  # bsnAPIfDot11CountersTable
Ā  Ā  Ā  - 1.3.6.1.4.1.14179.2.2.13.1.3Ā  Ā # bsnAPIfLoadChannelUtilization
Ā  Ā  Ā  - 1.3.6.1.4.1.14179.2.2.15.1.21Ā  # bsnAPIfDBNoisePower
Ā  Ā  lookups:
Ā  Ā  Ā  - source_indexes: [bsnDot11EssIndex]
Ā  Ā  Ā  Ā  lookup: bsnDot11EssSsid
Ā  Ā  Ā  Ā  drop_source_indexes: true
Ā  Ā  Ā  - source_indexes: [bsnAPDot3MacAddress]
Ā  Ā  Ā  Ā  lookup: bsnAPName
Ā  Ā  Ā  Ā  drop_source_indexes: true
Ā  Ā  overrides:
Ā  Ā  Ā  ifType:
Ā  Ā  Ā  Ā  type: EnumAsInfo

# APC/Schneider UPS Network Management Cards

....................
.................
..............

Brian Candler

unread,
Mar 1, 2022, 11:27:34 AM3/1/22
to Prometheus Users
On Tuesday, 1 March 2022 at 15:58:48 UTC hemj...@gmail.com wrote:
just few questions:

do those changes have to be done in snmp generator ? and then generate a snmp.yml? or it can be added straight away in snmp.yml?


I apply them straight away to snmp.yml
Ā 
What should I need to add, if for exampleĀ the switch snmp version is V3?

Example:

if_mib3:
Ā  <<: *if_mib
Ā  version: 3
Ā  auth:
Ā  Ā  security_level: authPriv
Ā  Ā  username: bla
Ā  Ā  auth_protocol: SHA
Ā  Ā  password: blabla
Ā  Ā  priv_protocol: AES
Ā  Ā  priv_password: blablabla


Ā 
Is it possible to have more than one string for snmp authentication in snmp.yml?


Yes, but you need to instantiate a separate module for each one:

if_mib_foo:
Ā  <<: *if_mib
Ā  version: 2
Ā  auth:
Ā  Ā  community: tcpip123


if_mib_bar:
Ā  <<: *if_mib
Ā  version: 2
Ā  auth:
Ā  Ā  community: xyzzy


...etc

Brian Candler

unread,
Mar 1, 2022, 11:33:07 AM3/1/22
to Prometheus Users
On Tuesday, 1 March 2022 at 16:14:16 UTC hemj...@gmail.com wrote:
also, if I edit generator.ymlĀ  please which part exactly on generator.yml need to be duplicated?Ā Ā 

Every module that you want to apply a different community string to.Ā  e.g.
There you've put already changed the community to "aspire-lan".Ā  If you want to run with another community as well, then either duplicate the *whole* section as if_mib_foo, with everything identical except the auth section; or use the YAML trick I showed before, like this.

modules:
Ā  # Default IF-MIB interfaces table with ifIndex.
Ā  if_mib: &if_mib
Ā  Ā  walk: [sysUpTime, interfaces, ifXTable]
Ā  Ā  version: 2Ā  # SNMP version to use. Defaults to 2.
Ā  Ā  auth:
Ā  Ā  Ā  # Community string is used with SNMP v1 and v2. Defaults to "public".
Ā  Ā  Ā  community: aspire-lan
Ā  Ā  lookups:
Ā  Ā  Ā  - source_indexes: [ifIndex]
Ā  Ā  Ā  Ā  lookup: ifAlias
Ā  Ā  Ā  - source_indexes: [ifIndex]
Ā  Ā  Ā  Ā  # Uis OID to avoid conflict with PaloAlto PAN-COMMON-MIB.
Ā  Ā  Ā  Ā  lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr
Ā  Ā  Ā  - source_indexes: [ifIndex]
Ā  Ā  Ā  Ā  # Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
Ā  Ā  Ā  Ā  lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
Ā  Ā  overrides:
Ā  Ā  Ā  ifAlias:
Ā  Ā  Ā  Ā  ignore: true # Lookup metric
Ā  Ā  Ā  ifDescr:
Ā  Ā  Ā  Ā  ignore: true # Lookup metric
Ā  Ā  Ā  ifName:
Ā  Ā  Ā  Ā  ignore: true # Lookup metric
Ā  Ā  Ā  ifType:
Ā  Ā  Ā  Ā  type: EnumAsInfo

...

if_mib_foo:

Ā  <<: *if_mib
Ā  version: 2
Ā  auth:
Ā  Ā  community: BlahBlah123


You'll have to repeat this as many times as you have different community strings.Ā  And if you want multiple auths for for cisco_wlc, then you'll need to do the same for that as well.

Re-run the generator, of course, with this new input.

Hemedi Salim

unread,
Mar 3, 2022, 11:47:51 AM3/3/22
to Brian Candler, Prometheus Users
Thanks very much Brian. got it workingĀ šŸ‘

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages