prometheus / snmp_exporter

SNMP Exporter for Prometheus
Apache License 2.0
1.65k stars 614 forks source link

When using `make docker-generate` get "Error generating config netsnmp" #1048

Closed jvillal-amp closed 9 months ago

jvillal-amp commented 9 months ago

Error seen is:

$ make docker-generate
docker build -t "prom/snmp-generator:main" .
<snip>
ts=2023-11-17T19:37:13.416Z caller=net_snmp.go:162 level=info msg="Loading MIBs" from=mibs
ts=2023-11-17T19:37:13.610Z caller=main.go:132 level=error msg="Error generating config netsnmp" err="error parsing yml config: yaml: unmarshal errors:\n  line 159: field scale not found in type main.plain\n  line 583: field scale not found in type main.plain\n  line 584: field offset not found in type main.plain"
make: *** [Makefile:86: docker-generate] Error 1

Using:

commit aec1630028c7e3bfe27a6187aa9623adde133372 (HEAD -> refs/heads/main, refs/remotes/origin/main, refs/remotes/origin/HEAD)
Author: Ben Kochie <superq@gmail.com>
Date:   Tue Nov 14 04:37:24 2023 -0600

    Refactor HOST-RESOURCES-MIB (#1027)
hhromic commented 9 months ago

See #1045 , the problem is that the main Docker image tag is built with a generator binary using the latest tagged release in the repository, and not a binary using the latest state/commit of the main branch.

The error you see is because the generator.yml file in main requires a recent feature not yet in a tagged release.

If you want to try a quick local fix, edit the generator/Dockerfile file and change @latest to @main. Afterwards, running make docker-generate should work as expected.

hhromic commented 9 months ago

Now that #1045 was merged, this should work as expected:

$ git clone git@github.com:prometheus/snmp_exporter.git
Cloning into 'snmp_exporter'...
remote: Enumerating objects: 7644, done.
remote: Counting objects: 100% (1680/1680), done.
remote: Compressing objects: 100% (462/462), done.
remote: Total 7644 (delta 1303), reused 1328 (delta 1192), pack-reused 5964
Receiving objects: 100% (7644/7644), 9.55 MiB | 8.07 MiB/s, done.
Resolving deltas: 100% (4297/4297), done.

$ cd snmp_exporter/generator/
$ make docker-generate
docker build --build-arg REPO_TAG="main" -t "prom/snmp-generator:main" .
(...)
>> Downloading apc-powernet-mib
# Workaround to make DisplayString available (#867)
>> Downloading Cisco AIRESPACE-REF-MIB
>> Downloading Cisco AIRESPACE-WIRELESS-MIB
>> Downloading ARISTA-ENTITY-SENSOR-MIB
(...)
docker run -ti -v "/home/hromic/temp/snmp_exporter/generator:/opt/" "prom/snmp-generator:main" generate
ts=2023-11-21T10:57:58.161Z caller=net_snmp.go:175 level=info msg="Loading MIBs" from=mibs
ts=2023-11-21T10:57:58.343Z caller=main.go:53 level=info msg="Generating config for module" module=ubiquiti_airmax
ts=2023-11-21T10:57:58.359Z caller=main.go:68 level=info msg="Generated metrics" module=ubiquiti_airmax metrics=79
ts=2023-11-21T10:57:58.359Z caller=main.go:53 level=info msg="Generating config for module" module=keepalived
ts=2023-11-21T10:57:58.400Z caller=main.go:68 level=info msg="Generated metrics" module=keepalived metrics=187
(...)
ts=2023-11-21T10:58:14.737Z caller=main.go:93 level=info msg="Config written" file=/opt/snmp.yml
JohnVillalovos commented 9 months ago

Thanks. I will test this when I get back from vacation next week.

jvillal-amp commented 9 months ago

I have tested it this morning.

I am getting the following error now:

ts=2023-11-27T15:48:48.150Z caller=net_snmp.go:175 level=info msg="Loading MIBs" from=mibs
ts=2023-11-27T15:48:48.150Z caller=main.go:134 level=error msg="Error generating config netsnmp" err="unable to determine absolute path for output"
make: *** [Makefile:92: docker-generate] Error 1

Not sure if I should open a new issue or not.

Current tip is:

commit d404ca54576558b2489504f50e309796f134d9d7 (HEAD -> refs/heads/main, refs/remotes/origin/main, refs/remotes/origin/HEAD)
Author: Nico <rey.nico@gmail.com>
Date:   Sat Nov 25 05:33:53 2023 -0300

    Add Netgear ReadyNAS and ReadyData appliances support (#1053)
<snip>
jvillal-amp commented 9 months ago

Never mind. I forgot to modify the Makefile to allow selinux to work. Once I did that then everything is working.

Thanks for the help @hhromic !!

jvillal-amp commented 9 months ago

@hhromic I created a PR to resolve my SELINUX issue. https://github.com/prometheus/snmp_exporter/pull/1054