diff --git a/pkg/probe/bgp_neighbors.go b/pkg/probe/bgp_neighbors.go index 34d5150..870db57 100644 --- a/pkg/probe/bgp_neighbors.go +++ b/pkg/probe/bgp_neighbors.go @@ -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, ) ) @@ -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)) } } @@ -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, ) ) @@ -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 + } +} diff --git a/pkg/probe/bgp_neighbors_test.go b/pkg/probe/bgp_neighbors_test.go index bf18470..9d970b4 100644 --- a/pkg/probe/bgp_neighbors_test.go +++ b/pkg/probe/bgp_neighbors_test.go @@ -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 { @@ -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 {