mirror of git://bitreich.org/reed-alert
Fix check function return value
This commit is contained in:
parent
b890363bf7
commit
9698c24926
|
@ -94,8 +94,8 @@
|
||||||
(result (funcall fonction params))
|
(result (funcall fonction params))
|
||||||
(filename (format nil "~a-~a-~a" level fonction hash))
|
(filename (format nil "~a-~a-~a" level fonction hash))
|
||||||
(filepath (format nil "~a/~a" *states-dir* filename))
|
(filepath (format nil "~a/~a" *states-dir* filename))
|
||||||
(current-state 'failure) ;; default state is a failure
|
(current-state nil) ;; default state is a failure
|
||||||
(previous-state 'success)
|
(previous-state nil)
|
||||||
(trigger-state 'no))
|
(trigger-state 'no))
|
||||||
|
|
||||||
;; we open the file to read the number of tries
|
;; we open the file to read the number of tries
|
||||||
|
@ -109,10 +109,12 @@
|
||||||
;; if result is a list then the check had fail a return both nil and the error value
|
;; if result is a list then the check had fail a return both nil and the error value
|
||||||
;; if result is not a list, then it was successful
|
;; if result is not a list, then it was successful
|
||||||
(if (not (listp result))
|
(if (not (listp result))
|
||||||
|
|
||||||
|
;; SUCCESS HANDLING
|
||||||
(progn
|
(progn
|
||||||
|
|
||||||
;; mark state as success
|
;; mark state as success
|
||||||
(setf current-state 'success)
|
(setf current-state t)
|
||||||
|
|
||||||
;; we delete the file with previous states
|
;; we delete the file with previous states
|
||||||
(when (probe-file filepath)
|
(when (probe-file filepath)
|
||||||
|
@ -121,11 +123,11 @@
|
||||||
;; it was a failure and then it's back to normal state
|
;; it was a failure and then it's back to normal state
|
||||||
(when triggered-before?
|
(when triggered-before?
|
||||||
(uiop:run-program (trigger-alert level fonction params t 'success) :output t)
|
(uiop:run-program (trigger-alert level fonction params t 'success) :output t)
|
||||||
(setf previous-state 'failure))
|
(setf previous-state nil))
|
||||||
;; in any case we return t because it's ok
|
;; in any case we return t because it's ok
|
||||||
t)
|
t)
|
||||||
|
|
||||||
;; failure handling
|
;; FAILURE HANDLING
|
||||||
(let ((trigger-now? (or
|
(let ((trigger-now? (or
|
||||||
;; we add +1 to tries because it's failing right now
|
;; we add +1 to tries because it's failing right now
|
||||||
(and (= (+ 1 tries) (getf params :try *tries*))
|
(and (= (+ 1 tries) (getf params :try *tries*))
|
||||||
|
@ -138,7 +140,7 @@
|
||||||
|
|
||||||
;; more error than limit, send alert once
|
;; more error than limit, send alert once
|
||||||
(when trigger-now?
|
(when trigger-now?
|
||||||
(setf trigger-state 'notified)
|
(setf trigger-state 'YES)
|
||||||
(uiop:run-program (trigger-alert level fonction params (cadr result) trigger-now?)))
|
(uiop:run-program (trigger-alert level fonction params (cadr result) trigger-now?)))
|
||||||
;; increment the number of tries by 1
|
;; increment the number of tries by 1
|
||||||
(with-open-file (stream-out filepath :direction :output
|
(with-open-file (stream-out filepath :direction :output
|
||||||
|
@ -146,9 +148,12 @@
|
||||||
(format stream-out "~a~%~a~%" (+ 1 tries) params))
|
(format stream-out "~a~%~a~%" (+ 1 tries) params))
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(format t "~a ~A ~A ~A ~A ~A~%"
|
(format t "~a ~A ~A ~A ~A ~A ~A~%"
|
||||||
level fonction (format nil "~{~A ~}" params)
|
level fonction (format nil "~{~A ~}" params)
|
||||||
previous-state current-state trigger-state))))
|
(if previous-state "SUCCESS" "ERROR")
|
||||||
|
(if current-state "SUCCESS" "ERROR")
|
||||||
|
trigger-state (+ 1 tries)))
|
||||||
|
current-state))
|
||||||
|
|
||||||
;; abort when using ctrl+c instead of dropping to debugger
|
;; abort when using ctrl+c instead of dropping to debugger
|
||||||
#+ecl
|
#+ecl
|
||||||
|
|
|
@ -12,3 +12,13 @@
|
||||||
(=> notification disk-usage :path "/" :limit 1 :reminder 2)
|
(=> notification disk-usage :path "/" :limit 1 :reminder 2)
|
||||||
(=> notification disk-usage :path "/" :limit 1 :reminder 2)
|
(=> notification disk-usage :path "/" :limit 1 :reminder 2)
|
||||||
(=> notification disk-usage :path "/" :limit 1 :reminder 2)
|
(=> notification disk-usage :path "/" :limit 1 :reminder 2)
|
||||||
|
|
||||||
|
(and
|
||||||
|
(=> notification disk-usage :path "/" :limit 99 :reminder 2 :desc "always OK")
|
||||||
|
(=> notification disk-usage :path "/" :limit 1 :reminder 2 :desc "always error")
|
||||||
|
(=> notification disk-usage :path "/" :limit 1 :reminder 2 :desc "always error, should not be displayed"))
|
||||||
|
|
||||||
|
|
||||||
|
(or
|
||||||
|
(=> notification disk-usage :path "/" :limit 1 :reminder 2 :desc "always error, should be followed by always ok")
|
||||||
|
(=> notification disk-usage :path "/" :limit 99 :reminder 2 :desc "always OK"))
|
||||||
|
|
Loading…
Reference in New Issue