Add new probe write-to-file - 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 13cf2712556758a985dc315ae25eea2aa7b3b0dd
DIR parent 98918e04dc8835f5dd3c4634cbc246dc89037fe9
HTML Author: Solene Rapenne <solene@perso.pw>
Date: Thu, 11 Jul 2019 10:06:26 +0200
Add new probe write-to-file
Diffstat:
M README | 19 +++++++++++++++++++
M example-full.lisp | 4 ++++
M example-simple.lisp | 2 ++
M probes.lisp | 14 ++++++++++++++
M test/test.lisp | 3 +++
5 files changed, 42 insertions(+), 0 deletions(-)
---
DIR diff --git a/README b/README
@@ -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
======================
DIR diff --git a/example-full.lisp b/example-full.lisp
@@ -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
DIR diff --git a/example-simple.lisp b/example-simple.lisp
@@ -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")
DIR diff --git a/probes.lisp b/probes.lisp
@@ -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)))
DIR diff --git a/test/test.lisp b/test/test.lisp
@@ -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")