From c6dd223201505d05d40d5a4980cf1e388850cfd6 Mon Sep 17 00:00:00 2001 From: Benjamin Clerc <79925489+benclerc@users.noreply.github.com> Date: Thu, 28 Dec 2023 16:56:45 +0100 Subject: [PATCH] fix: issue with OSPF state --- pkg/probe/ospf_neighbors.go | 18 ++++++++++-------- pkg/probe/ospf_neighbors_test.go | 9 ++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/probe/ospf_neighbors.go b/pkg/probe/ospf_neighbors.go index e539cb0..4925d7c 100644 --- a/pkg/probe/ospf_neighbors.go +++ b/pkg/probe/ospf_neighbors.go @@ -54,21 +54,23 @@ func probeOSPFNeighbors(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Me func ospfStateToNumber(ospfState string) float64 { switch ospfState { - case "Attempt": + case "Down": return 1 - case "Init": + case "Attempt": return 2 - case "Two way": + case "Init": return 3 - case "Exchange start": + case "Two way": return 4 - case "Exchange": + case "Exchange start": return 5 - case "Loading": + case "Exchange": return 6 - case "Full": + case "Loading": return 7 + case "Full": + return 8 default: // Down - return 0 + return 1 } } diff --git a/pkg/probe/ospf_neighbors_test.go b/pkg/probe/ospf_neighbors_test.go index 246a44d..a3fe424 100644 --- a/pkg/probe/ospf_neighbors_test.go +++ b/pkg/probe/ospf_neighbors_test.go @@ -19,7 +19,14 @@ func TestOSPFNeighborsIPv4(t *testing.T) { em := ` # HELP fortigate_ospf_neighbor_info List all discovered OSPF neighbors, return state as value (1 - Down, 2 - Attempt, 3 - Init, 4 - Two way, 5 - Exchange start, 6 - Exchange, 7 - Loading, 8 - Full) # TYPE fortigate_ospf_neighbor_info gauge - fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.1",priority="3",router_id="12345",state="Full",vdom="root"} 7 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.1",priority="3",router_id="12345",state="Down",vdom="root"} 1 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.2",priority="3",router_id="12345",state="Attempt",vdom="root"} 2 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.3",priority="3",router_id="12345",state="Init",vdom="root"} 3 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.4",priority="3",router_id="12345",state="Two way",vdom="root"} 4 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.5",priority="3",router_id="12345",state="Exchange start",vdom="root"} 5 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.6",priority="3",router_id="12345",state="Exchange",vdom="root"} 6 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.7",priority="3",router_id="12345",state="Loading",vdom="root"} 7 + fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.8",priority="3",router_id="12345",state="Full",vdom="root"} 8 ` if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {