Skip to content

Commit a070fe7

Browse files
committed
Corrected data
Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se>
1 parent a0f2dfc commit a070fe7

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

pkg/probe/system_ha_peer.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424
func probeSystemHaPeer (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
2525
var (
2626
Priority = prometheus.NewDesc(
27-
"fortigate_ha_peer_priority",
28-
"Priority level of the HA peer device.",
29-
[]string{"serial","vcluster","hostname","master","primary"}, nil,
27+
"fortigate_ha_peer",
28+
"True when the peer device is the HA primary.(true=1, false=0)",
29+
[]string{"serial","vcluster","hostname","master","primary","priority"}, nil,
3030
)
3131
)
3232

@@ -51,9 +51,14 @@ func probeSystemHaPeer (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Me
5151
m := []prometheus.Metric{}
5252
for _, r := range res.Result {
5353
if meta.VersionMajor >= 7 && meta.VersionMinor >= 4 {
54-
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, r.Priority, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), strconv.FormatBool(r.Primary)))
54+
if (r.Primary) {
55+
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), strconv.FormatBool(r.Primary), strconv.FormatFloat(r.Priority, 'f', -1, 64)))
56+
} else {
57+
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 0, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), strconv.FormatBool(r.Primary), strconv.FormatFloat(r.Priority, 'f', -1, 64)))
58+
}
5559
} else {
56-
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, r.Priority, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "Unsupported"))
60+
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, -1, "None", "0", "None", "false", "Unsupported", "false"))
61+
break
5762
}
5863
}
5964
return m, true

pkg/probe/system_ha_peer_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ func TestSystemHaPeerOld(t *testing.T) {
3434
}
3535

3636
em := `
37-
# HELP fortigate_ha_peer_priority Priority level of the HA peer device.
38-
# TYPE fortigate_ha_peer_priority gauge
39-
fortigate_ha_peer_priority{hostname="member-name-1",master="false",primary="Unsupported",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 200
40-
fortigate_ha_peer_priority{hostname="member-name-2",master="false",primary="Unsupported",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 100
37+
# HELP fortigate_ha_peer True when the peer device is the HA primary.(true=1, false=0)
38+
# TYPE fortigate_ha_peer gauge
39+
fortigate_ha_peer{hostname="None",master="false",primary="Unsupported",priority="false",serial="None",vcluster="0"} -1
4140
`
4241

4342
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
@@ -58,10 +57,10 @@ func TestSystemHaPeerAfter74(t *testing.T) {
5857
}
5958

6059
em := `
61-
# HELP fortigate_ha_peer_priority Priority level of the HA peer device.
62-
# TYPE fortigate_ha_peer_priority gauge
63-
fortigate_ha_peer_priority{hostname="member-name-1",master="false",primary="true",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 200
64-
fortigate_ha_peer_priority{hostname="member-name-2",master="false",primary="false",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 100
60+
# HELP fortigate_ha_peer True when the peer device is the HA primary.(true=1, false=0)
61+
# TYPE fortigate_ha_peer gauge
62+
fortigate_ha_peer{hostname="member-name-1",master="false",primary="true",priority="200",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 1
63+
fortigate_ha_peer{hostname="member-name-2",master="false",primary="false",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 0
6564
`
6665

6766
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {

0 commit comments

Comments
 (0)