From e1056aa50d950143ce2b20d9deed9290b5ba4743 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Mon, 5 Feb 2018 23:39:12 +0530 Subject: [PATCH] Fix admin-info, admin-status json status field (#2293) --- cmd/admin-info.go | 10 +++++----- cmd/admin-service-status.go | 16 +++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cmd/admin-info.go b/cmd/admin-info.go index 6073110c..4f0426b9 100644 --- a/cmd/admin-info.go +++ b/cmd/admin-info.go @@ -94,7 +94,7 @@ type ServerInfo struct { // infoMessage container to hold service status information. type infoMessage struct { Status string `json:"status"` - Service bool `json:"service"` + Service string `json:"service"` Addr string `json:"address"` Err string `json:"error"` *ServerInfo @@ -109,7 +109,7 @@ func (u infoMessage) String() (msg string) { dot := "●" // When service is offline - if !u.Service { + if u.Service == "off" { msg += fmt.Sprintf("%s %s\n", console.Colorize("InfoFail", dot), u.Addr) msg += fmt.Sprintf(" Uptime : Server is %s", console.Colorize("InfoFail", "offline")) return @@ -204,7 +204,7 @@ func mainAdminInfo(ctx *cli.Context) error { } if serviceOffline { - printMsg(infoMessage{Addr: aliasedURL, Service: false}) + printMsg(infoMessage{Addr: aliasedURL, Service: "off"}) return nil } @@ -215,7 +215,7 @@ func mainAdminInfo(ctx *cli.Context) error { // Print the error if exists and jump to the next server if serverInfo.Error != "" { printMsg(infoMessage{ - Service: true, + Service: "on", Addr: serverInfo.Addr, Err: serverInfo.Error, }) @@ -241,7 +241,7 @@ func mainAdminInfo(ctx *cli.Context) error { } printMsg(infoMessage{ - Service: true, + Service: "on", Addr: serverInfo.Addr, Err: serverInfo.Error, ServerInfo: &ServerInfo{ diff --git a/cmd/admin-service-status.go b/cmd/admin-service-status.go index 2a40a8d8..588e23b2 100644 --- a/cmd/admin-service-status.go +++ b/cmd/admin-service-status.go @@ -56,7 +56,7 @@ EXAMPLES: // serviceStatusMessage container to hold service status information. type serviceStatusMessage struct { Status string `json:"status"` - Service bool `json:"service"` + Service string `json:"service"` Uptime time.Duration `json:"uptime"` } @@ -66,7 +66,7 @@ func (u serviceStatusMessage) String() (msg string) { msg = console.Colorize("ServiceStatus", msg) }() // When service is offline - if !u.Service { + if u.Service == "off" { msg = "The server is offline." return } @@ -76,7 +76,13 @@ func (u serviceStatusMessage) String() (msg string) { // JSON jsonified service status Message message. func (u serviceStatusMessage) JSON() string { - u.Status = "success" + switch u.Service { + case "on": + u.Status = "success" + case "off": + u.Status = "failure" + } + statusJSONBytes, e := json.Marshal(u) fatalIf(probe.NewError(e), "Unable to marshal into JSON.") @@ -120,7 +126,7 @@ func mainAdminServiceStatus(ctx *cli.Context) error { } } if serviceOffline { - printMsg(serviceStatusMessage{Service: false}) + printMsg(serviceStatusMessage{Service: "off"}) return nil } @@ -129,7 +135,7 @@ func mainAdminServiceStatus(ctx *cli.Context) error { // Print the whole response printMsg(serviceStatusMessage{ - Service: true, + Service: "on", Uptime: st.Uptime, })