diff --git a/backend/sources/birdwatcher/parsers.go b/backend/sources/birdwatcher/parsers.go index f81ad22..1890353 100644 --- a/backend/sources/birdwatcher/parsers.go +++ b/backend/sources/birdwatcher/parsers.go @@ -53,6 +53,43 @@ func parseApiStatus(bird ClientResponse, config Config) (api.ApiStatus, error) { return status, nil } +// Parse birdwatcher status +func parseBirdwatcherStatus(bird ClientResponse, config Config) (api.Status, error) { + birdStatus := bird["status"].(map[string]interface{}) + + // Get special fields + serverTime, _ := parseServerTime( + birdStatus["current_server"], + SERVER_TIME_SHORT, + config.Timezone, + ) + + lastReboot, _ := parseServerTime( + birdStatus["last_reboot"], + SERVER_TIME_SHORT, + config.Timezone, + ) + + lastReconfig, _ := parseServerTime( + birdStatus["last_reconfig"], + SERVER_TIME_EXT, + config.Timezone, + ) + + // Make status response + status := api.Status{ + ServerTime: serverTime, + LastReboot: lastReboot, + LastReconfig: lastReconfig, + Backend: "bird", + Version: mustString(birdStatus["version"], "unknown"), + Message: mustString(birdStatus["message"], "unknown"), + RouterId: mustString(birdStatus["router_id"], "unknown"), + } + + return status, nil +} + // Parse neighbour uptime func parseRelativeServerTime(uptime interface{}, config Config) time.Duration { serverTime, _ := parseServerTime(uptime, SERVER_TIME_SHORT, config.Timezone) diff --git a/backend/sources/birdwatcher/source.go b/backend/sources/birdwatcher/source.go index ae52358..037f6b5 100644 --- a/backend/sources/birdwatcher/source.go +++ b/backend/sources/birdwatcher/source.go @@ -31,41 +31,14 @@ func (self *Birdwatcher) Status() (api.StatusResponse, error) { return api.StatusResponse{}, err } - birdStatus := bird["status"].(map[string]interface{}) - - // Get special fields - serverTime, _ := parseServerTime( - birdStatus["current_server"], - SERVER_TIME_SHORT, - self.config.Timezone, - ) - - lastReboot, _ := parseServerTime( - birdStatus["last_reboot"], - SERVER_TIME_SHORT, - self.config.Timezone, - ) - - lastReconfig, _ := parseServerTime( - birdStatus["last_reconfig"], - SERVER_TIME_EXT, - self.config.Timezone, - ) - - // Make status response - status := api.Status{ - ServerTime: serverTime, - LastReboot: lastReboot, - LastReconfig: lastReconfig, - Backend: "bird", - Version: birdStatus["version"].(string), - Message: birdStatus["message"].(string), - RouterId: birdStatus["router_id"].(string), + birdStatus, err := parseBirdwatcherStatus(bird, self.config) + if err != nil { + return api.StatusResponse{}, err } response := api.StatusResponse{ Api: apiStatus, - Status: status, + Status: birdStatus, } return response, nil