1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Merge pull request #37 from fach/master

Fixing bird2.x status parsing
This commit is contained in:
Annika Hannig 2021-04-14 11:07:17 +02:00 committed by GitHub
commit c1ff4e6544
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 3 deletions

View file

@ -62,9 +62,9 @@ func init() {
regex.status.startLine = regexp.MustCompile(`^BIRD\s([0-9\.]+)\s*$`)
regex.status.routerID = regexp.MustCompile(`^Router\sID\sis\s([0-9\.]+)\s*$`)
regex.status.currentServer = regexp.MustCompile(`^Current\sserver\stime\sis\s([0-9\-]+\s[0-9\:]+)\s*$`)
regex.status.lastReboot = regexp.MustCompile(`^Last\sreboot\son\s([0-9\-]+\s[0-9\:]+)\s*$`)
regex.status.lastReconfig = regexp.MustCompile(`^Last\sreconfiguration\son\s([0-9\-]+\s[0-9\:]+)\s*$`)
regex.status.currentServer = regexp.MustCompile(`^Current\sserver\stime\sis\s([0-9\-]+\s[0-9\:\.]+)\s*$`)
regex.status.lastReboot = regexp.MustCompile(`^Last\sreboot\son\s([0-9\-]+\s[0-9\:\.]+)\s*$`)
regex.status.lastReconfig = regexp.MustCompile(`^Last\sreconfiguration\son\s([0-9\-]+\s[0-9\:\.]+)\s*$`)
regex.symbols.keyRx = regexp.MustCompile(`^([^\s]+)\s+(.+)\s*$`)

View file

@ -15,6 +15,52 @@ func openFile(filename string) (*os.File, error) {
return os.Open(sample)
}
func TestParseStatus(t *testing.T) {
tests := []struct {
file string
expected Parsed
}{
// Test for bird1.x status
{
"status1.sample",
Parsed{
"current_server": "2021-03-30 02:28:45",
"last_reboot": "2021-03-30 02:28:19",
"last_reconfig": "2021-03-30 02:28:19",
"message": "Daemon is up and running",
"router_id": "172.25.3.2",
"version": "1.6.6",
},
},
// Test for bird2.x status
{
"status2.sample",
Parsed{
"current_server": "2021-03-30 02:23:32.330",
"last_reboot": "2021-03-30 01:58:07.850",
"last_reconfig": "2021-03-30 01:58:07.850",
"message": "Daemon is up and running",
"router_id": "172.25.3.2",
"version": "2.0.7",
},
},
}
for _, test := range tests {
f, err := openFile(test.file)
if err != nil {
t.Error(err)
}
s := parseStatus(f)
f.Close()
status := s["status"].(Parsed)
if !reflect.DeepEqual(status, test.expected) {
t.Error("Parse status: ", status, "expected: ", test.expected)
}
}
}
func TestParseBgpRoutes(t *testing.T) {
inputs := []string{

7
test/status1.sample Normal file
View file

@ -0,0 +1,7 @@
BIRD 1.6.6 ready.
BIRD 1.6.6
Router ID is 172.25.3.2
Current server time is 2021-03-30 02:28:45
Last reboot on 2021-03-30 02:28:19
Last reconfiguration on 2021-03-30 02:28:19
Daemon is up and running

7
test/status2.sample Normal file
View file

@ -0,0 +1,7 @@
BIRD 2.0.7 ready.
BIRD 2.0.7
Router ID is 172.25.3.2
Current server time is 2021-03-30 02:23:32.330
Last reboot on 2021-03-30 01:58:07.850
Last reconfiguration on 2021-03-30 01:58:07.850
Daemon is up and running