Skip to content

Commit

Permalink
Add BlockedBy to output for status
Browse files Browse the repository at this point in the history
  • Loading branch information
tierpod committed Apr 2, 2018
1 parent c70e42e commit e702b36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/sd-dbus-hooks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {

http.Handle("/unit/start/", unitStartHandler{conn, cfg})
http.Handle("/unit/stop/", unitStopHandler{conn, cfg})
http.Handle("/unit/status/", unitStatusHandler{conn})
http.Handle("/unit/status/", unitStatusHandler{conn, cfg})

// http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

Expand Down
21 changes: 16 additions & 5 deletions cmd/sd-dbus-hooks/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ import (

type unitStatusHandler struct {
conn *dbus.Conn
cfg *Config
}

func (h unitStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
name := r.URL.Path[len("/unit/status/"):]

// check if unit in config
unitCfg, err := h.cfg.getUnit(name)
if err != nil {
log.Printf("[ERROR] %s", err)
w.WriteHeader(http.StatusForbidden)
return
}

log.Printf("[INFO] get unit status %v", name)

units, err := h.conn.ListUnits()
Expand All @@ -25,11 +35,12 @@ func (h unitStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

for _, unit := range units {
if unit.Name == name {
fmt.Fprintf(w, "Name: %+v\n", unit.Name)
fmt.Fprintf(w, "Description: %+v\n", unit.Description)
fmt.Fprintf(w, "LoadState: %+v\n", unit.LoadState)
fmt.Fprintf(w, "ActiveState: %+v\n", unit.ActiveState)
fmt.Fprintf(w, "SubState: %+v\n", unit.ActiveState)
fmt.Fprintf(w, "Name %v\n", unit.Name)
fmt.Fprintf(w, "Description %v\n", unit.Description)
fmt.Fprintf(w, "LoadState %v\n", unit.LoadState)
fmt.Fprintf(w, "ActiveState %v\n", unit.ActiveState)
fmt.Fprintf(w, "SubState %v\n", unit.ActiveState)
fmt.Fprintf(w, "BlockedBy %v\n", unitCfg.BlockedBy)
return
}
}
Expand Down

0 comments on commit e702b36

Please sign in to comment.