Skip to content

Commit 8a6f0b3

Browse files
33Fraise33Gianni Stubbe
and
Gianni Stubbe
authored
feat(probe): BGP session state as value (#237)
* fix(BGP Info): Added support for bgp session state as value next to label * test(bgp): Updated tests to account for new value * test(bgp): Also change metric description in tests --------- Co-authored-by: Gianni Stubbe <[email protected]>
1 parent b26fdb4 commit 8a6f0b3

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

Diff for: pkg/probe/bgp_neighbors.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func probeBGPNeighborsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
3030
var (
3131
mBGPNeighbor = prometheus.NewDesc(
3232
"fortigate_bgp_neighbor_ipv4_info",
33-
"Configured bgp neighbor over ipv4",
33+
"Configured bgp neighbor over ipv4, return state as value (1 - Idle, 2 - Connect, 3 - Active, 4 - Open sent, 5 - Open confirm, 6 - Established)",
3434
[]string{"vdom", "remote_as", "state", "admin_status", "local_ip", "neighbor_ip"}, nil,
3535
)
3636
)
@@ -46,7 +46,7 @@ func probeBGPNeighborsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
4646

4747
for _, r := range rs {
4848
for _, peer := range r.Results {
49-
m = append(m, prometheus.MustNewConstMetric(mBGPNeighbor, prometheus.GaugeValue, 1, r.VDOM, strconv.Itoa(peer.RemoteAS), peer.State, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP))
49+
m = append(m, prometheus.MustNewConstMetric(mBGPNeighbor, prometheus.GaugeValue, bgpStateToNumber(peer.State), r.VDOM, strconv.Itoa(peer.RemoteAS), peer.State, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP))
5050
}
5151
}
5252

@@ -62,7 +62,7 @@ func probeBGPNeighborsIPv6(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
6262
var (
6363
mBGPNeighbor = prometheus.NewDesc(
6464
"fortigate_bgp_neighbor_ipv6_info",
65-
"Configured bgp neighbor over ipv6",
65+
"Configured bgp neighbor over ipv6, return state as value (1 - Idle, 2 - Connect, 3 - Active, 4 - Open sent, 5 - Open confirm, 6 - Established)",
6666
[]string{"vdom", "remote_as", "state", "admin_status", "local_ip", "neighbor_ip"}, nil,
6767
)
6868
)
@@ -78,9 +78,28 @@ func probeBGPNeighborsIPv6(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
7878

7979
for _, r := range rs {
8080
for _, peer := range r.Results {
81-
m = append(m, prometheus.MustNewConstMetric(mBGPNeighbor, prometheus.GaugeValue, 1, r.VDOM, strconv.Itoa(peer.RemoteAS), peer.State, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP))
81+
m = append(m, prometheus.MustNewConstMetric(mBGPNeighbor, prometheus.GaugeValue, bgpStateToNumber(peer.State), r.VDOM, strconv.Itoa(peer.RemoteAS), peer.State, strconv.FormatBool(peer.AdminStatus), peer.LocalIP, peer.NeighborIP))
8282
}
8383
}
8484

8585
return m, true
8686
}
87+
88+
func bgpStateToNumber(bgpState string) float64 {
89+
switch bgpState {
90+
case "Idle":
91+
return 1
92+
case "Connect":
93+
return 2
94+
case "Active":
95+
return 3
96+
case "Open sent":
97+
return 4
98+
case "Open confirm":
99+
return 5
100+
case "Established":
101+
return 6
102+
default:
103+
return 0
104+
}
105+
}

Diff for: pkg/probe/bgp_neighbors_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ func TestBGPNeighborsIPv4(t *testing.T) {
1717
}
1818

1919
em := `
20-
# HELP fortigate_bgp_neighbor_ipv4_info Configured bgp neighbor over ipv4
20+
# HELP fortigate_bgp_neighbor_ipv4_info Configured bgp neighbor over ipv4, return state as value (1 - Idle, 2 - Connect, 3 - Active, 4 - Open sent, 5 - Open confirm, 6 - Established)
2121
# TYPE fortigate_bgp_neighbor_ipv4_info gauge
22-
fortigate_bgp_neighbor_ipv4_info{admin_status="true",local_ip="10.0.0.0",neighbor_ip="10.0.0.1",remote_as="1337",state="Established",vdom="root"} 1
22+
fortigate_bgp_neighbor_ipv4_info{admin_status="true",local_ip="10.0.0.0",neighbor_ip="10.0.0.1",remote_as="1337",state="Established",vdom="root"} 6
2323
`
2424

2525
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
@@ -36,9 +36,9 @@ func TestBGPNeighborsIPv6(t *testing.T) {
3636
}
3737

3838
em := `
39-
# HELP fortigate_bgp_neighbor_ipv6_info Configured bgp neighbor over ipv6
39+
# HELP fortigate_bgp_neighbor_ipv6_info Configured bgp neighbor over ipv6, return state as value (1 - Idle, 2 - Connect, 3 - Active, 4 - Open sent, 5 - Open confirm, 6 - Established)
4040
# TYPE fortigate_bgp_neighbor_ipv6_info gauge
41-
fortigate_bgp_neighbor_ipv6_info{admin_status="true",local_ip="fd00::1",neighbor_ip="fd00::2",remote_as="1337",state="Established",vdom="root"} 1
41+
fortigate_bgp_neighbor_ipv6_info{admin_status="true",local_ip="fd00::1",neighbor_ip="fd00::2",remote_as="1337",state="Established",vdom="root"} 6
4242
`
4343

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

0 commit comments

Comments
 (0)