Skip to content

Commit

Permalink
feat(probe): BGP session state as value (#237)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
33Fraise33 and Gianni Stubbe authored Jul 25, 2023
1 parent b26fdb4 commit 8a6f0b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
27 changes: 23 additions & 4 deletions pkg/probe/bgp_neighbors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func probeBGPNeighborsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus
var (
mBGPNeighbor = prometheus.NewDesc(
"fortigate_bgp_neighbor_ipv4_info",
"Configured bgp neighbor over ipv4",
"Configured bgp neighbor over ipv4, return state as value (1 - Idle, 2 - Connect, 3 - Active, 4 - Open sent, 5 - Open confirm, 6 - Established)",
[]string{"vdom", "remote_as", "state", "admin_status", "local_ip", "neighbor_ip"}, nil,
)
)
Expand All @@ -46,7 +46,7 @@ func probeBGPNeighborsIPv4(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus

for _, r := range rs {
for _, peer := range r.Results {
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))
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))
}
}

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

for _, r := range rs {
for _, peer := range r.Results {
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))
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))
}
}

return m, true
}

func bgpStateToNumber(bgpState string) float64 {
switch bgpState {
case "Idle":
return 1
case "Connect":
return 2
case "Active":
return 3
case "Open sent":
return 4
case "Open confirm":
return 5
case "Established":
return 6
default:
return 0
}
}
8 changes: 4 additions & 4 deletions pkg/probe/bgp_neighbors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func TestBGPNeighborsIPv4(t *testing.T) {
}

em := `
# HELP fortigate_bgp_neighbor_ipv4_info Configured bgp neighbor over ipv4
# 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)
# TYPE fortigate_bgp_neighbor_ipv4_info gauge
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
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
`

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

em := `
# HELP fortigate_bgp_neighbor_ipv6_info Configured bgp neighbor over ipv6
# 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)
# TYPE fortigate_bgp_neighbor_ipv6_info gauge
fortigate_bgp_neighbor_ipv6_info{admin_status="true",local_ip="fd00::1",neighbor_ip="fd00::2",remote_as="1337",state="Established",vdom="root"} 1
fortigate_bgp_neighbor_ipv6_info{admin_status="true",local_ip="fd00::1",neighbor_ip="fd00::2",remote_as="1337",state="Established",vdom="root"} 6
`

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

0 comments on commit 8a6f0b3

Please sign in to comment.