AthennaMind / opnsense-exporter

OPNsense Exporter for Prometheus
Apache License 2.0
92 stars 10 forks source link

[BUG] Failed to unmarshal response body on api/core/system/status #18

Closed tebrown closed 7 months ago

tebrown commented 7 months ago

Describe the bug

I am setting up a docker container to gather metrics from OpnSense, and it appears to connect ok, but fails to unmarshal the data.

Host operating system: output of uname -a

Linux truenas 6.1.74-production+truenas #2 SMP PREEMPT_DYNAMIC Wed Feb 21 20:30:38 UTC 2024 x86_64 GNU/Linux

Versions

- OPNsense version: 24.1.5_1
- OPNsense exporter version: 0.0.4
- Prometheus version: 2.51.1

Configuration of the exporter

Provide the configuration of the exporter in flags or in ENV variables. Hide the sensitive information.

--opnsense.protocol=http
--opnsense.address=192.168.10.1
--exporter.instance-label=test
--web.listen-address=:17012
--opnsense.insecure

ENV's for API_KEY and API_SECRET

Expected behavior

Data should unmarshal correctly.

Screenshots

2024-04-04 20:03:47.507886-04:00ts=2024-04-05T00:03:47.507Z caller=main.go:34 level=info msg="starting opnsense-exporter" version=v0.0.4
2024-04-04 20:03:47.514329-04:00ts=2024-04-05T00:03:47.514Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:17012
2024-04-04 20:03:47.514382-04:00ts=2024-04-05T00:03:47.514Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:17012
2024-04-04 20:04:12.045354-04:00http://192.168.10.1/api/core/system/status
2024-04-04 20:04:12.045475-04:00{"CrashReporter":{"statusCode":-1,"message":"An issue was detected and can be reviewed using the firmware crash reporter.","logLocation":"\/crash_reporter.php","timestamp":1712275450,"status":"Error","age":"2 seconds ago"},"Firewall":{"statusCode":2,"message":"No problems were detected.","logLocation":"\/ui\/diagnostics\/log\/core\/firewall","timestamp":"0","status":"OK"},"System":{"status":"Error"}}
2024-04-04 20:04:12.045385-04:00ts=2024-04-05T00:04:12.045Z caller=collector.go:169 level=error msg="failed to fetch system status" err="opnsense-client api call error: endpoint: api/core/system/status; failed status code: 200; msg: failed to unmarshal response body: json: cannot unmarshal number into Go struct field .CrashReporter.timestamp of type string"
2024-04-04 20:04:20.424316-04:00http://192.168.10.1/api/core/system/status
2024-04-04 20:04:20.424429-04:00{"CrashReporter":{"statusCode":-1,"message":"An issue was detected and can be reviewed using the firmware crash reporter.","logLocation":"\/crash_reporter.php","timestamp":1712275460,"status":"Error","age":"0 seconds ago"},"Firewall":{"statusCode":2,"message":"No problems were detected.","logLocation":"\/ui\/diagnostics\/log\/core\/firewall","timestamp":"0","status":"OK"},"System":{"status":"Error"}}
2024-04-04 20:04:20.424347-04:00ts=2024-04-05T00:04:20.424Z caller=collector.go:169 level=error msg="failed to fetch system status" err="opnsense-client api call error: endpoint: api/core/system/status; failed status code: 200; msg: failed to unmarshal response body: json: cannot unmarshal number into Go struct field .CrashReporter.timestamp of type string"
tebrown commented 7 months ago

Logs with debug enabled

2024-04-04 20:16:47.905611-04:00ts=2024-04-05T00:16:47.905Z caller=main.go:34 level=info msg="starting opnsense-exporter" version=v0.0.4
2024-04-04 20:16:47.905705-04:00ts=2024-04-05T00:16:47.905Z caller=main.go:39 level=debug msg="settings Go MAXPROCS" procs=2
2024-04-04 20:16:47.911720-04:00ts=2024-04-05T00:16:47.911Z caller=main.go:61 level=debug msg="OPNsense registered endpoints map[arp:api/diagnostics/interface/search_arp cronJobs:api/cron/settings/searchJobs dhcpv4:api/dhcpv4/leases/searchLease gatewaysStatus:api/routes/gateway/status healthCheck:api/core/system/status interfaces:api/diagnostics/traffic/interface openVPNInstances:api/openvpn/instances/search protocolStatistics:api/diagnostics/interface/getProtocolStatistics services:api/core/service/search systemInfo:widgets/api/get.php?load=system%2Ctemperature unboundDNSStatus:api/unbound/diagnostics/stats wireguardClients:api/wireguard/service/show]"
2024-04-04 20:16:47.911812-04:00ts=2024-04-05T00:16:47.911Z caller=arp_table.go:34 level=debug msg="Registering collector" collector=arp_table
2024-04-04 20:16:47.911850-04:00ts=2024-04-05T00:16:47.911Z caller=cron.go:31 level=debug msg="Registering collector" collector=cron
2024-04-04 20:16:47.912084-04:00ts=2024-04-05T00:16:47.911Z caller=interfaces.go:39 level=debug msg="Registering collector" collector=interfaces
2024-04-04 20:16:47.912104-04:00ts=2024-04-05T00:16:47.912Z caller=openvpn.go:32 level=debug msg="Registering collector" collector=openvpn
2024-04-04 20:16:47.912176-04:00ts=2024-04-05T00:16:47.912Z caller=protocol.go:46 level=debug msg="Registering collector" collector=protocol
2024-04-04 20:16:47.912363-04:00ts=2024-04-05T00:16:47.912Z caller=services.go:33 level=debug msg="Registering collector" collector=services
2024-04-04 20:16:47.912380-04:00ts=2024-04-05T00:16:47.912Z caller=unbound_dns.go:31 level=debug msg="Registering collector" collector=unbound_dns
2024-04-04 20:16:47.912391-04:00ts=2024-04-05T00:16:47.912Z caller=wireguard.go:35 level=debug msg="Registering collector" collector=wireguard
2024-04-04 20:16:47.912898-04:00ts=2024-04-05T00:16:47.912Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:17012
2024-04-04 20:16:47.912920-04:00ts=2024-04-05T00:16:47.912Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:17012
2024-04-04 20:17:22.041857-04:00ts=2024-04-05T00:17:22.040Z caller=client.go:144 level=debug msg="fetching data" component=opnsense-client url=http://192.168.10.1/api/core/system/status method=GET
2024-04-04 20:17:22.127534-04:00ts=2024-04-05T00:17:22.127Z caller=collector.go:169 level=error msg="failed to fetch system status" err="opnsense-client api call error: endpoint: api/core/system/status; failed status code: 200; msg: failed to unmarshal response body: json: cannot unmarshal number into Go struct field .CrashReporter.timestamp of type string"
2024-04-04 20:17:22.127537-04:00http://192.168.10.1/api/core/system/status
2024-04-04 20:17:22.127643-04:00{"CrashReporter":{"statusCode":-1,"message":"An issue was detected and can be reviewed using the firmware crash reporter.","logLocation":"\/crash_reporter.php","timestamp":1712276240,"status":"Error","age":"2 seconds ago"},"Firewall":{"statusCode":2,"message":"No problems were detected.","logLocation":"\/ui\/diagnostics\/log\/core\/firewall","timestamp":"0","status":"OK"},"System":{"status":"Error"}}
ihatemodels commented 7 months ago

Got it. I will remove the unused fields and this should be fixed in the next release

tebrown commented 7 months ago

You are the best! Thank you!

ihatemodels commented 7 months ago

If you are in a hurry, you can now build the docker image from main. I plan to do proper release after a day or two after close of other issues as well.

Thanks for the bug report

tebrown commented 7 months ago

I am not in a hurry, but I will try it out! Thanks again!!