Skip to content

Commit

Permalink
fix: issue with OSPF state
Browse files Browse the repository at this point in the history
  • Loading branch information
benclerc committed Dec 28, 2023
1 parent 9d74331 commit c6dd223
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
18 changes: 10 additions & 8 deletions pkg/probe/ospf_neighbors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
9 changes: 8 additions & 1 deletion pkg/probe/ospf_neighbors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c6dd223

Please sign in to comment.