From 9b5e9bd4a8ff642b8a7408fc0f3e3dec11aa613d Mon Sep 17 00:00:00 2001 From: solene rapenne Date: Mon, 10 Oct 2016 20:35:49 +0200 Subject: [PATCH] [FIX] Return value of disk-used was a disk-used string instead of the variable --- probes.lisp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/probes.lisp b/probes.lisp index a097e7e..e10547d 100644 --- a/probes.lisp +++ b/probes.lisp @@ -1,6 +1,10 @@ (defmacro create-probe(name &body code) `(progn (defun ,name(params) ,@code))) +(defun get-file-size(path) + (with-open-file (stream path) + (and stream (file-length path)))) + (defun command-return-code(command) (let ((code (nth-value 2 (uiop:run-program command :ignore-error-status t)))) (if (= 0 code) @@ -44,7 +48,7 @@ percent-character-pos)))) (if (< used-disk (getf params :limit)) t - (list nil "used-disk")))))) + (list nil used-disk)))))) (defun system-load(time) (read-from-string @@ -75,6 +79,24 @@ t (list nil load)))) +(create-probe + file-more-than + (if (probe-file (getf params :path)) + (let ((result (get-file-size (getf params :path)))) + (if (< result (getf params :limit)) + t + (list nil result))) + "file not found")) + +(create-probe + file-less-than + (if (probe-file (getf params :path)) + (let ((result (get-file-size (getf params :path)))) + (if (> result (getf params :limit)) + t + (list nil result))) + "file not found")) + (create-probe command (command-return-code (getf params :command)))