-
Notifications
You must be signed in to change notification settings - Fork 119
Feature/system ha peer #347
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
bastischubert
merged 13 commits into
prometheus-community:main
from
Philldomd:feature/system-ha-peer
Feb 23, 2026
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a0f2dfc
System ha peer information added
Philldomd a070fe7
Corrected data
Philldomd e9d7607
Merge branch 'main' into feature/system-ha-peer
Philldomd d57c678
Correct state metrics
Philldomd e4c32bb
Merge branch 'main' into feature/system-ha-peer
Philldomd 4076976
Lint
Philldomd 8233b94
Merge branch 'main' into feature/system-ha-peer
Philldomd 2e5b08f
Merge branch 'main' into feature/system-ha-peer
Philldomd 404c0d5
New metrics for ha peer
Philldomd 1f7702b
Merge branch 'main' into feature/system-ha-peer
Philldomd 55df8e4
Removed year in copyright, removed public variables
Philldomd 298cea8
Added master back if minor version is equal to 4
Philldomd 4acf12c
Merge branch 'main' into feature/system-ha-peer
bastischubert 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
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,71 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
|
Philldomd marked this conversation as resolved.
Outdated
|
||
| // 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/client_golang/prometheus" | ||
|
|
||
| "github.com/prometheus-community/fortigate_exporter/pkg/http" | ||
| ) | ||
|
|
||
| func probeSystemHaPeer(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) { | ||
| Info := prometheus.NewDesc( | ||
|
Philldomd marked this conversation as resolved.
Outdated
|
||
| "fortigate_ha_peer_info", | ||
| "Information about the ha peer.", | ||
| []string{"serial", "vcluster", "hostname", "priority"}, nil, | ||
| ) | ||
|
|
||
| Primary := prometheus.NewDesc( | ||
|
Philldomd marked this conversation as resolved.
Outdated
|
||
| "fortigate_ha_peer_primary", | ||
| "True when the peer device is the HA primary.", | ||
| []string{"vcluster", "hostname"}, nil, | ||
| ) | ||
|
|
||
| type SystemHaPeer struct { | ||
| Serial string `json:"serial_no"` | ||
| Vcluster int64 `json:"vcluster_id"` | ||
| Priority float64 `json:"priority"` | ||
| Hostname string `json:"hostname"` | ||
| Master bool `json:"master"` | ||
| Primary bool `json:"primary"` | ||
| } | ||
|
|
||
| type SystemHaPeerResult struct { | ||
| Result []SystemHaPeer `json:"results"` | ||
| } | ||
|
|
||
| var res SystemHaPeerResult | ||
| if err := c.Get("api/v2/monitor/system/ha-peer", "", &res); err != nil { | ||
| log.Printf("Warning: %v", err) | ||
| return nil, false | ||
| } | ||
| m := []prometheus.Metric{} | ||
| for _, r := range res.Result { | ||
| if meta.VersionMajor >= 7 && meta.VersionMinor >= 4 { | ||
| m = append(m, prometheus.MustNewConstMetric(Info, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatFloat(r.Priority, 'f', -1, 64))) | ||
| if r.Primary { | ||
| m = append(m, prometheus.MustNewConstMetric(Primary, prometheus.GaugeValue, 1, strconv.FormatInt(r.Vcluster, 10), r.Hostname)) | ||
| } else { | ||
| m = append(m, prometheus.MustNewConstMetric(Primary, prometheus.GaugeValue, 0, strconv.FormatInt(r.Vcluster, 10), r.Hostname)) | ||
| } | ||
| } else { | ||
| m = append(m, prometheus.MustNewConstMetric(Info, prometheus.GaugeValue, -1, "None", "0", "None", "false")) | ||
| break | ||
| } | ||
| } | ||
| 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,73 @@ | ||
| // Copyright 2025 The Prometheus Authors | ||
|
Philldomd marked this conversation as resolved.
Outdated
|
||
| // 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 TestSystemHaPeerOld(t *testing.T) { | ||
| c := newFakeClient() | ||
| c.prepare("api/v2/monitor/system/ha-peer", "testdata/system-ha-peer.jsonnet") | ||
| r := prometheus.NewPedanticRegistry() | ||
| meta := &TargetMetadata{ | ||
| VersionMajor: 7, | ||
| VersionMinor: 0, | ||
| } | ||
| if !testProbeWithMetadata(probeSystemHaPeer, c, meta, r) { | ||
| t.Errorf("probeSystemHaPeer() returned non-success") | ||
| } | ||
|
|
||
| em := ` | ||
| # HELP fortigate_ha_peer_info Information about the ha peer. | ||
| # TYPE fortigate_ha_peer_info gauge | ||
| fortigate_ha_peer_info{hostname="None",priority="false",serial="None",vcluster="0"} -1 | ||
| ` | ||
|
|
||
| if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
| t.Fatalf("metric compare: err %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestSystemHaPeerAfter74(t *testing.T) { | ||
| c := newFakeClient() | ||
| c.prepare("api/v2/monitor/system/ha-peer", "testdata/system-ha-peer.jsonnet") | ||
| r := prometheus.NewPedanticRegistry() | ||
| meta := &TargetMetadata{ | ||
| VersionMajor: 7, | ||
| VersionMinor: 4, | ||
| } | ||
| if !testProbeWithMetadata(probeSystemHaPeer, c, meta, r) { | ||
| t.Errorf("probeSystemHaPeer() returned non-success") | ||
| } | ||
|
|
||
| em := ` | ||
| # HELP fortigate_ha_peer_info Information about the ha peer. | ||
| # TYPE fortigate_ha_peer_info gauge | ||
| fortigate_ha_peer_info{hostname="member-name-1",priority="200",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 1 | ||
| fortigate_ha_peer_info{hostname="member-name-2",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 1 | ||
| # HELP fortigate_ha_peer_primary True when the peer device is the HA primary. | ||
| # TYPE fortigate_ha_peer_primary gauge | ||
| fortigate_ha_peer_primary{hostname="member-name-1",vcluster="0"} 1 | ||
| fortigate_ha_peer_primary{hostname="member-name-2",vcluster="0"} 0 | ||
| ` | ||
|
|
||
| if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil { | ||
| t.Fatalf("metric compare: err %v", err) | ||
| } | ||
| } | ||
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,27 @@ | ||
| # api/v2/monitor/system/ha-peer | ||
| { | ||
| "http_method":"GET", | ||
| "results":[ | ||
| { | ||
| "serial_no":"FGT61E4QXXXXXXXX1", | ||
| "vcluster_id":0, | ||
| "priority":200, | ||
| "hostname":"member-name-1", | ||
| "primary":true | ||
| }, | ||
| { | ||
| "serial_no":"FGT61E4QXXXXXXXX2", | ||
| "vcluster_id":0, | ||
| "priority":100, | ||
| "hostname":"member-name-2" | ||
| } | ||
| ], | ||
| "vdom":"root", | ||
| "path":"system", | ||
| "name":"ha-peer", | ||
| "action":"", | ||
| "status":"success", | ||
| "serial":"FGT61E4QXXXXXXXX1", | ||
| "version":"v7.4.0", | ||
| "build":700 | ||
| } |
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.