-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(probe): status of SDN Connectors (#210)
* Adding functionality for querying the status of SDN Connectors
- Loading branch information
1 parent
22a6ee8
commit 62da407
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package probe | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/bluecmd/fortigate_exporter/pkg/http" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type SystemSDNConnectorResults struct { | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
Status string `json:"status"` | ||
Updating bool `json:"updating"` | ||
LastUpdate int `json:"last_update"` | ||
} | ||
|
||
type SystemSDNConnector struct { | ||
Results []SystemSDNConnectorResults `json:"results"` | ||
VDOM string `json:"vdom"` | ||
} | ||
|
||
func probeSystemSDNConnector(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { | ||
var ( | ||
SDNConnectorsStatus = prometheus.NewDesc( | ||
"fortigate_system_sdn_connector_status", | ||
"Status of SDN connectors (0=Disabled, 1=Down, 2=Unknown, 3=Up, 4=Updating)", | ||
[]string{"vdom", "name", "type"}, nil, | ||
) | ||
SDNConnectorsLastUpdate = prometheus.NewDesc( | ||
"fortigate_system_sdn_connector_last_update_seconds", | ||
"Last update time for SDN connectors (in seconds from epoch)", | ||
[]string{"vdom", "name", "type"}, nil, | ||
) | ||
) | ||
|
||
var res []SystemSDNConnector | ||
if err := c.Get("api/v2/monitor/system/sdn-connector/status", "vdom=*", &res); err != nil { | ||
log.Printf("Error: %v", err) | ||
return nil, false | ||
} | ||
|
||
m := []prometheus.Metric{} | ||
for _, r := range res { | ||
for _, sdnConn := range r.Results { | ||
if sdnConn.Status == "Disabled" { | ||
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(0), r.VDOM, sdnConn.Name, sdnConn.Type)) | ||
} else if sdnConn.Status == "Down" { | ||
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(1), r.VDOM, sdnConn.Name, sdnConn.Type)) | ||
} else if sdnConn.Status == "Unknown" { | ||
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(2), r.VDOM, sdnConn.Name, sdnConn.Type)) | ||
} else if sdnConn.Status == "Up" { | ||
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(3), r.VDOM, sdnConn.Name, sdnConn.Type)) | ||
} else if sdnConn.Status == "Updating" { | ||
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(4), r.VDOM, sdnConn.Name, sdnConn.Type)) | ||
} | ||
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsLastUpdate, prometheus.GaugeValue, float64(sdnConn.LastUpdate), r.VDOM, sdnConn.Name, sdnConn.Type)) | ||
} | ||
} | ||
|
||
return m, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package probe | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
) | ||
|
||
func TestSystemSDNConnector(t *testing.T) { | ||
c := newFakeClient() | ||
c.prepare("api/v2/monitor/system/sdn-connector/status", "testdata/system-sdn-connector.jsonnet") | ||
r := prometheus.NewPedanticRegistry() | ||
if !testProbe(probeSystemSDNConnector, c, r) { | ||
t.Errorf("probeSystemSDNConnector() returned non-success") | ||
} | ||
|
||
em := ` | ||
# HELP fortigate_system_sdn_connector_status Status of SDN connectors (0=Disabled, 1=Down, 2=Unknown, 3=Up, 4=Updating) | ||
# TYPE fortigate_system_sdn_connector_status gauge | ||
fortigate_system_sdn_connector_status{name="AWS Infra",type="aws",vdom="root"} 3 | ||
fortigate_system_sdn_connector_status{name="GCP Infra",type="gcp",vdom="google"} 1 | ||
# HELP fortigate_system_sdn_connector_last_update_seconds Last update time for SDN connectors (in seconds from epoch) | ||
# TYPE fortigate_system_sdn_connector_last_update_seconds gauge | ||
fortigate_system_sdn_connector_last_update_seconds{name="AWS Infra",type="aws",vdom="root"} 1680708575 | ||
fortigate_system_sdn_connector_last_update_seconds{name="GCP Infra",type="gcp",vdom="google"} 1680708001 | ||
` | ||
|
||
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
t.Fatalf("metric compare: err %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# api/v2/system/sdn-connector/status?vdom=* | ||
[ | ||
{ | ||
"http_method":"GET", | ||
"results":[ | ||
{ | ||
"name":"AWS Infra", | ||
"type":"aws", | ||
"status":"Up", | ||
"updating":false, | ||
"last_update":1680708575 | ||
} | ||
], | ||
"vdom":"root", | ||
"path":"system", | ||
"name":"sdn-connector", | ||
"action":"status", | ||
"status":"success", | ||
"serial":"FGABCDEF12345678", | ||
"version":"v7.0.9", | ||
"build":444 | ||
}, | ||
{ | ||
"http_method":"GET", | ||
"results":[ | ||
{ | ||
"name":"GCP Infra", | ||
"type":"gcp", | ||
"status":"Down", | ||
"updating":false, | ||
"last_update":1680708001 | ||
} | ||
], | ||
"vdom":"google", | ||
"path":"system", | ||
"name":"sdn-connector", | ||
"action":"status", | ||
"status":"success", | ||
"serial":"FGABCDEF12345678", | ||
"version":"v7.0.9", | ||
"build":444 | ||
} | ||
] |