From c6e717bc61e367b15bbbfadfa5b6eba190219d15 Mon Sep 17 00:00:00 2001 From: Patrick Seeburger Date: Wed, 20 Feb 2019 12:13:18 +0100 Subject: [PATCH] Fixed a bug regarding timestamps in the protocols parser. --- bird/parser.go | 2 +- bird/parser_test.go | 4 ++-- test/protocols_short.sample | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/bird/parser.go b/bird/parser.go index a22f9aa..074e808 100644 --- a/bird/parser.go +++ b/bird/parser.go @@ -73,7 +73,7 @@ func init() { regex.protocol.routeChanges = regexp.MustCompile(`(Import|Export) (updates|withdraws):\s+(\d+|---)\s+(\d+|---)\s+(\d+|---)\s+(\d+|---)\s+(\d+|---)\s*$`) regex.routes.startDefinition = regexp.MustCompile(`^([0-9a-f\.\:\/]+)\s+via\s+([0-9a-f\.\:]+)\s+on\s+([\w\.]+)\s+\[([\w\.:]+)\s+([0-9\-\:\s]+)(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*`) - regex.protocol.short = regexp.MustCompile(`^(?:1002\-)?([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([0-9\-]+)\s+(.*?)\s*?$`) + regex.protocol.short = regexp.MustCompile(`^(?:1002\-)?([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([0-9\-]+\s+[0-9\:]+?|[0-9\-]+)\s+(.*?)\s*?$`) regex.routes.second = regexp.MustCompile(`^\s+via\s+([0-9a-f\.\:]+)\s+on\s+([\w\.]+)\s+\[([\w\.:]+)\s+([0-9\-\:\s]+)(?:\s+from\s+([0-9a-f\.\:\/]+)){0,1}\]\s+(?:(\*)\s+){0,1}\((\d+)(?:\/\d+){0,1}\).*$`) regex.routes.routeType = regexp.MustCompile(`^\s+Type:\s+(.*)\s*$`) regex.routes.bgp = regexp.MustCompile(`^\s+BGP.(\w+):\s+(.+)\s*$`) diff --git a/bird/parser_test.go b/bird/parser_test.go index cb026dd..a4a81f8 100644 --- a/bird/parser_test.go +++ b/bird/parser_test.go @@ -74,9 +74,9 @@ func TestParseProtocolShort(t *testing.T) { log.Printf("%# v", pretty.Formatter(p)) protocols := p["protocols"].(Parsed) - if len(protocols) != 7 { + if len(protocols) != 27 { //log.Printf("%# v", pretty.Formatter(protocols)) - t.Fatalf("Expected 7 protocols, found: %v", len(protocols)) + t.Fatalf("Expected 27 protocols, found: %v", len(protocols)) } fmt.Println(protocols) diff --git a/test/protocols_short.sample b/test/protocols_short.sample index c55c3d4..5fabb6a 100644 --- a/test/protocols_short.sample +++ b/test/protocols_short.sample @@ -8,3 +8,24 @@ pp_0175_as15169 Pipe master up 2019-02-15 => t_0175_as15169 pb_0175_as15169 BGP t_0175_as15169 up 2019-02-15 Established pp_0026_as20940 Pipe master up 2019-02-15 => t_0026_as20940 pb_0026_as20940 BGP t_0026_as20940 up 2019-02-15 Established +direct1 Direct master down 2019-02-19 16:17:59 +kernel1 Kernel master down 2019-02-19 16:17:59 +M42_pch_radb Pipe master up 2019-02-19 16:17:59 => T42_pch_radb +C42_pch_radb Pipe Collector up 2019-02-19 16:17:59 => T42_pch_radb +R194_42 BGP T42_pch_radb up 2019-02-19 16:29:00 Established +M3856_pch_radb Pipe master up 2019-02-19 16:17:59 => T3856_pch_radb +C3856_pch_radb Pipe Collector up 2019-02-19 16:17:59 => T3856_pch_radb +R195_42 BGP T3856_pch_radb up 2019-02-19 16:18:33 Established +M112_112_ripe Pipe master up 2019-02-19 16:17:59 => T112_112_ripe +C112_112_ripe Pipe Collector up 2019-02-19 16:17:59 => T112_112_ripe +R195_77 BGP T112_112_ripe up 2019-02-19 16:24:31 Established +M286_kpn_ripe Pipe master up 2019-02-19 16:17:59 => T286_kpn_ripe +C286_kpn_ripe Pipe Collector up 2019-02-19 16:17:59 => T286_kpn_ripe +R192_22 BGP T286_kpn_ripe up 2019-02-19 16:26:10 Established +M553_belwue_ripe Pipe master up 2019-02-19 16:17:59 => T553_belwue_ripe +C553_belwue_ripe Pipe Collector up 2019-02-19 16:17:59 => T553_belwue_ripe +R192_175 BGP T553_belwue_ripe up 2019-02-19 16:18:34 Established +R194_106 BGP T553_belwue_ripe up 2019-02-19 16:18:09 Established +R194_205 BGP T52866_iveloz_radb start 2019-02-20 12:06:01 Idle BGP Error: Bad peer AS +R_janus1 BGP T6695_bh_20 start 2019-02-19 16:17:59 Idle +