mirror of
git://bitreich.org/reed-alert
synced 2024-06-14 13:26:42 +00:00
[DEV] Add extended probes
This commit is contained in:
parent
84cc333bfe
commit
6e496d0ce5
11
example.lisp
11
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)
|
||||
|
|
23
probes-extended.lisp
Normal file
23
probes-extended.lisp
Normal 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")))))
|
||||
|
Loading…
Reference in New Issue
Block a user