Adding initial support for printing results in JSON format. Adding Logrus logging and adding a logging level argument. Adding StartMaintenance API.
This commit is contained in:
parent
6ce6411ee0
commit
a559137fe3
5 changed files with 145 additions and 61 deletions
43
cmd/util.go
43
cmd/util.go
|
@ -3,8 +3,10 @@ package cmd
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/paypal/gorealis/gen-go/apache/aurora"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func toJSON(v interface{}) string {
|
||||
|
@ -12,7 +14,7 @@ func toJSON(v interface{}) string {
|
|||
output, err := json.Marshal(v)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("Unable to serialize statuses")
|
||||
log.Fatalln("Unable to serialize Aurora response: %+v", v)
|
||||
}
|
||||
|
||||
return string(output)
|
||||
|
@ -32,4 +34,39 @@ func getLoggingLevels() string {
|
|||
|
||||
return buffer.String()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.MaintenanceMode) {
|
||||
if len(hostResult) > 0 {
|
||||
// Create anonymous struct for JSON formatting
|
||||
output := struct{
|
||||
DesiredStates []string `json:desired_states`
|
||||
Transitioned []string `json:transitioned`
|
||||
NonTransitioned []string `json:non-transitioned`
|
||||
}{
|
||||
make([]string, 0),
|
||||
make([]string, 0),
|
||||
make([]string, 0),
|
||||
}
|
||||
|
||||
for _,state := range desiredStates {
|
||||
output.DesiredStates = append(output.DesiredStates, state.String())
|
||||
}
|
||||
|
||||
for host, ok := range hostResult {
|
||||
if ok {
|
||||
output.Transitioned = append(output.Transitioned, host)
|
||||
} else {
|
||||
output.NonTransitioned = append(output.NonTransitioned, host)
|
||||
}
|
||||
}
|
||||
|
||||
if toJson {
|
||||
fmt.Println(toJSON(output))
|
||||
} else {
|
||||
fmt.Printf("Entered %v status: %v", output.DesiredStates, output.Transitioned)
|
||||
fmt.Printf("Did not enter %v status: %v", output.DesiredStates, output.NonTransitioned)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue