Skip to content

Commit 1028bc9

Browse files
committed
Updated after discussion
Signed-off-by: Philip Örnfeldt <philip.ornfeldt@outlook.com>
1 parent 0f7b271 commit 1028bc9

2 files changed

Lines changed: 26 additions & 82 deletions

File tree

pkg/probe/system_sandbox_connection.go

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,10 @@ import (
2222
)
2323

2424
func probeSystemSandboxConnection(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
25-
connectionStatusDisable := prometheus.NewDesc(
26-
"fortigate_sandbox_connection_status_disabled",
25+
connectionStatus := prometheus.NewDesc(
26+
"fortigate_sandbox_connection_state",
2727
"Sandbox connection status",
28-
[]string{"sandbox_type"}, nil,
29-
)
30-
connectionStatusUreachable := prometheus.NewDesc(
31-
"fortigate_sandbox_connection_status_unreachable",
32-
"Sandbox connection status",
33-
[]string{"sandbox_type"}, nil,
34-
)
35-
connectionStatusReachable := prometheus.NewDesc(
36-
"fortigate_sandbox_connection_status_reachable",
37-
"Sandbox connection status",
38-
[]string{"sandbox_type"}, nil,
39-
)
40-
connectionStatusUnauthorized := prometheus.NewDesc(
41-
"fortigate_sandbox_connection_status_unauthorized",
42-
"Sandbox connection status",
43-
[]string{"sandbox_type"}, nil,
44-
)
45-
connectionStatusIncompatible := prometheus.NewDesc(
46-
"fortigate_sandbox_connection_status_incompatible",
47-
"Sandbox connection status",
48-
[]string{"sandbox_type"}, nil,
49-
)
50-
connectionStatusUnverified := prometheus.NewDesc(
51-
"fortigate_sandbox_connection_status_unverified",
52-
"Sandbox connection status",
53-
[]string{"sandbox_type"}, nil,
28+
[]string{"sandbox_type", "status"}, nil,
5429
)
5530

5631
type SystemSandboxConnection struct {
@@ -69,50 +44,29 @@ func probeSystemSandboxConnection(c http.FortiHTTP, _ *TargetMetadata) ([]promet
6944

7045
m := []prometheus.Metric{}
7146
for _, r := range res.Results {
47+
t := []prometheus.Metric{
48+
prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type, "unreachable"),
49+
prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type, "reachable"),
50+
prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type, "disabled"),
51+
prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type, "unauthorized"),
52+
prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type, "incompatible"),
53+
prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 0, r.Type, "unverified"),
54+
}
7255
switch r.Status {
7356
case "unreachable":
74-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 1, r.Type))
75-
m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 0, r.Type))
76-
m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 0, r.Type))
77-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnauthorized, prometheus.GaugeValue, 0, r.Type))
78-
m = append(m, prometheus.MustNewConstMetric(connectionStatusIncompatible, prometheus.GaugeValue, 0, r.Type))
79-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnverified, prometheus.GaugeValue, 0, r.Type))
57+
t[0] = prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 1, r.Type, r.Status)
8058
case "reachable":
81-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 0, r.Type))
82-
m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 1, r.Type))
83-
m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 0, r.Type))
84-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnauthorized, prometheus.GaugeValue, 0, r.Type))
85-
m = append(m, prometheus.MustNewConstMetric(connectionStatusIncompatible, prometheus.GaugeValue, 0, r.Type))
86-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnverified, prometheus.GaugeValue, 0, r.Type))
59+
t[1] = prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 1, r.Type, r.Status)
8760
case "disabled":
88-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 0, r.Type))
89-
m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 0, r.Type))
90-
m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 1, r.Type))
91-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnauthorized, prometheus.GaugeValue, 0, r.Type))
92-
m = append(m, prometheus.MustNewConstMetric(connectionStatusIncompatible, prometheus.GaugeValue, 0, r.Type))
93-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnverified, prometheus.GaugeValue, 0, r.Type))
61+
t[2] = prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 1, r.Type, r.Status)
9462
case "unauthorized":
95-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 0, r.Type))
96-
m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 0, r.Type))
97-
m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 0, r.Type))
98-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnauthorized, prometheus.GaugeValue, 1, r.Type))
99-
m = append(m, prometheus.MustNewConstMetric(connectionStatusIncompatible, prometheus.GaugeValue, 0, r.Type))
100-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnverified, prometheus.GaugeValue, 0, r.Type))
63+
t[3] = prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 1, r.Type, r.Status)
10164
case "incompatible":
102-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 0, r.Type))
103-
m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 0, r.Type))
104-
m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 0, r.Type))
105-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnauthorized, prometheus.GaugeValue, 0, r.Type))
106-
m = append(m, prometheus.MustNewConstMetric(connectionStatusIncompatible, prometheus.GaugeValue, 1, r.Type))
107-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnverified, prometheus.GaugeValue, 0, r.Type))
65+
t[4] = prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 1, r.Type, r.Status)
10866
case "unverified":
109-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 0, r.Type))
110-
m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 0, r.Type))
111-
m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 0, r.Type))
112-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnauthorized, prometheus.GaugeValue, 0, r.Type))
113-
m = append(m, prometheus.MustNewConstMetric(connectionStatusIncompatible, prometheus.GaugeValue, 0, r.Type))
114-
m = append(m, prometheus.MustNewConstMetric(connectionStatusUnverified, prometheus.GaugeValue, 1, r.Type))
67+
t[5] = prometheus.MustNewConstMetric(connectionStatus, prometheus.GaugeValue, 1, r.Type, r.Status)
11568
}
69+
m = append(m, t...)
11670
}
11771
return m, true
11872
}

pkg/probe/system_sandbox_connection_test.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,14 @@ func TestSystemSandboxConnection(t *testing.T) {
3030
}
3131

3232
em := `
33-
# HELP fortigate_sandbox_connection_status_disabled Sandbox connection status
34-
# TYPE fortigate_sandbox_connection_status_disabled gauge
35-
fortigate_sandbox_connection_status_disabled{sandbox_type="appliance"} 0
36-
# HELP fortigate_sandbox_connection_status_incompatible Sandbox connection status
37-
# TYPE fortigate_sandbox_connection_status_incompatible gauge
38-
fortigate_sandbox_connection_status_incompatible{sandbox_type="appliance"} 0
39-
# HELP fortigate_sandbox_connection_status_reachable Sandbox connection status
40-
# TYPE fortigate_sandbox_connection_status_reachable gauge
41-
fortigate_sandbox_connection_status_reachable{sandbox_type="appliance"} 1
42-
# HELP fortigate_sandbox_connection_status_unauthorized Sandbox connection status
43-
# TYPE fortigate_sandbox_connection_status_unauthorized gauge
44-
fortigate_sandbox_connection_status_unauthorized{sandbox_type="appliance"} 0
45-
# HELP fortigate_sandbox_connection_status_unreachable Sandbox connection status
46-
# TYPE fortigate_sandbox_connection_status_unreachable gauge
47-
fortigate_sandbox_connection_status_unreachable{sandbox_type="appliance"} 0
48-
# HELP fortigate_sandbox_connection_status_unverified Sandbox connection status
49-
# TYPE fortigate_sandbox_connection_status_unverified gauge
50-
fortigate_sandbox_connection_status_unverified{sandbox_type="appliance"} 0
33+
# HELP fortigate_sandbox_connection_state Sandbox connection status
34+
# TYPE fortigate_sandbox_connection_state gauge
35+
fortigate_sandbox_connection_state{sandbox_type="appliance",status="disabled"} 0
36+
fortigate_sandbox_connection_state{sandbox_type="appliance",status="incompatible"} 0
37+
fortigate_sandbox_connection_state{sandbox_type="appliance",status="reachable"} 1
38+
fortigate_sandbox_connection_state{sandbox_type="appliance",status="unauthorized"} 0
39+
fortigate_sandbox_connection_state{sandbox_type="appliance",status="unreachable"} 0
40+
fortigate_sandbox_connection_state{sandbox_type="appliance",status="unverified"} 0
5141
`
5242

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

0 commit comments

Comments
 (0)