mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
fixed issue in status parsing
This commit is contained in:
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user