Skip to content

Commit

Permalink
fix(output/prometheus-sd): int labels not allowed ...
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Jul 10, 2022
1 parent 156d07e commit 7c01dcb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions output/prometheus-sd/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prometheus_sd

import (
"errors"
"strconv"

"github.com/FreifunkBremen/yanic/output"
"github.com/FreifunkBremen/yanic/runtime"
Expand Down Expand Up @@ -81,8 +82,8 @@ func Register(configuration map[string]interface{}) (output.Output, error) {
}

type Targets struct {
Targets []string `json:"targets"`
Labels map[string]interface{} `json:"labels,omitempty"`
Targets []string `json:"targets"`
Labels map[string]string `json:"labels,omitempty"`
}

func toTargets(n *runtime.Node, defaultLabels map[string]interface{}, targetFunc TargetAddressFunc) *Targets {
Expand All @@ -91,9 +92,10 @@ func toTargets(n *runtime.Node, defaultLabels map[string]interface{}, targetFunc
return nil
}

labels := map[string]interface{}{}
labels := map[string]string{}
for k, v := range defaultLabels {
labels[k] = v
vS := v.(string)
labels[k] = vS
}
if ni := n.Nodeinfo; ni != nil {
labels["node_id"] = ni.NodeID
Expand All @@ -120,10 +122,10 @@ func toTargets(n *runtime.Node, defaultLabels map[string]interface{}, targetFunc

// wireless - airtime
if wifi := ni.Wireless; wifi != nil {
labels["wifi_txpower24"] = wifi.TxPower24
labels["wifi_channel24"] = wifi.Channel24
labels["wifi_txpower5"] = wifi.TxPower5
labels["wifi_channel5"] = wifi.Channel5
labels["wifi_txpower24"] = strconv.Itoa(int(wifi.TxPower24))
labels["wifi_channel24"] = strconv.Itoa(int(wifi.Channel24))
labels["wifi_txpower5"] = strconv.Itoa(int(wifi.TxPower5))
labels["wifi_channel5"] = strconv.Itoa(int(wifi.Channel5))
}
}
return &Targets{
Expand Down

0 comments on commit 7c01dcb

Please sign in to comment.