SNMP Generator
Installation
The generator is already installed. It came with the SNMP exporter. But if you have a device that supplies it’s own MIB (and many do), you should add that to the default location.
# Mibs are often named SOMETHING-MIB.txt
sudo cp -n *MIB.txt /usr/share/snmp/mibs/
Preparation
You must identify the values you want to capture. Using snmpwalk is a good way to see what’s available, but it helps to have a little context.
The data is arranged like a folder structure that you drill-down though. The folder names are all numeric, with ‘.’ instead of slashes. So if you wanted to get a device’s sysName you’d click down through 1.3.6.1.2.1.1.5 and look in the file 0.
snmpwalk -v2c -c public 10.10.202.246 1.3.6.1.2.1.1.5
SNMPv2-MIB::sysName.0 = STRING: RickeySelby131
Why did sysName get put there? A bunch of folks got together (the ISO folks) and decided everything in advance. Since trying to remember all those numbers is a bit painful, they made some handy files (MIBs) and passed them out so you can jump right to what you want.
snmpwalk -v2c -c public 10.10.202.246 sysName.0
SNMPv2-MIB::sysName.0 = STRING: RickeySelby131
They allow vendors to create their own sections as well, for things that might not fit anywhere else.
A good place to start is looking at what the vendor made available. You see this by “walking” their section (descending down through all the folders from a starting point).
You’ll get descriptive names as long as you already coped their MIB and enabled all in the snmp.conf file. If not, you can put it in your working directory and include it at the command line.
# The SysobjectID identifies the vendor section
# Note use of the MIB name without the .txt
$ snmpwalk -m +SOMEVENDOR-MIB -v 2c -c public some.address SysobjectID
SNMPv2-MIB::sysObjectID.0 = OID: SOMEVENDOR-MIB::somevendoramerica
# Then walk the vendor section using the name from above
$ snmpwalk -m +SOMEVENDOR-MIB -v 2c -c some.address somevendoramerica
SOMEVENDOR-MIB::model.0 = STRING: SOME-MODEL
SOMEVENDOR-MIB::power.0 = INTEGER: 0
...
...
# Also check out the general System section
$ snmpwalk -m +SOMEVENDOR-MIB -v 2c -c public some.address system
# You can also walk the whole ISO tree. In some cases,
# there are thousands of entries and it's indecipherable
$ snmpwalk -m +SOMEVENDOR-MIB -v 2c -c public some.system iso
This can be a lot of information and you’ll need to do some homework to see what data you want to collect.
Configuration
The exporter’s default configuration file is snmp.yml and contains about 57 Thousand lines of config. It’s designed to pull data from whatever you point it at. Basically, it doesn’t know what device it’s talking to, so it tries to cover all the bases.
This isn’t a file you should edit by hand. Instead, you create instructions for the generator and it look though the MIBs and create one for you. Here’s an example for a Samlex Invertor.
vim ~/generator.yml
modules:
samlex:
walk:
- sysLocation
- inverterMode
- power
- vin
- tempDD
- tempDA
Generate a new snmp.yml to replace the default.
prometheus-snmp-generator generate
sudo cp /etc/prometheus/snmp.yml /etc/prometheus/snmp.yml.orig
sudo cp ~/snmp.yml /etc/prometheus
sudo systemctl reload prometheus-snmp-exporter.service
Configuration in Prometheus remains the same - but since we picked a new module name we need to adjust that.
...
...
params:
module: [samlex]
...
...
sudo systemctl reload prometheus.service
Adding Data Prefixes
by default, the names are all over the place. The SNMP Exporter Devs leave it this way because there are a lot of pre-built dashboards on downstream systems that expect the existing names.
If you are building your own downstream systems you can prefix (as is best-practice) as you like with a post generation step. This example cases them all to be prefixed with samlex_.
prometheus-snmp-generator generate
sed -i 's/name: /name: samlex_/' snmp.yml
sudo cp ~/snmp.yml /etc/prometheus
sudo systemctl reload prometheus-snmp-exporter.service
Combining MIBs
You can combine multiple systems in the generator file to create one snmp.yml file, and refer to them by the module name in the Prometheus file.
modules:
samlex:
walk:
- sysLocation
- inverterMode
- power
- vin
- tempDD
- tempDA
ubiquiti:
walk:
- something
- somethingElse
Operation
As before, you can get a preview directly from the exporter (using a link like below). This data should show up in the Web UI too.
http://some.server:9116/snmp?module=samlex&target=some.device
Troubleshooting
SNMP Exporter
server returned HTTP status 400 Bad Request
If you see this error message in your http://some.server:9090/classic/targets, and:
Unknown auth ‘public_v2’
When you look directly at http://some.server:9116/snmp?module=samlex&target=a.ups.your.local
Then you may need to add an auth section to your file as in this posting.
sudo vi /etc/prometheus/snmp.yml
# Add this right at the top
auths:
public_v1:
version: 1
public_v2:
community: public
security_level: noAuthNoPriv
auth_protocol: MD5
priv_protocol: DES
version: 2
sudo systemctl restart prometheus-snmp-exporter.service
Possible version missmatch between generator and snmp_exporter. Make sure generator and snmp_exporter are the same version."
If you upgrade and the snmp exporter doesn’t start, you may see this in your log. It’s possible your snmp.yml files has old syntax. You can run the generate and cp commands to generate a current one.
level=ERROR source=main.go:137 msg=“Failing on reported parse error(s)”
You might have that operator syntax error as described in the exporter config. Double check that you can snmpwalk without error.
NetSNMP
If you’re running prometheus-snmp-generator generate and get the error:
NetSNMP reported parse error(s)
you must update a mib file. This is described in some detail but the short answer is to run this command;
sudo wget --output-document /usr/share/snmp/mibs/ietf/SNMPv2-PDU https://pastebin.com/raw/p3QyuXzZ
Sources
https://github.com/prometheus/snmp_exporter/tree/main/generator
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.