Fix check function return value

This commit is contained in:
Solene Rapenne 2019-07-09 16:55:01 +02:00
parent b890363bf7
commit 9698c24926
2 changed files with 23 additions and 8 deletions

View File

@ -94,8 +94,8 @@
(result (funcall fonction params))
(filename (format nil "~a-~a-~a" level fonction hash))
(filepath (format nil "~a/~a" *states-dir* filename))
(current-state 'failure) ;; default state is a failure
(previous-state 'success)
(current-state nil) ;; default state is a failure
(previous-state nil)
(trigger-state 'no))
;; 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 not a list, then it was successful
(if (not (listp result))
;; SUCCESS HANDLING
(progn
;; mark state as success
(setf current-state 'success)
(setf current-state t)
;; we delete the file with previous states
(when (probe-file filepath)
@ -121,11 +123,11 @@
;; it was a failure and then it's back to normal state
(when triggered-before?
(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
t)
;; failure handling
;; FAILURE HANDLING
(let ((trigger-now? (or
;; we add +1 to tries because it's failing right now
(and (= (+ 1 tries) (getf params :try *tries*))
@ -138,7 +140,7 @@
;; more error than limit, send alert once
(when trigger-now?
(setf trigger-state 'notified)
(setf trigger-state 'YES)
(uiop:run-program (trigger-alert level fonction params (cadr result) trigger-now?)))
;; increment the number of tries by 1
(with-open-file (stream-out filepath :direction :output
@ -146,9 +148,12 @@
(format stream-out "~a~%~a~%" (+ 1 tries) params))
nil))
(format t "~a ~A ~A ~A ~A ~A~%"
(format t "~a ~A ~A ~A ~A ~A ~A~%"
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
#+ecl

View File

@ -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)
(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"))