Skip to content

Commit 5732f68

Browse files
authored
fix license expiration metric (#282)
1 parent 3392081 commit 5732f68

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

pkg/features/system/collector.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,19 @@ func (c *systemCollector) collectLicense(client collector.Client, ch chan<- prom
420420
ch <- prometheus.MustNewConstMetric(licenseInstalledDesc, prometheus.GaugeValue, float64(lic.Installed), licenseLabels...)
421421
ch <- prometheus.MustNewConstMetric(licenseNeededDesc, prometheus.GaugeValue, float64(lic.Needed), licenseLabels...)
422422

423-
expiry_str := strings.ToLower(lic.ValidityType)
424-
expiry, err := time.Parse("2006-01-02 03:04:05 MST", expiry_str)
425-
if err != nil {
426-
if strings.Compare(expiry_str, "expired") == 0 {
427-
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(-1), licenseLabels...)
428-
} else if strings.Compare(expiry_str, "permanent") == 0 {
429-
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(math.Inf(1)), licenseLabels...)
423+
if strings.Compare(lic.ValidityType, "expired") == 0 {
424+
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(-1), licenseLabels...)
425+
} else if strings.Compare(lic.ValidityType, "permanent") == 0 {
426+
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(math.Inf(1)), licenseLabels...)
427+
} else {
428+
expiry_str := strings.ToLower(lic.EndDate)
429+
expiry, err := time.Parse("2006-01-02", expiry_str)
430+
if err != nil {
431+
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(math.Inf(-1)), licenseLabels...)
430432
} else {
431-
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(math.Inf(-1)), licenseLabels...)
433+
license_ttl_days := time.Until(expiry).Hours() / 24.0
434+
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(license_ttl_days), licenseLabels...)
432435
}
433-
} else {
434-
license_ttl_days := time.Until(expiry).Hours() / 24.0
435-
ch <- prometheus.MustNewConstMetric(licenseExpiryDesc, prometheus.GaugeValue, float64(license_ttl_days), licenseLabels...)
436436
}
437437
}
438438
}
439-

pkg/features/system/rpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type licenseInformation struct {
8282
Used int `xml:"used-licensed"`
8383
Needed int `xml:"needed"`
8484
ValidityType string `xml:"validity-type"`
85+
EndDate string `xml:"end-date"`
8586
} `xml:"feature-summary"`
8687
} `xml:"license-usage-summary"`
87-
}
88+
}

0 commit comments

Comments
 (0)