Skip to content

Commit 99e11c0

Browse files
authored
fix(probe): correct OSPF state enum
1 parent 9d74331 commit 99e11c0

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

Diff for: pkg/probe/ospf_neighbors.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,23 @@ func probeOSPFNeighbors(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Me
5454

5555
func ospfStateToNumber(ospfState string) float64 {
5656
switch ospfState {
57-
case "Attempt":
57+
case "Down":
5858
return 1
59-
case "Init":
59+
case "Attempt":
6060
return 2
61-
case "Two way":
61+
case "Init":
6262
return 3
63-
case "Exchange start":
63+
case "Two way":
6464
return 4
65-
case "Exchange":
65+
case "Exchange start":
6666
return 5
67-
case "Loading":
67+
case "Exchange":
6868
return 6
69-
case "Full":
69+
case "Loading":
7070
return 7
71+
case "Full":
72+
return 8
7173
default: // Down
72-
return 0
74+
return 1
7375
}
7476
}

Diff for: pkg/probe/ospf_neighbors_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ func TestOSPFNeighborsIPv4(t *testing.T) {
1919
em := `
2020
# 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)
2121
# TYPE fortigate_ospf_neighbor_info gauge
22-
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.1",priority="3",router_id="12345",state="Full",vdom="root"} 7
22+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.1",priority="3",router_id="12341",state="Down",vdom="root"} 1
23+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.2",priority="3",router_id="12342",state="Attempt",vdom="root"} 2
24+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.3",priority="3",router_id="12343",state="Init",vdom="root"} 3
25+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.4",priority="3",router_id="12344",state="Two way",vdom="root"} 4
26+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.5",priority="3",router_id="12345",state="Exchange start",vdom="root"} 5
27+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.6",priority="3",router_id="12346",state="Exchange",vdom="root"} 6
28+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.7",priority="3",router_id="12347",state="Loading",vdom="root"} 7
29+
fortigate_ospf_neighbor_info{neighbor_ip="10.0.0.8",priority="3",router_id="12348",state="Full",vdom="root"} 8
2330
`
2431

2532
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {

Diff for: pkg/probe/testdata/router-ospf-neighbors.jsonnet

+43-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,50 @@
66
{
77
"neighbor_ip":"10.0.0.1",
88
"priority":3,
9-
"state":"Full",
9+
"state":"Down",
10+
"router_id":"12341"
11+
},
12+
{
13+
"neighbor_ip":"10.0.0.2",
14+
"priority":3,
15+
"state":"Attempt",
16+
"router_id":"12342"
17+
},
18+
{
19+
"neighbor_ip":"10.0.0.3",
20+
"priority":3,
21+
"state":"Init",
22+
"router_id":"12343"
23+
},
24+
{
25+
"neighbor_ip":"10.0.0.4",
26+
"priority":3,
27+
"state":"Two way",
28+
"router_id":"12344"
29+
},
30+
{
31+
"neighbor_ip":"10.0.0.5",
32+
"priority":3,
33+
"state":"Exchange start",
1034
"router_id":"12345"
35+
},
36+
{
37+
"neighbor_ip":"10.0.0.6",
38+
"priority":3,
39+
"state":"Exchange",
40+
"router_id":"12346"
41+
},
42+
{
43+
"neighbor_ip":"10.0.0.7",
44+
"priority":3,
45+
"state":"Loading",
46+
"router_id":"12347"
47+
},
48+
{
49+
"neighbor_ip":"10.0.0.8",
50+
"priority":3,
51+
"state":"Full",
52+
"router_id":"12348"
1153
}
1254
],
1355
"vdom":"root",

0 commit comments

Comments
 (0)