Skip to content

Commit 5738b84

Browse files
committed
Add SNMP generator image
1 parent 166b51f commit 5738b84

File tree

5 files changed

+227
-0
lines changed

5 files changed

+227
-0
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
prometheus/node-exporter: 'prometheus/node-exporter/**'
7979
prometheus/prometheus: 'prometheus/prometheus/**'
8080
prometheus/snmp-exporter: 'prometheus/snmp-exporter/**'
81+
prometheus/snmp-generator: 'prometheus/snmp-generator/**'
8182
pspace: 'pspace/**'
8283
pulumi/pulumi-base: 'pulumi/pulumi-base/**'
8384
pulumi/pulumi-python: 'pulumi/pulumi-python/**'
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# syntax=docker/dockerfile:1
2+
ARG BASE_IMAGE=docker.io/boxcutter/golang:1.24-noble
3+
# hadolint ignore=DL3006
4+
FROM $BASE_IMAGE AS base
5+
6+
FROM base AS build
7+
8+
ARG SNMP_EXPORTER_SOURCE_URL
9+
ARG PEPLINK_SNMP_MIBS_URL
10+
11+
WORKDIR /usr/src/snmp_exporter
12+
13+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
14+
RUN <<EOF
15+
apt-get update
16+
apt-get install -y --no-install-recommends \
17+
ca-certificates \
18+
curl \
19+
libsnmp-dev \
20+
unzip \
21+
libarchive-tools
22+
mkdir -p /tmp/snmp_exporter
23+
curl -fsSL -o /tmp/snmp_exporter.tar.gz "${SNMP_EXPORTER_SOURCE_URL}"
24+
tar xvf /tmp/snmp_exporter.tar.gz -C /usr/src/snmp_exporter --strip-components 1
25+
rm -rf /var/lib/apt/lists/*
26+
EOF
27+
28+
WORKDIR /usr/src/snmp_exporter/generator
29+
30+
# "make mibs" frequently breaks, so just include the ones we know that work
31+
SHELL ["/bin/bash", "-o", "pipefail", "-e", "-c"]
32+
RUN <<EOF
33+
make generator
34+
# broken 2025-06-18
35+
# make mibs/apc-powernet-mib
36+
make mibs/readynas
37+
make mibs/readydataos
38+
make mibs/AIRESPACE-REF-MIB
39+
make mibs/AIRESPACE-WIRELESS-MIB
40+
make mibs/ARISTA-ENTITY-SENSOR-MIB
41+
make mibs/ARISTA-SMI-MIB
42+
make mibs/ARISTA-SW-IP-FORWARDING-MIB
43+
make mibs/iDRAC-SMIv2.mib
44+
make mibs/.hpe-mib
45+
make mibs/IANA-CHARSET-MIB.txt
46+
make mibs/IANA-IFTYPE-MIB.txt
47+
make mibs/IANA-PRINTER-MIB.txt
48+
make mibs/FServer-Std.MIB
49+
make mibs/KEEPALIVED-MIB
50+
make mibs/VRRP-MIB
51+
make mibs/VRRPv3-MIB
52+
make mibs/.kemp-lm
53+
make mibs/MIKROTIK-MIB
54+
make mibs/.net-snmp
55+
make mibs/.paloalto_panos
56+
make mibs/PICO-IPSEC-FLOW-MONITOR-MIB.txt
57+
make mibs/PICO-SMI-ID-MIB.txt
58+
make mibs/PICO-SMI-MIB.txt
59+
make mibs/PRINTER-MIB-V2.txt
60+
make mibs/servertech-sentry3-mib
61+
make mibs/servertech-sentry4-mib
62+
make mibs/.synology
63+
make mibs/.sophos_xg
64+
make mibs/.tplinkddm
65+
make mibs/UBNT-UniFi-MIB
66+
make mibs/UBNT-AirFiber-MIB
67+
make mibs/UBNT-AirMAX-MIB.txt
68+
make mibs/PDU-MIB.txt
69+
make mibs/PDU2-MIB.txt
70+
make mibs/Infrapower-MIB.mib
71+
make mibs/LIEBERT_GP_PDU.MIB
72+
make mibs/CyberPower.MIB
73+
make mibs/EAP.MIB
74+
make mibs/EAP-Client.MIB
75+
make mibs/powercom
76+
make mibs/.cisco_imc
77+
make mibs/.cisco-device
78+
make mibs/FROGFOOT-RESOURCES-MIB
79+
make mibs/.dlink-mibs
80+
# Broken 2025-06-15
81+
# make mibs/.eltex-mes
82+
make mibs/.juniper
83+
make mibs/.dell-network
84+
make mibs/.yamaha-rt
85+
EOF
86+
87+
WORKDIR /opt/snmp_generator/mibs/peplink
88+
89+
RUN <<EOF
90+
curl -fsSL -o /tmp/peplink-snmp-mibs.zip "${PEPLINK_SNMP_MIBS_URL}"
91+
bsdtar -xf /tmp/peplink-snmp-mibs.zip --strip-components=1 -C /opt/snmp_generator/mibs/peplink
92+
EOF
93+
94+
FROM base
95+
96+
COPY --chmod=755 --from=build /usr/src/snmp_exporter/generator/generator /bin/generator
97+
COPY --from=build /usr/src/snmp_exporter/generator/mibs /opt/snmp_exporter/generator/mibs
98+
COPY --from=build /opt/snmp_generator/mibs/peplink /opt/snmp_exporter/generator/peplink
99+
100+
RUN <<EOF
101+
apt-get update
102+
apt-get install -y --no-install-recommends \
103+
ca-certificates \
104+
curl \
105+
libsnmp-dev \
106+
unzip
107+
rm -rf /var/lib/apt/lists/*
108+
EOF
109+
110+
WORKDIR /code
111+
112+
ENTRYPOINT ["/bin/generator"]
113+
ENV MIBDIRS=mibs

prometheus/snmp-generator/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# snmp-generator
2+
3+
This image packages the SNMP Exporter Config Generator tool from https://github.com/prometheus/snmp_exporter/tree/main/generator
4+
It runs `/usr/bin/generator` by default.
5+
6+
All the default MIBs produced by the `make mibs` command are available
7+
in the `/opt/snmp_exporter/generator/mibs` directory.
8+
9+
Peplink SNMP MIBs are available in the following directories:
10+
- `/opt/snmp_exporter/generator/peplink/peplink`
11+
- `/opt/snmp_exporter/generator/peplink/pepwave`
12+
- `/opt/snmp_exporter/generator/peplink/pepxim`
13+
14+
To generate an `snmp.yml` for the Prometheus SNMP exporter, pass in the
15+
directors of mibs, a path to a `generator.yml` file and the path to the
16+
output `snmp.yml`:
17+
18+
```bash
19+
docker run -it --rm \
20+
--mount type=bind,source="$(pwd)",target=/code \
21+
docker.io/polymathrobotics/snmp-generator \
22+
-m /opt/snmp_exporter/generator/mibs \
23+
-m /opt/snmp_exporter/generator/peplink/peplink \
24+
-g generator.yml \
25+
-o snmp.yml
26+
```
27+
28+
For more information on the `generator.yml` file format, refer to
29+
https://github.com/prometheus/snmp_exporter/blob/main/generator/FORMAT.md
30+
31+
## CLI
32+
33+
```bash
34+
% docker run -it --rm docker.io/polymathrobotics/rsnmp-generator -h
35+
usage: generator [<flags>] <command> [<args> ...]
36+
37+
38+
Flags:
39+
-h, --[no-]help Show context-sensitive help (also try --help-long and
40+
--help-man).
41+
--[no-]fail-on-parse-errors
42+
Exit with a non-zero status if there are MIB parsing
43+
errors
44+
--snmp.mibopts="eu" Toggle various defaults controlling MIB parsing,
45+
see snmpwalk --help
46+
-m, --mibs-dir= ... Paths to mibs directory
47+
--log.level=info Only log messages with the given severity or above.
48+
One of: [debug, info, warn, error]
49+
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
50+
51+
Commands:
52+
help [<command>...]
53+
Show help.
54+
55+
generate [<flags>]
56+
Generate snmp.yml from generator.yml
57+
58+
parse_errors
59+
Debug: Print the parse errors output by NetSNMP
60+
61+
dump
62+
Debug: Dump the parsed and prepared MIBs
63+
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
variable "TAG_PREFIX" {
2+
default = "docker.io/polymathrobotics/snmp-generator"
3+
}
4+
5+
variable "VERSION" {
6+
default = "0.29.0"
7+
}
8+
9+
# There's no darwin-based Docker, so if we're running on macOS, change the platform to linux
10+
variable "LOCAL_PLATFORM" {
11+
default = regex_replace("${BAKE_LOCAL_PLATFORM}", "^(darwin)", "linux")
12+
}
13+
14+
target "_common" {
15+
dockerfile = "Containerfile"
16+
args = {
17+
SNMP_EXPORTER_SOURCE_URL = "https://github.com/prometheus/snmp_exporter/archive/refs/tags/v0.29.0.tar.gz"
18+
PEPLINK_SNMP_MIBS_URL = "https://download.peplink.com/resources/peplink_pepwave_snmp_mib-2024-07.zip"
19+
}
20+
tags = [
21+
"${TAG_PREFIX}:${VERSION}",
22+
"${TAG_PREFIX}:latest"
23+
]
24+
labels = {
25+
"org.opencontainers.image.source" = "https://github.com/polymathrobotics/oci"
26+
"org.opencontainers.image.licenses" = "Apache-2.0"
27+
"org.opencontainers.image.description" = "Prometheus SNMP generator"
28+
"org.opencontainers.image.title" = "${TAG_PREFIX}"
29+
"org.opencontainers.image.created" = "${timestamp()}"
30+
"dev.polymathrobotics.image.readme-filepath" = "prometheus/snmp-generator/README.md"
31+
}
32+
}
33+
34+
target "local" {
35+
inherits = ["_common"]
36+
platforms = ["${LOCAL_PLATFORM}"]
37+
}
38+
39+
target "default" {
40+
inherits = ["_common"]
41+
platforms = ["linux/amd64", "linux/arm64/v8"]
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
describe command('generator') do
2+
it { should exist }
3+
end
4+
5+
describe command('generator -h') do
6+
its('exit_status') { should eq 0 }
7+
its('stderr') { should match(/usage: generator/) }
8+
end

0 commit comments

Comments
 (0)