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 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_priority Priority level of the HA peer device.
38+ # TYPE fortigate_ha_peer_priority gauge
39+ fortigate_ha_peer_priority{hostname="member-name-1",master="false",primary="Unsupported",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 200
40+ fortigate_ha_peer_priority{hostname="member-name-2",master="false",primary="Unsupported",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 100
41+ `
42+
43+ if err := testutil .GatherAndCompare (r , strings .NewReader (em )); err != nil {
44+ t .Fatalf ("metric compare: err %v" , err )
45+ }
46+ }
47+
48+ func TestSystemHaPeerAfter74 (t * testing.T ) {
49+ c := newFakeClient ()
50+ c .prepare ("api/v2/monitor/system/ha-peer" , "testdata/system-ha-peer.jsonnet" )
51+ r := prometheus .NewPedanticRegistry ()
52+ meta := & TargetMetadata {
53+ VersionMajor : 7 ,
54+ VersionMinor : 4 ,
55+ }
56+ if ! testProbeWithMetadata (probeSystemHaPeer , c , meta , r ) {
57+ t .Errorf ("probeSystemHaPeer() returned non-success" )
58+ }
59+
60+ em := `
61+ # HELP fortigate_ha_peer_priority Priority level of the HA peer device.
62+ # TYPE fortigate_ha_peer_priority gauge
63+ fortigate_ha_peer_priority{hostname="member-name-1",master="false",primary="true",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 200
64+ fortigate_ha_peer_priority{hostname="member-name-2",master="false",primary="false",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 100
65+ `
66+
67+ if err := testutil .GatherAndCompare (r , strings .NewReader (em )); err != nil {
68+ t .Fatalf ("metric compare: err %v" , err )
69+ }
70+ }
0 commit comments