Skip to content

Commit 1717a62

Browse files
authored
Merge branch 'main' into feature/sdn-connector-v7.6
2 parents 1745c53 + b6c2d3c commit 1717a62

6 files changed

Lines changed: 194 additions & 0 deletions

File tree

README.md

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ To improve security, limit permissions to required ones only (least privilege pr
183183
|System/Central-management/Status | sysgrp.cfg |api/v2/monitor/system/central-management/status|
184184
|System/Fortimanager/Status | sysgrp.cfg |api/v2/monitor/system/fortimanager/status |
185185
|System/HAStatistics | sysgrp.cfg |api/v2/monitor/system/ha-statistics<br>api/v2/cmdb/system/ha |
186+
|System/Ha-peer | sysgrp.cfg |api/v2/monitor/system/ha-peer |
186187
|System/Interface | netgrp.cfg |api/v2/monitor/system/interface/select |
187188
|System/Interface/Transceivers| *any* |api/v2/monitor/system/interface/transceivers |
188189
|System/LinkMonitor | sysgrp.cfg |api/v2/monitor/system/link-monitor |

metrics.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Global:
3737
* `fortigate_system_performance_status_mem_used_bytes`
3838
* _System/HAChecksums_
3939
* `fortigate_ha_member_has_role`
40+
* _System/HAPeer_
41+
* `fortigate_ha_peer_info`
42+
* `fortigate_ha_peer_primary`
4043
* _System/Ntp/Status_
4144
* `fortigate_system_ntp_delay_seconds`
4245
* `fortigate_system_ntp_dispersion_seconds`

pkg/probe/probe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func (p *Collector) Probe(ctx context.Context, target map[string]string, hc *htt
148148
{"System/Central-Management/Status", probeSystemCentralManagementStatus},
149149
{"System/Fortimanager/Status", probeSystemFortimanagerStatus},
150150
{"System/HAStatistics", probeSystemHAStatistics},
151+
{"System/Ha-peer", probeSystemHaPeer},
151152
{"System/Interface", probeSystemInterface},
152153
{"System/Interface/Transceivers", probeSystemInterfaceTransceivers},
153154
{"System/LinkMonitor", probeSystemLinkMonitor},

pkg/probe/system_ha_peer.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
"strconv"
19+
20+
"github.com/prometheus/client_golang/prometheus"
21+
22+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
23+
)
24+
25+
func probeSystemHaPeer(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
26+
info := prometheus.NewDesc(
27+
"fortigate_ha_peer_info",
28+
"Information about the ha peer.",
29+
[]string{"serial", "vcluster", "hostname", "priority"}, nil,
30+
)
31+
32+
primary := prometheus.NewDesc(
33+
"fortigate_ha_peer_primary",
34+
"True when the peer device is the HA primary.",
35+
[]string{"vcluster", "hostname"}, nil,
36+
)
37+
38+
master := prometheus.NewDesc(
39+
"fortigate_ha_peer_master",
40+
"True when the peer device is the HA master.",
41+
[]string{"vcluster", "hostname"}, nil,
42+
)
43+
44+
type SystemHaPeer struct {
45+
Serial string `json:"serial_no"`
46+
Vcluster int64 `json:"vcluster_id"`
47+
Priority float64 `json:"priority"`
48+
Hostname string `json:"hostname"`
49+
Master bool `json:"master"`
50+
Primary bool `json:"primary"`
51+
}
52+
53+
type SystemHaPeerResult struct {
54+
Result []SystemHaPeer `json:"results"`
55+
}
56+
57+
var res SystemHaPeerResult
58+
if err := c.Get("api/v2/monitor/system/ha-peer", "", &res); err != nil {
59+
log.Printf("Warning: %v", err)
60+
return nil, false
61+
}
62+
m := []prometheus.Metric{}
63+
for _, r := range res.Result {
64+
if meta.VersionMajor >= 7 && meta.VersionMinor >= 4 {
65+
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)))
66+
if r.Primary {
67+
m = append(m, prometheus.MustNewConstMetric(primary, prometheus.GaugeValue, 1, strconv.FormatInt(r.Vcluster, 10), r.Hostname))
68+
} else {
69+
m = append(m, prometheus.MustNewConstMetric(primary, prometheus.GaugeValue, 0, strconv.FormatInt(r.Vcluster, 10), r.Hostname))
70+
}
71+
if meta.VersionMinor == 4 {
72+
if r.Master {
73+
m = append(m, prometheus.MustNewConstMetric(master, prometheus.GaugeValue, 1, strconv.FormatInt(r.Vcluster, 10), r.Hostname))
74+
} else {
75+
m = append(m, prometheus.MustNewConstMetric(master, prometheus.GaugeValue, 0, strconv.FormatInt(r.Vcluster, 10), r.Hostname))
76+
}
77+
}
78+
} else {
79+
m = append(m, prometheus.MustNewConstMetric(info, prometheus.GaugeValue, -1, "None", "0", "None", "false"))
80+
break
81+
}
82+
}
83+
return m, true
84+
}

pkg/probe/system_ha_peer_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
"strings"
18+
"testing"
19+
20+
"github.com/prometheus/client_golang/prometheus"
21+
"github.com/prometheus/client_golang/prometheus/testutil"
22+
)
23+
24+
func TestSystemHaPeerOld(t *testing.T) {
25+
c := newFakeClient()
26+
c.prepare("api/v2/monitor/system/ha-peer", "testdata/system-ha-peer.jsonnet")
27+
r := prometheus.NewPedanticRegistry()
28+
meta := &TargetMetadata{
29+
VersionMajor: 7,
30+
VersionMinor: 0,
31+
}
32+
if !testProbeWithMetadata(probeSystemHaPeer, c, meta, r) {
33+
t.Errorf("probeSystemHaPeer() returned non-success")
34+
}
35+
36+
em := `
37+
# HELP fortigate_ha_peer_info Information about the ha peer.
38+
# TYPE fortigate_ha_peer_info gauge
39+
fortigate_ha_peer_info{hostname="None",priority="false",serial="None",vcluster="0"} -1
40+
`
41+
42+
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
43+
t.Fatalf("metric compare: err %v", err)
44+
}
45+
}
46+
47+
func TestSystemHaPeerAfter74(t *testing.T) {
48+
c := newFakeClient()
49+
c.prepare("api/v2/monitor/system/ha-peer", "testdata/system-ha-peer.jsonnet")
50+
r := prometheus.NewPedanticRegistry()
51+
meta := &TargetMetadata{
52+
VersionMajor: 7,
53+
VersionMinor: 4,
54+
}
55+
if !testProbeWithMetadata(probeSystemHaPeer, c, meta, r) {
56+
t.Errorf("probeSystemHaPeer() returned non-success")
57+
}
58+
59+
em := `
60+
# HELP fortigate_ha_peer_info Information about the ha peer.
61+
# TYPE fortigate_ha_peer_info gauge
62+
fortigate_ha_peer_info{hostname="member-name-1",priority="200",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 1
63+
fortigate_ha_peer_info{hostname="member-name-2",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 1
64+
# HELP fortigate_ha_peer_master True when the peer device is the HA master.
65+
# TYPE fortigate_ha_peer_master gauge
66+
fortigate_ha_peer_master{hostname="member-name-1",vcluster="0"} 0
67+
fortigate_ha_peer_master{hostname="member-name-2",vcluster="0"} 1
68+
# HELP fortigate_ha_peer_primary True when the peer device is the HA primary.
69+
# TYPE fortigate_ha_peer_primary gauge
70+
fortigate_ha_peer_primary{hostname="member-name-1",vcluster="0"} 1
71+
fortigate_ha_peer_primary{hostname="member-name-2",vcluster="0"} 0
72+
`
73+
74+
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
75+
t.Fatalf("metric compare: err %v", err)
76+
}
77+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# api/v2/monitor/system/ha-peer
2+
{
3+
"http_method":"GET",
4+
"results":[
5+
{
6+
"serial_no":"FGT61E4QXXXXXXXX1",
7+
"vcluster_id":0,
8+
"priority":200,
9+
"hostname":"member-name-1",
10+
"primary":true
11+
},
12+
{
13+
"serial_no":"FGT61E4QXXXXXXXX2",
14+
"vcluster_id":0,
15+
"priority":100,
16+
"hostname":"member-name-2",
17+
"master": true
18+
}
19+
],
20+
"vdom":"root",
21+
"path":"system",
22+
"name":"ha-peer",
23+
"action":"",
24+
"status":"success",
25+
"serial":"FGT61E4QXXXXXXXX1",
26+
"version":"v7.4.0",
27+
"build":700
28+
}

0 commit comments

Comments
 (0)