[DEV] Add extended probes - 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 6e496d0ce582d7db769a93aa5f582321dc089894 DIR parent 84cc333bfe3d62aff0d2ff899f58b034ac2ca542 HTML Author: solene rapenne <solene@dataswamp.org> Date: Fri, 14 Oct 2016 14:21:24 +0200 [DEV] Add extended probes Diffstat: M example.lisp | 11 +++++++++++ A probes-extended.lisp | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-) --- DIR diff --git a/example.lisp b/example.lisp @@ -9,6 +9,7 @@ '(with-plus ("echo -n '" + date + _ + hostname + " had problem on " + function + newline + params + newline + desc + "' | mail -s '[Error] " + function + " - " + hostname + "' foo@bar.com")))) + (load "functions.lisp") ;; check if used percent :path partition is more than :limit @@ -47,4 +48,14 @@ (=> void command (:command "echo hello")) ;; success (=> void command (:command "ls /non-existent-file")) ;; fail +(load "probes-extended.lisp") + +;; check if web page :url answer under :limit +(=> void http-response-time (:url "http://google.fr/" :limit 10)) + +;; check if the web page :url contains the text :pattern +(=> void http-text-present (:url "http://google.fr/" :pattern "html")) +(=> void http-text-present (:url "http://google.fr/" :pattern "hello")) ;; error + + (quit) DIR diff --git a/probes-extended.lisp b/probes-extended.lisp @@ -0,0 +1,23 @@ +(ql:quickload :drakma) +(ql:quickload :cl-ppcre) + +(create-probe + http-response-time + (let ((begin (get-universal-time))) + (let ((result (ignore-errors + (drakma:http-request (getf params :url) :connection-timeout (getf params :timeout 3))))) + (if result + (let ((elapsed-time (- (get-universal-time) begin))) + (if (< elapsed-time (getf params :limit)) + t + (list nil elapsed-time))) + (list nil "http connection failure"))))) + +(create-probe + http-text-present + (ignore-errors + (let ((result (drakma:http-request (getf params :url) :connection-timeout (getf params :timeout 3)))) + (if (cl-ppcre:scan (getf params :pattern) result) + t + (list nil "pattern not found"))))) +