SMOLNET PORTAL home about changes
iPrevent a end notif without a start - reed-alert - Lightweight agentless alerting system for server	Err	bitreich.org	70
hgit clone git://bitreich.org/reed-alert/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/reed-alert/	URL:git://bitreich.org/reed-alert/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/reed-alert/	bitreich.org	70
1Log	/scm/reed-alert/log.gph	bitreich.org	70
1Files	/scm/reed-alert/files.gph	bitreich.org	70
1Refs	/scm/reed-alert/refs.gph	bitreich.org	70
1Tags	/scm/reed-alert/tag	bitreich.org	70
1README	/scm/reed-alert/file/README.gph	bitreich.org	70
1LICENSE	/scm/reed-alert/file/LICENSE.gph	bitreich.org	70
i---	Err	bitreich.org	70
1commit 9469c17e98862282e7e6e810f17d8a1ae6af2922	/scm/reed-alert/commit/9469c17e98862282e7e6e810f17d8a1ae6af2922.gph	bitreich.org	70
1parent a384acbcfd91a1067dc91a83d1f16fc23a6c881f	/scm/reed-alert/commit/a384acbcfd91a1067dc91a83d1f16fc23a6c881f.gph	bitreich.org	70
hAuthor: Solene Rapenne <solene@perso.pw>	URL:mailto:solene@perso.pw	bitreich.org	70
iDate:   Mon, 22 Jan 2018 08:09:30 +0100	Err	bitreich.org	70
i	Err	bitreich.org	70
iPrevent a end notif without a start	Err	bitreich.org	70
i	Err	bitreich.org	70
iDiffstat:	Err	bitreich.org	70
i  M functions.lisp                      |      85 +++++++++++++++----------------	Err	bitreich.org	70
i	Err	bitreich.org	70
i1 file changed, 42 insertions(+), 43 deletions(-)	Err	bitreich.org	70
i---	Err	bitreich.org	70
1diff --git a/functions.lisp b/functions.lisp	/scm/reed-alert/file/functions.lisp.gph	bitreich.org	70
i@@ -87,54 +87,53 @@	Err	bitreich.org	70
i      (or ,@body)))	Err	bitreich.org	70
i 	Err	bitreich.org	70
i (defun =>(level fonction &rest params)	Err	bitreich.org	70
i-  (format t "[~a~a ~20A~a] ~45A" *yellow* level fonction *white* (getf params :desc params))	Err	bitreich.org	70
i+  (format t "[~a~10a ~20A~a] ~45A" *yellow* level fonction *white* (getf params :desc params))	Err	bitreich.org	70
i   (let* ((hash (fnv-hash (format nil "~{~a~}" (remove-if #'symbolp params))))	Err	bitreich.org	70
i          (result (funcall fonction params))	Err	bitreich.org	70
i          (filename (format nil "~a-~a-~a" level fonction hash))	Err	bitreich.org	70
i          (filepath (format nil "states/~a" filename)))	Err	bitreich.org	70
i-    (if (not (listp result))	Err	bitreich.org	70
i-        (progn	Err	bitreich.org	70
i-          (if (probe-file filepath)	Err	bitreich.org	70
i-              ;; last time was a failure	Err	bitreich.org	70
i-              (progn	Err	bitreich.org	70
i-                (uiop:run-program (trigger-alert level fonction params t 'success) :output t)	Err	bitreich.org	70
i-                (delete-file filepath)	Err	bitreich.org	70
i-                (format t " => ~afailure => success~a~%" *green* *white*))	Err	bitreich.org	70
i-              ;; last time was a success	Err	bitreich.org	70
i-              (format t " => ~asuccess~a~%" *green* *white*))	Err	bitreich.org	70
i-          ;; we return t because it's ok	Err	bitreich.org	70
i-          t)	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+    ;; we open the file to read the number of tries	Err	bitreich.org	70
i+    ;; if no fail then we have 0 try	Err	bitreich.org	70
i+    (let* ((tries (if (not (probe-file filepath))	Err	bitreich.org	70
i+                      0	Err	bitreich.org	70
i+                      (with-open-file (stream filepath :direction :input)	Err	bitreich.org	70
i+                        (parse-integer (read-line stream 0 nil)))))	Err	bitreich.org	70
i+           (trigger-now?   (= tries (getf params :try *tries*)))	Err	bitreich.org	70
i+           (triggered-before? (>= tries (getf params :try *tries*))))	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+      ;; if result is a list then the check had fail a return both nil and the error value	Err	bitreich.org	70
i+      ;; if result is not a list, then it was successful	Err	bitreich.org	70
i+      (if (not (listp result))	Err	bitreich.org	70
i+          (progn	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+            ;; we delete the file with previous states	Err	bitreich.org	70
i+            (when (probe-file filepath)	Err	bitreich.org	70
i+                 (delete-file filepath))	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+            ;; it was a failure and then it's back to normal state	Err	bitreich.org	70
i+            (if triggered-before?	Err	bitreich.org	70
i+                (progn	Err	bitreich.org	70
i+                  (uiop:run-program (trigger-alert level fonction params t 'success) :output t)	Err	bitreich.org	70
i+                  (format t " => ~afailure => success~a~%" *green* *white*))	Err	bitreich.org	70
i+                (progn	Err	bitreich.org	70
i+                  ;; last time was a success	Err	bitreich.org	70
i+                  (format t " => ~asuccess~a~%" *green* *white*)))	Err	bitreich.org	70
i+            ;; in any case we return t because it's ok	Err	bitreich.org	70
i+            t)	Err	bitreich.org	70
i 	Err	bitreich.org	70
i         (progn	Err	bitreich.org	70
i-          (if (probe-file filepath)	Err	bitreich.org	70
i-              ;; error before	Err	bitreich.org	70
i-              ;; but how many ?	Err	bitreich.org	70
i-              (with-open-file (stream filepath :direction :input)	Err	bitreich.org	70
i-                (let ((tries (parse-integer (read-line stream 0 nil))))	Err	bitreich.org	70
i-                  (format t " => ~aerror (~a failures before)~a~%" *red* tries *white*)	Err	bitreich.org	70
i-	Err	bitreich.org	70
i-                  ;; more error than limit, send alert once	Err	bitreich.org	70
i-                  (when (= tries (getf params :try *tries*))	Err	bitreich.org	70
i-                    (uiop:run-program (trigger-alert level fonction params (cadr result) 'error) :output t))	Err	bitreich.org	70
i-	Err	bitreich.org	70
i-                  ;; increment the file	Err	bitreich.org	70
i-                  (progn	Err	bitreich.org	70
i-                    (with-open-file (stream-out filepath :direction :output	Err	bitreich.org	70
i-                                                :if-exists :supersede)	Err	bitreich.org	70
i-                      (format stream-out "~a~%~a~%" (+ 1 tries) params)))))	Err	bitreich.org	70
i-	Err	bitreich.org	70
i-              ;; file doesn't exist	Err	bitreich.org	70
i-              (with-open-file (stream-out filepath :direction :output	Err	bitreich.org	70
i-                                          :if-exists :supersede)	Err	bitreich.org	70
i-                (format t " => ~aerror (first failure)~a~%" *red* *white*)	Err	bitreich.org	70
i-	Err	bitreich.org	70
i-                ;; maybe we would be warned at first error ?	Err	bitreich.org	70
i-                ;; code is duplicated from above because it	Err	bitreich.org	70
i-                ;; requires reading the non existent file	Err	bitreich.org	70
i-                (when (= 1 (getf params :try *tries*))	Err	bitreich.org	70
i-                  (uiop:run-program (trigger-alert level fonction params (cadr result) 'error) :output t))	Err	bitreich.org	70
i-	Err	bitreich.org	70
i-                (format stream-out "1~%~a~%" params)))	Err	bitreich.org	70
i-          nil))))	Err	bitreich.org	70
i+          (format t " => ~aerror (~a failure(s) before)~a~a~%" *red* tries *white* (if trigger-now? " NOTIFIED" ""))	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+          ;; more error than limit, send alert once	Err	bitreich.org	70
i+          (when trigger-now?	Err	bitreich.org	70
i+            (uiop:run-program (trigger-alert level fonction params (cadr result) 'error) :output t))	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+          ;; increment the number of tries by 1	Err	bitreich.org	70
i+          (with-open-file (stream-out filepath :direction :output	Err	bitreich.org	70
i+                                      :if-exists :supersede)	Err	bitreich.org	70
i+            (format stream-out "~a~%~a~%" (+ 1 tries) params))	Err	bitreich.org	70
i+	Err	bitreich.org	70
i+          nil)))))	Err	bitreich.org	70
i 	Err	bitreich.org	70
i (load "probes.lisp")	Err	bitreich.org	70
.
Response: text/plain
Original URLgopher://bitreich.org/0/scm/reed-alert/commit/9469c17e988...
Content-Typetext/plain; charset=utf-8