From b44c25ef05d6212c74748641c91a1aaf2834390c Mon Sep 17 00:00:00 2001 From: Vyacheslav Vershinin Date: Wed, 27 Nov 2024 12:08:13 +0000 Subject: [PATCH 1/2] feat: add bmc url Signed-off-by: happyfx --- collector_bmc.go | 10 ++++++++-- freeipmi/freeipmi.go | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/collector_bmc.go b/collector_bmc.go index 84b8ce3..18a735f 100644 --- a/collector_bmc.go +++ b/collector_bmc.go @@ -27,7 +27,7 @@ var ( bmcInfoDesc = prometheus.NewDesc( prometheus.BuildFQName(namespace, "bmc", "info"), "Constant metric with value '1' providing details about the BMC.", - []string{"firmware_revision", "manufacturer_id", "system_firmware_version"}, + []string{"firmware_revision", "manufacturer_id", "system_firmware_version", "bmc_url"}, nil, ) ) @@ -63,11 +63,17 @@ func (c BMCCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metri logger.Debug("Failed to parse bmc-info data", "target", targetName(target.host), "error", err) systemFirmwareVersion = "N/A" } + bmcUrl, err := freeipmi.GetBMCInfoBmcUrl(result) + if err != nil { + // This one is not always available. + logger.Debug("Failed to parse bmc-info data", "target", targetName(target.host), "error", err) + systemFirmwareVersion = "N/A" + } ch <- prometheus.MustNewConstMetric( bmcInfoDesc, prometheus.GaugeValue, 1, - firmwareRevision, manufacturerID, systemFirmwareVersion, + firmwareRevision, manufacturerID, systemFirmwareVersion, bmcUrl ) return 1, nil } diff --git a/freeipmi/freeipmi.go b/freeipmi/freeipmi.go index 1d6c8d5..cc2987d 100644 --- a/freeipmi/freeipmi.go +++ b/freeipmi/freeipmi.go @@ -43,6 +43,7 @@ var ( bmcInfoFirmwareRevisionRegex = regexp.MustCompile(`^Firmware Revision\s*:\s*(?P[0-9.]*).*`) bmcInfoSystemFirmwareVersionRegex = regexp.MustCompile(`^System Firmware Version\s*:\s*(?P[0-9.]*).*`) bmcInfoManufacturerIDRegex = regexp.MustCompile(`^Manufacturer ID\s*:\s*(?P.*)`) + bmcInfoBmcUrlRegex = regexp.MustCompile(`^BMC URL\s*:\s*(?P.*)`) bmcWatchdogTimerStateRegex = regexp.MustCompile(`^Timer:\s*(?PRunning|Stopped)`) bmcWatchdogTimerUseRegex = regexp.MustCompile(`^Timer Use:\s*(?P.*)`) bmcWatchdogTimerLoggingRegex = regexp.MustCompile(`^Logging:\s*(?PEnabled|Disabled)`) @@ -313,6 +314,13 @@ func GetBMCInfoSystemFirmwareVersion(ipmiOutput Result) (string, error) { return getValue(ipmiOutput.output, bmcInfoSystemFirmwareVersionRegex) } +func GetBMCInfoBmcUrl(ipmiOutput Result) (string, error) { + if ipmiOutput.err != nil { + return "", fmt.Errorf("%s: %s", ipmiOutput.err, ipmiOutput.output) + } + return getValue(ipmiOutput.output, bmcInfoBmcUrlRegex) +} + func GetSELInfoEntriesCount(ipmiOutput Result) (float64, error) { if ipmiOutput.err != nil { return -1, fmt.Errorf("%s: %s", ipmiOutput.err, ipmiOutput.output) From 2993a9a8bd23fa782ab6e060587d12aa2cd80535 Mon Sep 17 00:00:00 2001 From: happyfx Date: Wed, 27 Nov 2024 14:13:46 +0200 Subject: [PATCH 2/2] fix: comma Signed-off-by: happyfx --- collector_bmc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector_bmc.go b/collector_bmc.go index 18a735f..114e28b 100644 --- a/collector_bmc.go +++ b/collector_bmc.go @@ -73,7 +73,7 @@ func (c BMCCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metri bmcInfoDesc, prometheus.GaugeValue, 1, - firmwareRevision, manufacturerID, systemFirmwareVersion, bmcUrl + firmwareRevision, manufacturerID, systemFirmwareVersion, bmcUrl, ) return 1, nil }