snmp_exporter: add a pkg-readme with a quick intro, and show how to run the

config generator (including setting MIBDIRS) when changing the generator
input file. add an example showing use with OPENBSD-PF-MIB (which just had
a commit in src/ that will prevent snmp_exporter from using a hexdump of
various names, so if someone is trying this right now they should pick up
the updated MIB first).

Parts borrowed from https://yetiops.net/posts/openbsd-snmp-exporter/
This commit is contained in:
sthen 2021-03-23 19:42:28 +00:00
parent b4f51aa50b
commit d0ab2b2cfd
5 changed files with 115 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.12 2021/03/08 21:04:59 sthen Exp $
# $OpenBSD: Makefile,v 1.13 2021/03/23 19:42:28 sthen Exp $
COMMENT= Prometheus exporter for SNMP metrics
@ -6,6 +6,7 @@ COMMENT= Prometheus exporter for SNMP metrics
# "make mibs", update M version, "make makesum".
V= 0.20.0
M= 0.20.0
REVISION= 0
GH_ACCOUNT= prometheus
GH_PROJECT= snmp_exporter
GH_TAGNAME= v$V
@ -48,7 +49,7 @@ do-install:
${INSTALL_DATA} ${WRKSRC}/{LICENSE,README.md} \
${PREFIX}/share/doc/snmp_exporter/
${INSTALL_DATA} ${WRKSRC}/{snmp,generator/generator}.yml \
${PREFIX}/share/examples/snmp_exporter/
${FILESDIR}/generator-pf.yml ${PREFIX}/share/examples/snmp_exporter/
cp -r ${WRKSRC}/generator/mibs \
${PREFIX}/share/examples/snmp_exporter/
find ${PREFIX}/share/examples/snmp_exporter/mibs -name '*.md5' -delete

View File

@ -0,0 +1,59 @@
# $OpenBSD: generator-pf.yml,v 1.1 2021/03/23 19:42:28 sthen Exp $
# Cut-down example of if_mib setup done using SNMPv3 (edit the various
# $snmpv3-... as needed) and information from OPENBSD-PF-MIB, based on
# https://yetiops.net/posts/openbsd-snmp-exporter/.
modules:
if_mib:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- source_indexes: [ifIndex]
lookup: ifAlias
- source_indexes: [ifIndex]
lookup: ifDescr
- source_indexes: [ifIndex]
lookup: ifName
overrides:
ifAlias:
ignore: true # Lookup metric
ifDescr:
ignore: true # Lookup metric
ifName:
ignore: true # Lookup metric
ifType:
type: EnumAsInfo
version: 3
auth:
username: "$snmpv3-user"
security_level: authPriv
password: "$snmpv3-authkey"
auth_protocol: SHA
priv_protocol: AES
priv_password: "$snmpv3-enckey"
openbsd_pf:
walk:
- pfRunning
- pfRuntime
- pfDebug
- pfHostid
- pfStateCount
- pfStateSearches
- pfStateInserts
- pfStateRemovals
- pfIfTable
- pfIfDescr
- pfIfType
- pfIfIndex
lookups:
- source_indexes: [pfIfIndex]
lookup: pfIfDescr
drop_source_indexes: false
version: 3
auth:
username: "$snmpv3-user"
security_level: authPriv
password: "$snmpv3-authkey"
auth_protocol: SHA
priv_protocol: AES
priv_password: "$snmpv3-enckey"

View File

@ -1,7 +1,5 @@
Prometheus exporter for metrics gathered from SNMP. Contains an exporter
that does the actual scraping, and a generator (which depends on Net-SNMP)
that creates the configuration for use by the exporter.
Prometheus exporter for metrics gathered from SNMP.
The snmp exporter reads from a snmp.yml config file by default. This file
is not intended to be written by hand, rather use the generator to generate
it for you.
This package contains both the exporter that does the actual scraping,
and a generator (which depends on Net-SNMP) that creates the
configuration for use by the exporter.

View File

@ -1,9 +1,10 @@
@comment $OpenBSD: PLIST,v 1.5 2021/03/08 21:04:59 sthen Exp $
@comment $OpenBSD: PLIST,v 1.6 2021/03/23 19:42:28 sthen Exp $
@newgroup _snmpexporter:845
@newuser _snmpexporter:845:_snmpexporter:daemon:prometheus snmp_exporter:/nonexistent:/sbin/nologin
@rcscript ${RCDIR}/snmp_exporter
@bin bin/snmp_exporter
@bin bin/snmp_generator
share/doc/pkg-readmes/${PKGSTEM}
share/doc/snmp_exporter/
share/doc/snmp_exporter/LICENSE
share/doc/snmp_exporter/README.md
@ -15,6 +16,7 @@ share/examples/snmp_exporter/
@mode
@owner
@group
share/examples/snmp_exporter/generator-pf.yml
share/examples/snmp_exporter/generator.yml
@sample ${SYSCONFDIR}/snmp_exporter/generator.yml
share/examples/snmp_exporter/mibs/

View File

@ -0,0 +1,46 @@
$OpenBSD: README,v 1.1 2021/03/23 19:42:28 sthen Exp $
+-------------------------------------------------------------------------------
| Running ${PKGSTEM} on OpenBSD
+-------------------------------------------------------------------------------
snmp_exporter runs as a daemon and performs SNMP queries in response to
incoming requests on its HTTP port. It would normally be queried by Prometheus
which passes parameters specifying which host it should poll and which mib to
use.
snmp_exporter's own configuration provides definitions for mibs with
OID-to-name mappings, and can include SNMP authentication information.
The "runtime" configuration in ${SYSCONFDIR}/snmp_exporter/snmp.yml is intended
to be generated by a tool (name "snmp_generator" in this package) from
a higher-level configuration file ${SYSCONFDIR}/snmp_exporter/generator.yml.
The generator uses this in conjunction with MIB files (read in via Net-SNMP)
to produce snmp.yml.
The default configuration can be used directly for some simple uses (for
example, polling interface stats with default authentication values).
For more complex cases and less-common MIBs you will need to adapt or
write your own generator.yml and generate a new snmp.yml from it.
The MIB files required for snmp_exporter's sample configuration are included
in this package (in ${TRUEPREFIX}/share/examples/snmp_exporter/mibs).
Additional MIBs may be needed if you're adding less common devices;
the LibreNMS package provides a collection of thousands of these covering
many network devices in /var/www/librenms/mibs.
Some OpenBSD-specific MIBs for use with snmpd(8) are provided in
/usr/share/snmp/mibs.
You will need to provide a suitable MIB search path allowing the generator
to find any MIB files referenced in your configuration; this can be set
in the environment variable MIBDIRS.
An example of adapting and building config:
# cd ${SYSCONFDIR}/snmp_exporter
# cp ${TRUEPREFIX}/share/examples/snmp_exporter/generator-pf.yml generator.yml
# vi ${SYSCONFDIR}/snmp_exporter/generator.yml
[...]
# export MIBDIRS=/usr/share/snmp/mibs:${LOCALBASE}/share/snmp/mibs:${TRUEPREFIX}/share/examples/snmp_exporter/mibs
# snmp_generator generate