0

We running Prometheus with SNMP Exporter to scrape SNMP targets. One target uses a large number of OctetStrings. What we'd like to achieve is overriding the OctetStrings to DisplayStrings and then using regex to retrieve the label as the metric.

The MIB looks as follows: The MIB file

For now we'll only focus on cfgProductName, cfgSoftwareVersion and cfgMIBVersion.

  • For cfgProductName we'll add overrides for the type from OctetString to DisplayString and a regex to return the label value of cfgProductName as the metric. The regex we used is adapted from the Grafana regex use here and tested on regex101. We confirmed that the regex yields the result we're after.
  • For cfgSoftwareVersion we'll add overrides for the type from OctetString to DisplayString and a simple regex just to test that the regex is doing something.
  • For cfgMIBVersion we just change type from OctetString to DisplayString with no regex.

Our generator.yml file looks as follows: The generator.yml file

The resulting SNMP.yml looks as follows: The SNMP.yml file

We use the resulting SNMP.yml in the SNMP Exporter to scrape the target.

The results are as follows:

  • For cfgProductName, Prometheus allows autocomplete of the search string indicating that the scrape is in the DB, but returns an empty query result.
  • For cfgSoftwareVersion, Prometheus doesn't allow autocomplete of the search string, suggesting that no scrape was performed.
  • For cfgMIBVersion, the OctetString is changed to a DisplayString as we expected and Prometheus returns a result.cfgMIBVersion query result

We were expecting to see e.g. cfgProductNameValue with a metric equal to the result of the regex. Any suggestions on where we're going wrong?

  • Welcome to SO. Although you described your problem very detailed which is good, have a look at [how to ask](https://stackoverflow.com/help/how-to-ask). It is hard to read when you have to follow links and pictures here and there. Try to post all the necessary informations and the content of your links as text or code or embed the picture at least directly in the question. – Rabinzel Apr 22 '22 at 18:02
  • Thanks for the feedback. I'm not allowed to embed pictures until I reach 10 reputation points but next time I'll embed the code snippets :-) – WernerNL Apr 23 '22 at 08:11
  • The way to solve this problem is to skip the regex_extract sections and to to check, what the exporter really returns (e.g.the output of something like `curl -s 'http://localhost:9116/snmp?compact&module=test&target=myDeviceIPorFQDN'`). – jelmd Aug 07 '22 at 05:32

0 Answers0