Parse date and time from DisplayString
Host operating system: output of uname -a
Docker on Linux
snmp_exporter version: output of snmp_exporter -version
snmp_exporter, version 0.26.0 (branch: HEAD, revision: 44f8732988e726bad3f13d5779f1da7705178642)
build user: root@90ba0aabb239
build date: 20240511-11:16:35
go version: go1.22.3
platform: linux/amd64
tags: unknown
What device/snmpwalk OID are you using?
sfosBaseFWLicExpiryDate OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION "Base Firewall protection Lic expiry date"
::= { sfosDeviceBaseFWLic 2 }
If this is a new device, please link to the MIB(s).
https://docs.sophos.com/nsg/sophos-firewall/MIB/SOPHOS-XG-MIB.zip
What did you do that produced an error?
What did you expect to see?
Parse the date and time and report the timestamp
What did you see instead?
I'm currently working on including Sophos XG devices. But at the moment I haven't finished a PR because the snmp_exporter is unable to parse date and time from a DisplayString.
If a valid license has been provided the output looks like the example below.
# HELP sfosBaseFWLicExpiryDate Base Firewall protection Lic expiry date - 1.3.6.1.4.1.2604.5.1.5.1.2
# TYPE sfosBaseFWLicExpiryDate gauge
sfosBaseFWLicExpiryDate{sfosBaseFWLicExpiryDate="Dec 31 2999"} 1
If a license is not available the output will look like.
# HELP sfosCentralOrchestrationLicExpiryDate Central Orchestration Lic expiry date - 1.3.6.1.4.1.2604.5.1.5.9.2
# TYPE sfosCentralOrchestrationLicExpiryDate gauge
sfosCentralOrchestrationLicExpiryDate{sfosCentralOrchestrationLicExpiryDate="fail"} 1
Also there is a value for the current time.
# HELP sfosCurrentDate Current system date and time - 1.3.6.1.4.1.2604.5.1.2.1
# TYPE sfosCurrentDate gauge
sfosCurrentDate{sfosCurrentDate="Thu Aug 8 14:28:07 2024"} 1
New feature
Would be great if the exporter can parse the date and time and report the timestamp similar to the DateAndTime type.
To solve the issue I would like to add a new type ParseDateAndTime and use the time.Parse() https://pkg.go.dev/time#Parse function to parse the value. If go is unable to parse the date I would skip the metric.
Example config:
overrides: # Allows for per-module overrides of bits of MIBs
sfosBaseFWLicExpiryDate{sfosBaseFWLicExpiryDate:
type: ParseDateAndTime
datetime_format: Jan 02 2006
sfosCurrentDate{sfosCurrentDate:
type: ParseDateAndTime
datetime_format: Mon Jan 2 3:04:05 2006
What do you think about it? Is it worth to implement this feature and open a PR or is it out of scope for the snmp_exporter?
I think this would be a great idea. The resulting output should follow the Prometheus convention of returning a UNIX epoch timestamp in seconds as the value.
Personally I would prefer strftime parser over Go's weirdo format.
I think this has been proposed in the past. But of course I can't find the feature request in the issue tracker right now.
I think this would be a great idea. The resulting output should follow the Prometheus convention of returning a UNIX epoch timestamp in seconds as the value.
Yes I totally agree.
Personally I would prefer strftime parser over Go's weirdo format.
I have suggested the time module to avoid additional dependencies and all the stftime modules only have a few stars on github. But if we all agree on using the suggested stftime module I can provide a PR and use it instead the time.
We can do some more research on time parse libraries. That is a small component to swap out.