forked from DataDog/datadog-agent
/
restart.go
40 lines (32 loc) · 876 Bytes
/
restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package api
import (
"net/http"
"github.com/StackVista/stackstate-agent/cmd/system-probe/api/module"
"github.com/StackVista/stackstate-agent/cmd/system-probe/config"
"github.com/StackVista/stackstate-agent/cmd/system-probe/modules"
"github.com/gorilla/mux"
)
func restartModuleHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
moduleName := config.ModuleName(vars["module-name"])
if moduleName == config.SecurityRuntimeModule {
w.WriteHeader(http.StatusOK)
return
}
var target module.Factory
for _, f := range modules.All {
if f.Name == moduleName {
target = f
}
}
if target.Name != moduleName {
http.Error(w, "invalid module", http.StatusBadRequest)
return
}
err := module.RestartModule(target)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}