Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse date and time from DisplayString #1232

Closed
phibos opened this issue Aug 8, 2024 · 3 comments · Fixed by #1234
Closed

Parse date and time from DisplayString #1232

phibos opened this issue Aug 8, 2024 · 3 comments · Fixed by #1234

Comments

@phibos
Copy link
Contributor

phibos commented Aug 8, 2024

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?

@SuperQ
Copy link
Member

SuperQ commented Aug 8, 2024

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.

@phibos
Copy link
Contributor Author

phibos commented Aug 8, 2024

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.

@SuperQ
Copy link
Member

SuperQ commented Aug 8, 2024

We can do some more research on time parse libraries. That is a small component to swap out.

phibos added a commit to phibos/snmp_exporter that referenced this issue Aug 13, 2024
Add new type ParseDateAndTime to parse timestamps from DisplayString
and report it as unix timestamp.
phibos added a commit to phibos/snmp_exporter that referenced this issue Aug 13, 2024
Add new type ParseDateAndTime to parse timestamps from DisplayString
and report it as unix timestamp.

Signed-off-by: PhiBo <[email protected]>
phibos added a commit to phibos/snmp_exporter that referenced this issue Aug 27, 2024
Add new type ParseDateAndTime to parse timestamps from DisplayString
and report it as unix timestamp.

Signed-off-by: PhiBo <[email protected]>
@SuperQ SuperQ closed this as completed in 1d75633 Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants