Code cleanup
parent
5b86e618fc
commit
ceb53970a1
|
@ -19,10 +19,15 @@ func handleReport(w http.ResponseWriter, r *http.Request) {
|
||||||
switch action {
|
switch action {
|
||||||
|
|
||||||
case "ping":
|
case "ping":
|
||||||
_ = db.SourceUpdateLastSeenAt(src.SourceID)
|
if err = db.SourceUpdateLastSeenAt(src.SourceID); err != nil {
|
||||||
w.WriteHeader(http.StatusOK)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
case "log":
|
case "log":
|
||||||
|
_ = db.SourceUpdateLastSeenAt(src.SourceID)
|
||||||
|
|
||||||
text := r.Form.Get("text")
|
text := r.Form.Get("text")
|
||||||
_ = db.LogInsert(Entry{
|
_ = db.LogInsert(Entry{
|
||||||
SourceID: src.SourceID,
|
SourceID: src.SourceID,
|
||||||
|
@ -32,6 +37,8 @@ func handleReport(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
case "alert":
|
case "alert":
|
||||||
|
_ = db.SourceUpdateLastSeenAt(src.SourceID)
|
||||||
|
|
||||||
text := r.Form.Get("text")
|
text := r.Form.Get("text")
|
||||||
_ = db.LogInsert(Entry{
|
_ = db.LogInsert(Entry{
|
||||||
SourceID: src.SourceID,
|
SourceID: src.SourceID,
|
||||||
|
@ -40,5 +47,8 @@ func handleReport(w http.ResponseWriter, r *http.Request) {
|
||||||
})
|
})
|
||||||
runAlertAction(src.AlertAction, src.Name, text)
|
runAlertAction(src.AlertAction, src.Name, text)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
|
default:
|
||||||
|
http.Error(w, "Unknown action: "+action, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue