Write status output in JSON. (refs #2561)
authorTim Pierce <twp@curoverse.com>
Fri, 11 Apr 2014 11:02:42 +0000 (07:02 -0400)
committerTim Pierce <twp@curoverse.com>
Fri, 11 Apr 2014 11:02:42 +0000 (07:02 -0400)
services/keep/keep.go

index 4ee9fb3832698cd594826a5b95a391e4563bf13c..71c2a8b9138f97d010fce4f5e48cf9665d3cad3f 100644 (file)
@@ -4,6 +4,7 @@ import (
        "bufio"
        "bytes"
        "crypto/md5"
+       "encoding/json"
        "errors"
        "fmt"
        "github.com/gorilla/mux"
@@ -209,6 +210,14 @@ func StatusHandler(w http.ResponseWriter, req *http.Request) {
        for _, vol := range KeepVolumes {
                st.Volumes[vol] = GetVolumeStatus(vol)
        }
+
+       if jstat, err := json.Marshal(st); err == nil {
+               w.Write(jstat)
+       } else {
+               log.Printf("json.Marshal: %s\n", err)
+               log.Printf("NodeStatus = %v\n", st)
+               http.Error(w, err.Error(), 500)
+       }
 }
 
 // GetVolumeStatus