Skip to content

Commit cbf6808

Browse files
Rewrite of sdn_connector_status to stateset (#368)
* Rewrite of sdn_connector_status to stateset Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> * New stateset implemented Signed-off-by: Philip Örnfeldt <philip.ornfeldt@outlook.com> * Reverted back old version and added new to metrics Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> --------- Signed-off-by: Örnfeldt Philip (66140321) <philip.ornfeldt@forsakringskassan.se> Signed-off-by: Philip Örnfeldt <philip.ornfeldt@outlook.com> Co-authored-by: Sebastian Schubert <16682281+bastischubert@users.noreply.github.com>
1 parent a03e09f commit cbf6808

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Per-VDOM:
9292
* _System/Interface/Transceivers_
9393
* `fortigate_inteface_transceivers_info`
9494
* _System/SDNConnector_
95+
* `fortigate_system_sdn_connector_state`
9596
* `fortigate_system_sdn_connector_status`
9697
* `fortigate_system_sdn_connector_last_update_seconds`
9798
* _/System/CentralManagement/Status_

pkg/probe/system_sdn_connector.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func probeSystemSDNConnector(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.
4141
"Status of SDN connectors (0=Disabled, 1=Down, 2=Unknown, 3=Up, 4=Updating)",
4242
[]string{"vdom", "name", "type"}, nil,
4343
)
44+
SDNConnectorsState = prometheus.NewDesc(
45+
"fortigate_system_sdn_connector_state",
46+
"Status of SDN connectors disabled",
47+
[]string{"vdom", "name", "type", "state"}, nil,
48+
)
4449
SDNConnectorsLastUpdate = prometheus.NewDesc(
4550
"fortigate_system_sdn_connector_last_update_seconds",
4651
"Last update time for SDN connectors (in seconds from epoch)",
@@ -57,19 +62,32 @@ func probeSystemSDNConnector(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.
5762
m := []prometheus.Metric{}
5863
for _, r := range res {
5964
for _, sdnConn := range r.Results {
65+
t := []prometheus.Metric{
66+
prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 0.0, r.VDOM, sdnConn.Name, sdnConn.Type, "Disabled"),
67+
prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 0.0, r.VDOM, sdnConn.Name, sdnConn.Type, "Down"),
68+
prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 0.0, r.VDOM, sdnConn.Name, sdnConn.Type, "Unknown"),
69+
prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 0.0, r.VDOM, sdnConn.Name, sdnConn.Type, "Up"),
70+
prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 0.0, r.VDOM, sdnConn.Name, sdnConn.Type, "Updating"),
71+
}
6072
switch sdnConn.Status {
6173
case "Disabled":
6274
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(0), r.VDOM, sdnConn.Name, sdnConn.Type))
75+
t[0] = prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 1.0, r.VDOM, sdnConn.Name, sdnConn.Type, sdnConn.Status)
6376
case "Down":
6477
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(1), r.VDOM, sdnConn.Name, sdnConn.Type))
78+
t[1] = prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 1.0, r.VDOM, sdnConn.Name, sdnConn.Type, sdnConn.Status)
6579
case "Unknown":
6680
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(2), r.VDOM, sdnConn.Name, sdnConn.Type))
81+
t[2] = prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 1.0, r.VDOM, sdnConn.Name, sdnConn.Type, sdnConn.Status)
6782
case "Up":
6883
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(3), r.VDOM, sdnConn.Name, sdnConn.Type))
84+
t[3] = prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 1.0, r.VDOM, sdnConn.Name, sdnConn.Type, sdnConn.Status)
6985
case "Updating":
7086
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(4), r.VDOM, sdnConn.Name, sdnConn.Type))
87+
t[4] = prometheus.MustNewConstMetric(SDNConnectorsState, prometheus.GaugeValue, 1.0, r.VDOM, sdnConn.Name, sdnConn.Type, sdnConn.Status)
7188
}
7289
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsLastUpdate, prometheus.GaugeValue, float64(sdnConn.LastUpdate), r.VDOM, sdnConn.Name, sdnConn.Type))
90+
m = append(m, t...)
7391
}
7492
}
7593

pkg/probe/system_sdn_connector_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,26 @@ func TestSystemSDNConnector(t *testing.T) {
3030
}
3131

3232
em := `
33+
# HELP fortigate_system_sdn_connector_last_update_seconds Last update time for SDN connectors (in seconds from epoch)
34+
# TYPE fortigate_system_sdn_connector_last_update_seconds gauge
35+
fortigate_system_sdn_connector_last_update_seconds{name="AWS Infra",type="aws",vdom="root"} 1.680708575e+09
36+
fortigate_system_sdn_connector_last_update_seconds{name="GCP Infra",type="gcp",vdom="google"} 1.680708001e+09
37+
# HELP fortigate_system_sdn_connector_state Status of SDN connectors disabled
38+
# TYPE fortigate_system_sdn_connector_state gauge
39+
fortigate_system_sdn_connector_state{name="AWS Infra",state="Disabled",type="aws",vdom="root"} 0
40+
fortigate_system_sdn_connector_state{name="AWS Infra",state="Down",type="aws",vdom="root"} 0
41+
fortigate_system_sdn_connector_state{name="AWS Infra",state="Unknown",type="aws",vdom="root"} 0
42+
fortigate_system_sdn_connector_state{name="AWS Infra",state="Up",type="aws",vdom="root"} 1
43+
fortigate_system_sdn_connector_state{name="AWS Infra",state="Updating",type="aws",vdom="root"} 0
44+
fortigate_system_sdn_connector_state{name="GCP Infra",state="Disabled",type="gcp",vdom="google"} 0
45+
fortigate_system_sdn_connector_state{name="GCP Infra",state="Down",type="gcp",vdom="google"} 1
46+
fortigate_system_sdn_connector_state{name="GCP Infra",state="Unknown",type="gcp",vdom="google"} 0
47+
fortigate_system_sdn_connector_state{name="GCP Infra",state="Up",type="gcp",vdom="google"} 0
48+
fortigate_system_sdn_connector_state{name="GCP Infra",state="Updating",type="gcp",vdom="google"} 0
3349
# HELP fortigate_system_sdn_connector_status Status of SDN connectors (0=Disabled, 1=Down, 2=Unknown, 3=Up, 4=Updating)
3450
# TYPE fortigate_system_sdn_connector_status gauge
3551
fortigate_system_sdn_connector_status{name="AWS Infra",type="aws",vdom="root"} 3
3652
fortigate_system_sdn_connector_status{name="GCP Infra",type="gcp",vdom="google"} 1
37-
# HELP fortigate_system_sdn_connector_last_update_seconds Last update time for SDN connectors (in seconds from epoch)
38-
# TYPE fortigate_system_sdn_connector_last_update_seconds gauge
39-
fortigate_system_sdn_connector_last_update_seconds{name="AWS Infra",type="aws",vdom="root"} 1680708575
40-
fortigate_system_sdn_connector_last_update_seconds{name="GCP Infra",type="gcp",vdom="google"} 1680708001
4153
`
4254

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

0 commit comments

Comments
 (0)