[Fix] Alert triggered one cycle later - reed-alert - Lightweight agentless alerting system for server HTML git clone git://bitreich.org/reed-alert/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/reed-alert/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit f21b8c0e4e6021c7db52f98fb76953096bbc2793 DIR parent 0b600b142b7d503226b44ff7f58188df569898a9 HTML Author: Solene Rapenne <solene@perso.pw> Date: Thu, 25 Jan 2018 19:36:03 +0100 [Fix] Alert triggered one cycle later Diffstat: M functions.lisp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) --- DIR diff --git a/functions.lisp b/functions.lisp @@ -99,7 +99,6 @@ 0 (with-open-file (stream filepath :direction :input) (parse-integer (read-line stream 0 nil))))) - (trigger-now? (= tries (getf params :try *tries*))) (triggered-before? (>= tries (getf params :try *tries*)))) ;; if result is a list then the check had fail a return both nil and the error value @@ -109,7 +108,7 @@ ;; we delete the file with previous states (when (probe-file filepath) - (delete-file filepath)) + (delete-file filepath)) ;; it was a failure and then it's back to normal state (if triggered-before? @@ -122,18 +121,17 @@ ;; in any case we return t because it's ok t) - (progn - (format t " => ~aerror (~a failure(s) before)~a~a~%" *red* tries *white* (if trigger-now? " NOTIFIED" "")) - - ;; more error than limit, send alert once - (when trigger-now? - (uiop:run-program (trigger-alert level fonction params (cadr result) 'error) :output t)) - - ;; increment the number of tries by 1 - (with-open-file (stream-out filepath :direction :output - :if-exists :supersede) - (format stream-out "~a~%~a~%" (+ 1 tries) params)) - - nil))))) + ;; failure handling + (let ((trigger-now? (= (+ 1 tries) (getf params :try *tries*)))) ; we add +1 because it's failing right now + (format t " => ~aerror (~a failure(s) before)~a~a~%" *red* tries *white* (if trigger-now? " NOTIFIED" "")) + + ;; more error than limit, send alert once + (when trigger-now? + (uiop:run-program (trigger-alert level fonction params (cadr result) 'error) :output t)) + ;; increment the number of tries by 1 + (with-open-file (stream-out filepath :direction :output + :if-exists :supersede) + (format stream-out "~a~%~a~%" (+ 1 tries) params)) + nil))))) (load "probes.lisp")