[DEV] Add extended probes

This commit is contained in:
solene rapenne 2016-10-14 14:21:24 +02:00
parent 84cc333bfe
commit 6e496d0ce5
2 changed files with 34 additions and 0 deletions

View File

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

23
probes-extended.lisp Normal file
View File

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