|
| 1 | +// Copyright The Prometheus Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +package probe |
| 15 | + |
| 16 | +import ( |
| 17 | + "log" |
| 18 | + |
| 19 | + "github.com/prometheus/client_golang/prometheus" |
| 20 | + |
| 21 | + "github.com/prometheus-community/fortigate_exporter/pkg/http" |
| 22 | +) |
| 23 | + |
| 24 | +func probeSystemSandboxConnection(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) { |
| 25 | + connectionStatusDisable := prometheus.NewDesc( |
| 26 | + "fortigate_sandbox_connection_status_disabled", |
| 27 | + "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 | + |
| 41 | + type SystemSandboxConnection struct { |
| 42 | + Status string `json:"status"` |
| 43 | + Type string `json:"type"` |
| 44 | + } |
| 45 | + |
| 46 | + type SystemSandboxConnectionResult struct { |
| 47 | + Results []SystemSandboxConnection `json:"results"` |
| 48 | + } |
| 49 | + var res SystemSandboxConnectionResult |
| 50 | + if err := c.Get("api/v2/monitor/system/sandbox/connection", "", &res); err != nil { |
| 51 | + log.Printf("Warning: %v", err) |
| 52 | + return nil, false |
| 53 | + } |
| 54 | + |
| 55 | + m := []prometheus.Metric{} |
| 56 | + for _, r := range res.Results { |
| 57 | + switch r.Status { |
| 58 | + case "unreachable": |
| 59 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 1, r.Type)) |
| 60 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 0, r.Type)) |
| 61 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 0, r.Type)) |
| 62 | + case "reachable": |
| 63 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 0, r.Type)) |
| 64 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 1, r.Type)) |
| 65 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 0, r.Type)) |
| 66 | + case "disabled": |
| 67 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusUreachable, prometheus.GaugeValue, 0, r.Type)) |
| 68 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusReachable, prometheus.GaugeValue, 0, r.Type)) |
| 69 | + m = append(m, prometheus.MustNewConstMetric(connectionStatusDisable, prometheus.GaugeValue, 1, r.Type)) |
| 70 | + } |
| 71 | + } |
| 72 | + return m, true |
| 73 | +} |
0 commit comments