remove prefix enumeration like 01-...

This commit is contained in:
Holger Obermaier 2022-11-22 17:02:29 +01:00
parent ed68baeada
commit 3e91a37dee

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"io" "io"
"os/exec" "os/exec"
"regexp"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -100,6 +101,7 @@ func (r *IPMIReceiver) doReadMetric() {
idxUnits idxUnits
idxEvent idxEvent
) )
numPrefixRegex := regexp.MustCompile("^[[:digit:]][[:digit:]]-(.*)$")
scanner := bufio.NewScanner(stdout) scanner := bufio.NewScanner(stdout)
for scanner.Scan() { for scanner.Scan() {
// Read host // Read host
@ -124,7 +126,13 @@ func (r *IPMIReceiver) doReadMetric() {
metric := strings.ToLower(v2[idxType]) metric := strings.ToLower(v2[idxType])
name := strings.ToLower( name := strings.ToLower(
strings.Replace(v2[idxName], " ", "_", -1)) strings.Replace(
strings.TrimSpace(
v2[idxName]), " ", "_", -1))
// remove prefix enumeration like 01-...
if v := numPrefixRegex.FindStringSubmatch(name); v != nil {
name = v[1]
}
unit := v2[idxUnits] unit := v2[idxUnits]
if unit == "Watts" { if unit == "Watts" {