diff --git a/api/api.go b/api/api.go index bd2da6b..5b7fec7 100644 --- a/api/api.go +++ b/api/api.go @@ -45,7 +45,7 @@ const ( cptvGlob = "*.cptv" failedUploadsFolder = "failed-uploads" rebootDelay = time.Second * 5 - apiVersion = 3 + apiVersion = 4 ) type ManagementAPI struct { @@ -460,6 +460,22 @@ func (api *ManagementAPI) DeleteEvents(w http.ResponseWriter, r *http.Request) { } } +// CheckSaltConnection will try to ping the salt server and return the response +func (api *ManagementAPI) CheckSaltConnection(w http.ResponseWriter, r *http.Request) { + log.Println("pinging salt server") + out, err := exec.Command("salt-call", "test.ping").Output() + + output := map[string]interface{}{ + "output": string(out), + "success": true, + } + if err != nil { + output["error"] = err.Error() + output["success"] = false + } + json.NewEncoder(w).Encode(output) +} + func isEventKey(key uint64) (bool, error) { keys, err := eventclient.GetEventKeys() if err != nil { diff --git a/cmd/managementd/main.go b/cmd/managementd/main.go index f2551f2..21eb2c1 100644 --- a/cmd/managementd/main.go +++ b/cmd/managementd/main.go @@ -101,6 +101,7 @@ func main() { apiRouter.HandleFunc("/event-keys", apiObj.GetEventKeys).Methods("GET") apiRouter.HandleFunc("/events", apiObj.GetEvents).Methods("GET") apiRouter.HandleFunc("/events", apiObj.DeleteEvents).Methods("DELETE") + apiRouter.HandleFunc("/check-salt-connection", apiObj.CheckSaltConnection).Methods("GET") apiRouter.Use(basicAuth) listenAddr := fmt.Sprintf(":%d", config.Port) diff --git a/html/about.html b/html/about.html index d258f1c..3fa8e45 100644 --- a/html/about.html +++ b/html/about.html @@ -62,6 +62,7 @@