Add new probe write-to-file

This commit is contained in:
Solene Rapenne 2019-07-11 10:06:26 +02:00
parent 98918e04dc
commit 13cf271255
5 changed files with 42 additions and 0 deletions

19
README
View File

@ -370,6 +370,25 @@ Example: `(=> alert ssl-expiration :host "domain.local" :seconds 86400 :port 669
Example: `(=> alert ssl-expiration :host "smtp.domain.local" :seconds 86400 :starttls "smtp" :port 25)
write-to-file
--------------------
Write content to a file, create it if non existent.
The purpose of this probe is to be used at the end of a reed-alert
script to update the modification time of a file, and use file-updated
on this file at the beginning of a script to monitor if reed-alert did
finish correctly on last run.
> Set the path of the file.
:path "STRING"
> Set the content of the file (OPTIONAL).
:text "STRING" (default to current time in seconds)
Example: `(=> alert write-to-file :path "/tmp/reed-alert.txt")`
Example: `(=> alert write-to-file :path "/tmp/reed-alert.txt" :text "hello world")`
The configuration file
======================

View File

@ -19,6 +19,7 @@
;; check if :path file exists and has been updated since :limit minutes
(=> empty file-updated :path "/var/log/messages" :limit 400)
(=> mail file-updated :path "/bsd.rd" :limit 1 :desc "OpenBSD kernel") ;; failure
(=> mail file-updated :path "/tmp/reed-alert.txt" :limit 10)
;; check if :path pid file process is running
(=> mail pid-running :path "/var/run/xdm.pid" :desc "XDM pid")
@ -58,6 +59,9 @@
(=> mail ssl-expiration :host "freenode.net" :seconds (* 7 24 60 60))
(=> mail ssl-expiration :host "freenode.net" :seconds 1296000 :port 6697)
;; update a file modification time
(=> mail write-to-file :path "/tmp/reed-alert.txt")
;; we declare a new probe here
(create-probe
check-http-pattern

View File

@ -6,6 +6,7 @@
;; this is a comment
; this is also a comment
(=> mail file-updated :path "/tmp/reed-alert" :limit 100)
(=> mail disk-usage :path "/" :limit 90)
(=> mail service :name "dovecot")
@ -16,3 +17,4 @@
(=> mail ping :host "bitreich.org" :desc "Ping Bitreich")
(=> mail ping :host "openbsd.org" :desc "Ping OpenBSD.org")
(=> mail ssl-expiration :host "freenode.net" :seconds (* 7 24 60 60) :desc "SSL IRC Freenode")
(=> mail write-to-file :path "/tmp/reed-alert")

View File

@ -140,3 +140,17 @@
"openssl x509 -inform pem -noout "
(when starttls (strcat " -starttls " starttls))
" -checkend " seconds))))
(create-probe
write-to-file
(let ((filepath (getf params :path nil))
(text (getf params :text
(princ-to-string
(get-universal-time)))))
(when filepath
(with-open-file
(stream-out filepath
:direction :output
:if-exists :supersede)
(format stream-out "~a~%" text))
t)))

View File

@ -22,3 +22,6 @@
(or
(=> notification disk-usage :path "/" :limit 1 :reminder 2 :desc "always error, should be followed by always ok")
(=> notification disk-usage :path "/" :limit 99 :reminder 2 :desc "always OK"))
(=> notification write-to-file :path "/tmp/hello.txt")
(=> notification write-to-file :path "/tmp/hello2.txt" :text "hi")