Added problem state in notification
This commit is contained in:
parent
6629b834fd
commit
f77a65ff66
14
main.go
14
main.go
@ -203,7 +203,7 @@ func entryDatapoint(w http.ResponseWriter, r *http.Request, sess *session.T) { /
|
|||||||
logger.Error("entry", "error", err)
|
logger.Error("entry", "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiple triggers can use the same datapoint.
|
// Multiple triggers can use the same datapoint.
|
||||||
for _, trigger := range triggers {
|
for _, trigger := range triggers {
|
||||||
var out any
|
var out any
|
||||||
out, err = trigger.Run()
|
out, err = trigger.Run()
|
||||||
@ -215,25 +215,25 @@ func entryDatapoint(w http.ResponseWriter, r *http.Request, sess *session.T) { /
|
|||||||
logger.Debug("entry", "datapoint", dpoint, "value", value, "trigger", trigger, "result", out)
|
logger.Debug("entry", "datapoint", dpoint, "value", value, "trigger", trigger, "result", out)
|
||||||
|
|
||||||
var problemID int
|
var problemID int
|
||||||
|
var problemState string
|
||||||
switch v := out.(type) {
|
switch v := out.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
// Trigger returning true - a problem occurred
|
// Trigger returning true - a problem occurred
|
||||||
if v {
|
if v {
|
||||||
problemID, err = ProblemStart(trigger)
|
problemID, err = ProblemStart(trigger)
|
||||||
logger.Info("FOO", "problemID", problemID, "err==nil", err == nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = werr.Wrap(err).Log()
|
err = werr.Wrap(err).Log()
|
||||||
logger.Error("entry", "error", err)
|
logger.Error("entry", "error", err)
|
||||||
}
|
}
|
||||||
|
problemState = "PROBLEM"
|
||||||
} else {
|
} else {
|
||||||
// A problem didn't occur.
|
// A problem didn't occur.
|
||||||
problemID, err = ProblemClose(trigger)
|
problemID, err = ProblemClose(trigger)
|
||||||
logger.Info("FOO", "problemID", problemID, "err==nil", err == nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = werr.Wrap(err).Log()
|
err = werr.Wrap(err).Log()
|
||||||
logger.Error("entry", "error", err)
|
logger.Error("entry", "error", err)
|
||||||
}
|
}
|
||||||
|
problemState = "OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has a change in problem state happened?
|
// Has a change in problem state happened?
|
||||||
@ -244,7 +244,7 @@ func entryDatapoint(w http.ResponseWriter, r *http.Request, sess *session.T) { /
|
|||||||
logger.Debug("notification", "trigger", trigger.ID, "state", "change")
|
logger.Debug("notification", "trigger", trigger.ID, "state", "change")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = notificationManager.Send(problemID, []byte(trigger.Name), func(notificationService *notification.Service, err error) {
|
err = notificationManager.Send(problemID, []byte(problemState+": "+trigger.Name), func(notificationService *notification.Service, err error) {
|
||||||
logger.Info(
|
logger.Info(
|
||||||
"notification",
|
"notification",
|
||||||
"service", (*notificationService).GetType(),
|
"service", (*notificationService).GetType(),
|
||||||
@ -611,12 +611,12 @@ func pageDatapointValues(w http.ResponseWriter, r *http.Request, _ *session.T) {
|
|||||||
PAGE: "datapoint_values",
|
PAGE: "datapoint_values",
|
||||||
MENU: "datapoints",
|
MENU: "datapoints",
|
||||||
Icon: "datapoints",
|
Icon: "datapoints",
|
||||||
Label: "Values for "+datapoint.Name,
|
Label: "Values for " + datapoint.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
page.Data = map[string]any{
|
page.Data = map[string]any{
|
||||||
"Datapoint": datapoint,
|
"Datapoint": datapoint,
|
||||||
"Values": values,
|
"Values": values,
|
||||||
}
|
}
|
||||||
page.Render(w)
|
page.Render(w)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user