Skip to content

Commit d8fda54

Browse files
PhilldomdSuperQ
andauthored
Central management status added (#337)
* Central management status added --------- Signed-off-by: Örnfeldt Philip (66140321) <[email protected]> Signed-off-by: Philip Örnfeldt <[email protected]> Signed-off-by: Philip Örnfeldt <[email protected]> Co-authored-by: Ben Kochie <[email protected]>
1 parent 9be60e4 commit d8fda54

File tree

5 files changed

+180
-0
lines changed

5 files changed

+180
-0
lines changed

README.md

100755100644
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ Per-VDOM:
123123
* _System/SDNConnector_
124124
* `fortigate_system_sdn_connector_status`
125125
* `fortigate_system_sdn_connector_last_update_seconds`
126+
* _/System/CentralManagement/Status_
127+
* `fortigate_system_central_management_mode`
128+
* `fortigate_system_central_management_status`
129+
* `fortigate_system_central_management_registration_status`
126130
* _System/VDOMResource_
127131
* `fortigate_vdom_resource_cpu_usage`
128132
* `fortigate_vdom_resource_memory_usage`
@@ -459,6 +463,7 @@ To improve security, limit permissions to required ones only (least privilege pr
459463
|Log/DiskUsage | loggrp.config |api/v2/monitor/log/current-disk-usage |
460464
|Network/Dns/Latency | sysgrp.cfg |api/v2/monitor/network/dns/latency |
461465
|System/AvailableCertificates | *any* |api/v2/monitor/system/available-certificates |
466+
|System/Central-management/Status | sysgrp.cfg |api/v2/monitor/system/central-management/status|
462467
|System/Fortimanager/Status | sysgrp.cfg |api/v2/monitor/system/fortimanager/status |
463468
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |
464469
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |

pkg/probe/probe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
145145
{"Log/DiskUsage", probeLogCurrentDiskUsage},
146146
{"Network/Dns/Latency", probeNetworkDNSLatency},
147147
{"System/AvailableCertificates", probeSystemAvailableCertificates},
148+
{"System/Central-Management/Status", probeSystemCentralManagementStatus},
148149
{"System/Fortimanager/Status", probeSystemFortimanagerStatus},
149150
{"System/HAStatistics", probeSystemHAStatistics},
150151
{"System/Interface", probeSystemInterface},
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2025 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+
"strconv"
19+
20+
"github.com/prometheus/client_golang/prometheus"
21+
22+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
23+
)
24+
25+
func probeSystemCentralManagementStatus(c http.FortiHTTP, _ *TargetMetadata) ([]prometheus.Metric, bool) {
26+
var (
27+
mode = prometheus.NewDesc(
28+
"fortigate_system_central_management_mode",
29+
"Operating mode of the central management.",
30+
[]string{"mode", "server", "mgmt_ip", "mgmt_port", "sn", "pendfortman"}, nil,
31+
)
32+
status = prometheus.NewDesc(
33+
"fortigate_system_central_management_status",
34+
"Status of the connection from FortiGate to the central management server.",
35+
[]string{"status", "server", "mgmt_ip", "mgmt_port", "sn", "pendfortman"}, nil,
36+
)
37+
registrationStatus = prometheus.NewDesc(
38+
"fortigate_system_central_management_registration_status",
39+
"Status of the registration from FortiGate to the central management server.",
40+
[]string{"status", "server", "mgmt_ip", "mgmt_port", "sn", "pendfortman"}, nil,
41+
)
42+
)
43+
44+
type centralManagementStatus struct {
45+
Mode string `json:"mode"`
46+
Server string `json:"server"`
47+
Status string `json:"status"`
48+
RegStat string `json:"registration_status"`
49+
MgmtIP string `json:"mgmt_ip"`
50+
MgmtPort float64 `json:"mgmt_port"`
51+
Sn string `json:"sn"`
52+
PenFortMan string `json:"pending_fortimanager"`
53+
}
54+
55+
type centralManagementStatusResult struct {
56+
Result centralManagementStatus `json:"results"`
57+
}
58+
59+
var res centralManagementStatusResult
60+
if err := c.Get("api/v2/monitor/system/central-management/status", "skip_detect=true", &res); err != nil {
61+
log.Printf("Error: %v", err)
62+
return nil, false
63+
}
64+
65+
m := []prometheus.Metric{}
66+
var normal, backup, down, up, handshake, inProgress, registered, unregistered, defaultValue float64
67+
if res.Result.Mode == "normal" {
68+
normal = 1
69+
} else {
70+
backup = 1
71+
}
72+
switch res.Result.Status {
73+
case "down":
74+
down = 1
75+
case "up":
76+
up = 1
77+
case "handshake":
78+
handshake = 1
79+
}
80+
switch res.Result.RegStat {
81+
case "in_progress":
82+
inProgress = 1
83+
case "registered":
84+
registered = 1
85+
case "unregistered":
86+
unregistered = 1
87+
default:
88+
defaultValue = 1
89+
}
90+
m = append(m, prometheus.MustNewConstMetric(mode, prometheus.GaugeValue, normal, "normal", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
91+
m = append(m, prometheus.MustNewConstMetric(mode, prometheus.GaugeValue, backup, "backup", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
92+
m = append(m, prometheus.MustNewConstMetric(status, prometheus.GaugeValue, down, "down", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
93+
m = append(m, prometheus.MustNewConstMetric(status, prometheus.GaugeValue, up, "up", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
94+
m = append(m, prometheus.MustNewConstMetric(status, prometheus.GaugeValue, handshake, "handshake", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
95+
m = append(m, prometheus.MustNewConstMetric(registrationStatus, prometheus.GaugeValue, inProgress, "inprogress", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
96+
m = append(m, prometheus.MustNewConstMetric(registrationStatus, prometheus.GaugeValue, registered, "registered", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
97+
m = append(m, prometheus.MustNewConstMetric(registrationStatus, prometheus.GaugeValue, unregistered, "unregistered", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
98+
m = append(m, prometheus.MustNewConstMetric(registrationStatus, prometheus.GaugeValue, defaultValue, "unknown", res.Result.Server, res.Result.MgmtIP, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan))
99+
100+
return m, true
101+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2025 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+
"strings"
18+
"testing"
19+
20+
"github.com/prometheus/client_golang/prometheus"
21+
"github.com/prometheus/client_golang/prometheus/testutil"
22+
)
23+
24+
func TestSystemCentralManagementStatus(t *testing.T) {
25+
c := newFakeClient()
26+
c.prepare("api/v2/monitor/system/central-management/status", "testdata/system-central-management-status.jsonnet")
27+
r := prometheus.NewPedanticRegistry()
28+
if !testProbe(probeSystemCentralManagementStatus, c, r) {
29+
t.Errorf("probeSystemCentralManagementStatus() returned non-success")
30+
}
31+
32+
em := `# HELP fortigate_system_central_management_mode Operating mode of the central management.
33+
# TYPE fortigate_system_central_management_mode gauge
34+
fortigate_system_central_management_mode{mgmt_ip="127.0.0.1",mgmt_port="0",mode="backup",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748"} 0
35+
fortigate_system_central_management_mode{mgmt_ip="127.0.0.1",mgmt_port="0",mode="normal",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748"} 1
36+
# HELP fortigate_system_central_management_registration_status Status of the registration from FortiGate to the central management server.
37+
# TYPE fortigate_system_central_management_registration_status gauge
38+
fortigate_system_central_management_registration_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748",status="inprogress"} 0
39+
fortigate_system_central_management_registration_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748",status="registered"} 0
40+
fortigate_system_central_management_registration_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748",status="unknown"} 1
41+
fortigate_system_central_management_registration_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748",status="unregistered"} 0
42+
# HELP fortigate_system_central_management_status Status of the connection from FortiGate to the central management server.
43+
# TYPE fortigate_system_central_management_status gauge
44+
fortigate_system_central_management_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748",status="down"} 1
45+
fortigate_system_central_management_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748",status="handshake"} 0
46+
fortigate_system_central_management_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748",status="up"} 0
47+
`
48+
49+
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
50+
t.Fatalf("metric compare: err %v", err)
51+
}
52+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"http_method":"GET",
3+
"results":{
4+
"mode": "normal",
5+
"server": "HA-TEST",
6+
"status": "down",
7+
"registration_status": "unknown",
8+
"mgmt_ip": "127.0.0.1",
9+
"mgmt_port": 0,
10+
"sn": "121748",
11+
"pending_fortimanager": "12.329845.45k3"
12+
},
13+
"vdom":"root",
14+
"path":"system",
15+
"name":"fortimanager",
16+
"action":"status",
17+
"status":"success",
18+
"serial":"FGT61FT000000000",
19+
"version":"v6.0.10",
20+
"build":365
21+
}

0 commit comments

Comments
 (0)