Skip to content

Commit e702b36

Browse files
committed
Add BlockedBy to output for status
1 parent c70e42e commit e702b36

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

cmd/sd-dbus-hooks/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func main() {
4141

4242
http.Handle("/unit/start/", unitStartHandler{conn, cfg})
4343
http.Handle("/unit/stop/", unitStopHandler{conn, cfg})
44-
http.Handle("/unit/status/", unitStatusHandler{conn})
44+
http.Handle("/unit/status/", unitStatusHandler{conn, cfg})
4545

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

cmd/sd-dbus-hooks/status.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ import (
1010

1111
type unitStatusHandler struct {
1212
conn *dbus.Conn
13+
cfg *Config
1314
}
1415

1516
func (h unitStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
1617
name := r.URL.Path[len("/unit/status/"):]
18+
19+
// check if unit in config
20+
unitCfg, err := h.cfg.getUnit(name)
21+
if err != nil {
22+
log.Printf("[ERROR] %s", err)
23+
w.WriteHeader(http.StatusForbidden)
24+
return
25+
}
26+
1727
log.Printf("[INFO] get unit status %v", name)
1828

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

2636
for _, unit := range units {
2737
if unit.Name == name {
28-
fmt.Fprintf(w, "Name: %+v\n", unit.Name)
29-
fmt.Fprintf(w, "Description: %+v\n", unit.Description)
30-
fmt.Fprintf(w, "LoadState: %+v\n", unit.LoadState)
31-
fmt.Fprintf(w, "ActiveState: %+v\n", unit.ActiveState)
32-
fmt.Fprintf(w, "SubState: %+v\n", unit.ActiveState)
38+
fmt.Fprintf(w, "Name %v\n", unit.Name)
39+
fmt.Fprintf(w, "Description %v\n", unit.Description)
40+
fmt.Fprintf(w, "LoadState %v\n", unit.LoadState)
41+
fmt.Fprintf(w, "ActiveState %v\n", unit.ActiveState)
42+
fmt.Fprintf(w, "SubState %v\n", unit.ActiveState)
43+
fmt.Fprintf(w, "BlockedBy %v\n", unitCfg.BlockedBy)
3344
return
3445
}
3546
}

0 commit comments

Comments
 (0)