moncheck - add function to remove acknowledge
An acknowledge should be set to false when the alarm switches to an ok state.
This commit is contained in:
parent
a0c78acdda
commit
ddc0053ce8
|
@ -131,7 +131,9 @@ func check(thread int, db *sql.DB, waitDuration time.Duration) {
|
|||
}
|
||||
msg := output.String()
|
||||
|
||||
if _, err := tx.Exec("update active_checks set next_time = now() + intval, states = $2 where check_id = $1", id, &states); err != nil {
|
||||
if _, err := tx.Exec(`update active_checks
|
||||
set next_time = now() + intval, states = $2, msg = $3, acknowledged = case when $4 then false else acknowledged end
|
||||
where check_id = $1`, id, &states, &msg, states.ToOK()); err != nil {
|
||||
log.Printf("[%d] could not update row '%d': %s", thread, id, err)
|
||||
tx.Rollback()
|
||||
continue
|
||||
|
@ -203,3 +205,18 @@ func (s *States) Add(state int) {
|
|||
*s = append([]int{state}, vals[:statePos]...)
|
||||
return
|
||||
}
|
||||
|
||||
// ToOK returns true when the state returns from != 0 to 0.
|
||||
func (s *States) ToOK() bool {
|
||||
vals := *s
|
||||
if len(vals) == 0 {
|
||||
return false
|
||||
}
|
||||
if len(vals) <= 1 {
|
||||
return vals[0] == 0
|
||||
}
|
||||
if vals[0] == 0 && vals[1] > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user