Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Cannot parse OpenVPN client tIme #48

Open
erdnaxe opened this issue Aug 14, 2021 · 2 comments
Open

Cannot parse OpenVPN client tIme #48

erdnaxe opened this issue Aug 14, 2021 · 2 comments

Comments

@erdnaxe
Copy link

erdnaxe commented Aug 14, 2021

When querying the exporter, I get:

openvpn_exporter[801]: 2021/08/14 13:11:20 Failed to scrape showq socket: parsing time "2021-08-14 13:11:20" as "Mon Jan 2 15:04:05 2006": cannot parse "2021-08-14 13:11:20" as "Mon"

I believe this is caused by

// Time at which the statistics were updated.
location, _ := time.LoadLocation("Local")
timeParser, err := time.ParseInLocation("Mon Jan 2 15:04:05 2006", fields[1], location)
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(
e.openvpnStatusUpdateTimeDesc,
prometheus.GaugeValue,
float64(timeParser.Unix()),
statusPath)

@erdnaxe
Copy link
Author

erdnaxe commented Aug 14, 2021

Proposition, although they may be a cleaner way to do this:

	// Time at which the statistics were updated.
	location, _ := time.LoadLocation("Local")
	timeParser, err := time.ParseInLocation("Mon Jan 2 15:04:05 2006", fields[1], location)
	if err != nil {
		// Try ISO8601 format (OpenVPN 2.5+)
		timeParser, err = time.ParseInLocation("2006-01-02 15:04:05", fields[1], location)
	}
	if err != nil {
		return err
	}
	ch <- prometheus.MustNewConstMetric(
		e.openvpnStatusUpdateTimeDesc,
		prometheus.GaugeValue,
		float64(timeParser.Unix()),
		statusPath)

@erdnaxe
Copy link
Author

erdnaxe commented Aug 14, 2021

This has been broken with OpenVPN 2.5.0, Change timestamps in file-based logging to ISO 8601 time format. in https://community.openvpn.net/openvpn/wiki/ChangesInOpenvpn25

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant