Skip to content

Commit d57c678

Browse files
committed
Correct state metrics
Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se>
1 parent e9d7607 commit d57c678

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

pkg/probe/system_ha_peer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func probeSystemHaPeer (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Me
2525
var (
2626
Priority = prometheus.NewDesc(
2727
"fortigate_ha_peer",
28-
"True when the peer device is the HA primary.(true=1, false=0)",
28+
"True when the peer device is the HA primary.",
2929
[]string{"serial","vcluster","hostname","master","primary","priority"}, nil,
3030
)
3131
)
@@ -52,9 +52,11 @@ func probeSystemHaPeer (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Me
5252
for _, r := range res.Result {
5353
if meta.VersionMajor >= 7 && meta.VersionMinor >= 4 {
5454
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)))
55+
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "true", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
56+
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 0, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "false", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
5657
} 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+
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 0, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "true", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
59+
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "false", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
5860
}
5961
} else {
6062
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, -1, "None", "0", "None", "false", "Unsupported", "false"))

pkg/probe/system_ha_peer_test.go

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

3636
em := `
37-
# HELP fortigate_ha_peer True when the peer device is the HA primary.(true=1, false=0)
37+
# HELP fortigate_ha_peer True when the peer device is the HA primary.
3838
# TYPE fortigate_ha_peer gauge
3939
fortigate_ha_peer{hostname="None",master="false",primary="Unsupported",priority="false",serial="None",vcluster="0"} -1
4040
`
@@ -57,10 +57,12 @@ func TestSystemHaPeerAfter74(t *testing.T) {
5757
}
5858

5959
em := `
60-
# HELP fortigate_ha_peer True when the peer device is the HA primary.(true=1, false=0)
60+
# HELP fortigate_ha_peer True when the peer device is the HA primary.
6161
# TYPE fortigate_ha_peer gauge
62+
fortigate_ha_peer{hostname="member-name-1",master="false",primary="false",priority="200",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 0
6263
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
64+
fortigate_ha_peer{hostname="member-name-2",master="false",primary="false",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 1
65+
fortigate_ha_peer{hostname="member-name-2",master="false",primary="true",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 0
6466
`
6567

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

0 commit comments

Comments
 (0)