-
Notifications
You must be signed in to change notification settings - Fork 119
Central management status added #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SuperQ
merged 7 commits into
prometheus-community:main
from
Philldomd:feature/system-central-management-status
Nov 14, 2025
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bbd5bdd
Central management status added
Philldomd af6e0f6
Enum sets
Philldomd 299d05b
Update pkg/probe/system_central_management.go
Philldomd 8bc89ce
Reworked metrics to fit state
Philldomd c22b243
Merge branch 'main' into feature/system-central-management-status
Philldomd fcc83dc
Lint
Philldomd 981aa51
Merge branch 'main' into feature/system-central-management-status
Philldomd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "log" | ||
| "strconv" | ||
|
|
||
| "github.com/prometheus-community/fortigate_exporter/pkg/http" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| func probeSystemCentralManagementStatus (c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { | ||
| var ( | ||
| mode = prometheus.NewDesc( | ||
| "fortigate_system_central_management_mode", | ||
| "Operating mode of the central management. (Normal = 1, Backup = 0)", | ||
| []string{"server", "mgmt_ip", "mgmt_port", "sn", "pendfortman"}, nil, | ||
| ) | ||
| status = prometheus.NewDesc( | ||
| "fortigate_system_central_management_status", | ||
| "Status of the connection from FortiGate to the central management server. (down = 0, up = 1, handshake = 2)", | ||
| []string{"server", "mgmt_ip", "mgmt_port", "sn", "pendfortman"}, nil, | ||
| ) | ||
| registration_status = prometheus.NewDesc( | ||
| "fortigate_system_central_management_registration_status", | ||
| "Status of the registration from FortiGate to the central management server. (unknown = -1, in_progress = 2, registered = 1, unregistered = 0)", | ||
| []string{"server", "mgmt_ip", "mgmt_port", "sn", "pendfortman"}, nil, | ||
| ) | ||
| ) | ||
|
|
||
| type centralManagementStatus struct { | ||
| Mode string `json:"mode"` | ||
| Server string `json:"server"` | ||
| Status string `json:"status"` | ||
| RegStat string `json:"registration_status"` | ||
| MgmtIp string `json:"mgmt_ip"` | ||
| MgmtPort float64 `json:"mgmt_port"` | ||
| Sn string `json:"sn"` | ||
| PenFortMan string `json:"pending_fortimanager"` | ||
| } | ||
|
|
||
| type centralManagementStatusResult struct { | ||
| Result centralManagementStatus `json:"results"` | ||
| } | ||
|
|
||
| var res centralManagementStatusResult | ||
| if err := c.Get("api/v2/monitor/system/central-management/status", "skip_detect=true", &res); err != nil { | ||
| log.Printf("Error: %v", err) | ||
| return nil, false | ||
| } | ||
|
|
||
| m := []prometheus.Metric{} | ||
| if res.Result.Mode == "normal" { | ||
| m = append(m, prometheus.MustNewConstMetric(mode, prometheus.GaugeValue, 1, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| } else { | ||
| m = append(m, prometheus.MustNewConstMetric(mode, prometheus.GaugeValue, 0, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| } | ||
| switch res.Result.Status { | ||
| case "down": | ||
| m = append(m, prometheus.MustNewConstMetric(status, prometheus.GaugeValue, 0, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| case "up": | ||
| m = append(m, prometheus.MustNewConstMetric(status, prometheus.GaugeValue, 1, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| case "handshake": | ||
| m = append(m, prometheus.MustNewConstMetric(status, prometheus.GaugeValue, 2, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| } | ||
| switch res.Result.RegStat { | ||
| case "in_progress": | ||
| m = append(m, prometheus.MustNewConstMetric(registration_status, prometheus.GaugeValue, 2, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| case "registered": | ||
| m = append(m, prometheus.MustNewConstMetric(registration_status, prometheus.GaugeValue, 1, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| case "unregistered": | ||
| m = append(m, prometheus.MustNewConstMetric(registration_status, prometheus.GaugeValue, 0, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| default: | ||
| m = append(m, prometheus.MustNewConstMetric(registration_status, prometheus.GaugeValue, -1, res.Result.Server, res.Result.MgmtIp, strconv.FormatFloat(res.Result.MgmtPort, 'f', -1, 64), res.Result.Sn, res.Result.PenFortMan)) | ||
| } | ||
| return m, true | ||
| } | ||
This file contains hidden or 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,47 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| ) | ||
|
|
||
| func TestSystemCentralManagementStatus(t *testing.T) { | ||
| c := newFakeClient() | ||
| c.prepare("api/v2/monitor/system/central-management/status", "testdata/system-central-management-status.jsonnet") | ||
| r := prometheus.NewPedanticRegistry() | ||
| if !testProbe(probeSystemCentralManagementStatus, c, r) { | ||
| t.Errorf("probeSystemCentralManagementStatus() returned non-success") | ||
| } | ||
|
|
||
| em := ` | ||
| # HELP fortigate_system_central_management_mode Operating mode of the central management. (Normal = 1, Backup = 0) | ||
| # TYPE fortigate_system_central_management_mode gauge | ||
| fortigate_system_central_management_mode{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748"} 1 | ||
| # HELP fortigate_system_central_management_registration_status Status of the registration from FortiGate to the central management server. (unknown = -1, in_progress = 2, registered = 1, unregistered = 0) | ||
| # TYPE fortigate_system_central_management_registration_status gauge | ||
| fortigate_system_central_management_registration_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748"} -1 | ||
| # HELP fortigate_system_central_management_status Status of the connection from FortiGate to the central management server. (down = 0, up = 1, handshake = 2) | ||
| # TYPE fortigate_system_central_management_status gauge | ||
| fortigate_system_central_management_status{mgmt_ip="127.0.0.1",mgmt_port="0",pendfortman="12.329845.45k3",server="HA-TEST",sn="121748"} 0 | ||
| ` | ||
|
|
||
| if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
| t.Fatalf("metric compare: err %v", err) | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
pkg/probe/testdata/system-central-management-status.jsonnet
This file contains hidden or 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,21 @@ | ||
| { | ||
| "http_method":"GET", | ||
| "results":{ | ||
| "mode": "normal", | ||
| "server": "HA-TEST", | ||
| "status": "down", | ||
| "registration_status": "unknown", | ||
| "mgmt_ip": "127.0.0.1", | ||
| "mgmt_port": 0, | ||
| "sn": "121748", | ||
| "pending_fortimanager": "12.329845.45k3" | ||
| }, | ||
| "vdom":"root", | ||
| "path":"system", | ||
| "name":"fortimanager", | ||
| "action":"status", | ||
| "status":"success", | ||
| "serial":"FGT61FT000000000", | ||
| "version":"v6.0.10", | ||
| "build":365 | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.