|
| 1 | +package probe |
| 2 | + |
| 3 | +import ( |
| 4 | + "log" |
| 5 | + |
| 6 | + "github.com/bluecmd/fortigate_exporter/pkg/http" |
| 7 | + "github.com/prometheus/client_golang/prometheus" |
| 8 | +) |
| 9 | + |
| 10 | +type SystemSDNConnectorResults struct { |
| 11 | + Name string `json:"name"` |
| 12 | + Type string `json:"type"` |
| 13 | + Status string `json:"status"` |
| 14 | + Updating bool `json:"updating"` |
| 15 | + LastUpdate int `json:"last_update"` |
| 16 | +} |
| 17 | + |
| 18 | +type SystemSDNConnector struct { |
| 19 | + Results []SystemSDNConnectorResults `json:"results"` |
| 20 | + VDOM string `json:"vdom"` |
| 21 | +} |
| 22 | + |
| 23 | +func probeSystemSDNConnector(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { |
| 24 | + var ( |
| 25 | + SDNConnectorsStatus = prometheus.NewDesc( |
| 26 | + "fortigate_system_sdn_connector_status", |
| 27 | + "Status of SDN connectors (0=Disabled, 1=Down, 2=Unknown, 3=Up, 4=Updating)", |
| 28 | + []string{"vdom", "name", "type"}, nil, |
| 29 | + ) |
| 30 | + SDNConnectorsLastUpdate = prometheus.NewDesc( |
| 31 | + "fortigate_system_sdn_connector_last_update_seconds", |
| 32 | + "Last update time for SDN connectors (in seconds from epoch)", |
| 33 | + []string{"vdom", "name", "type"}, nil, |
| 34 | + ) |
| 35 | + ) |
| 36 | + |
| 37 | + var res []SystemSDNConnector |
| 38 | + if err := c.Get("api/v2/monitor/system/sdn-connector/status", "vdom=*", &res); err != nil { |
| 39 | + log.Printf("Error: %v", err) |
| 40 | + return nil, false |
| 41 | + } |
| 42 | + |
| 43 | + m := []prometheus.Metric{} |
| 44 | + for _, r := range res { |
| 45 | + for _, sdnConn := range r.Results { |
| 46 | + if sdnConn.Status == "Disabled" { |
| 47 | + m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(0), r.VDOM, sdnConn.Name, sdnConn.Type)) |
| 48 | + } else if sdnConn.Status == "Down" { |
| 49 | + m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(1), r.VDOM, sdnConn.Name, sdnConn.Type)) |
| 50 | + } else if sdnConn.Status == "Unknown" { |
| 51 | + m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(2), r.VDOM, sdnConn.Name, sdnConn.Type)) |
| 52 | + } else if sdnConn.Status == "Up" { |
| 53 | + m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(3), r.VDOM, sdnConn.Name, sdnConn.Type)) |
| 54 | + } else if sdnConn.Status == "Updating" { |
| 55 | + m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(4), r.VDOM, sdnConn.Name, sdnConn.Type)) |
| 56 | + } |
| 57 | + m = append(m, prometheus.MustNewConstMetric(SDNConnectorsLastUpdate, prometheus.GaugeValue, float64(sdnConn.LastUpdate), r.VDOM, sdnConn.Name, sdnConn.Type)) |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return m, true |
| 62 | +} |
0 commit comments