iHow to declare new probes - reed-alert - Lightweight agentless alerting system for server Err bitreich.org 70
hgit clone git://bitreich.org/reed-alert/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/reed-alert/ URL:git://bitreich.org/reed-alert/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/reed-alert/ bitreich.org 70
1Log /scm/reed-alert/log.gph bitreich.org 70
1Files /scm/reed-alert/files.gph bitreich.org 70
1Refs /scm/reed-alert/refs.gph bitreich.org 70
1Tags /scm/reed-alert/tag bitreich.org 70
1README /scm/reed-alert/file/README.gph bitreich.org 70
1LICENSE /scm/reed-alert/file/LICENSE.gph bitreich.org 70
i--- Err bitreich.org 70
1commit a384acbcfd91a1067dc91a83d1f16fc23a6c881f /scm/reed-alert/commit/a384acbcfd91a1067dc91a83d1f16fc23a6c881f.gph bitreich.org 70
1parent f352b8458e9b406ce8795bf00c704c260c511cd6 /scm/reed-alert/commit/f352b8458e9b406ce8795bf00c704c260c511cd6.gph bitreich.org 70
hAuthor: Solene Rapenne <solene@perso.pw> URL:mailto:solene@perso.pw bitreich.org 70
iDate: Mon, 22 Jan 2018 08:06:19 +0100 Err bitreich.org 70
i Err bitreich.org 70
iHow to declare new probes Err bitreich.org 70
i Err bitreich.org 70
iDiffstat: Err bitreich.org 70
i M README | 76 +++++++++++++++++++++++++++++++ Err bitreich.org 70
i Err bitreich.org 70
i1 file changed, 76 insertions(+), 0 deletions(-) Err bitreich.org 70
i--- Err bitreich.org 70
1diff --git a/README b/README /scm/reed-alert/file/README.gph bitreich.org 70
i@@ -370,3 +370,79 @@ than 98%, the "buzzer" alert will make some bad noises in the room to Err bitreich.org 70
i warn me about this. Err bitreich.org 70
i Err bitreich.org 70
i Note : escalation is an alias for the **or** function. Err bitreich.org 70
i+ Err bitreich.org 70
i+ Err bitreich.org 70
i+Extend with your own probes Err bitreich.org 70
i+=========================== Err bitreich.org 70
i+ Err bitreich.org 70
i+It is likely that you want to write your own probes. While using the Err bitreich.org 70
i+command probe can be convenient, you may want to have a probe with Err bitreich.org 70
i+more parameters and better integration than the command probe. Err bitreich.org 70
i+ Err bitreich.org 70
i+There are two methods for adding probes : Err bitreich.org 70
i+- in the configuration file before using it Err bitreich.org 70
i+- in a separated lisp file that you load from the configuration file Err bitreich.org 70
i+ Err bitreich.org 70
i+If you want to reuse for multiples configuration files or servers, I Err bitreich.org 70
i+would recommend a separate file, otherwise, adding it at the top of Err bitreich.org 70
i+the configuration file can be convenient too. Err bitreich.org 70
i+ Err bitreich.org 70
i+ Err bitreich.org 70
i+Using a shell command Err bitreich.org 70
i+--------------------- Err bitreich.org 70
i+ Err bitreich.org 70
i+A minimum of Common LISP comprehension is needed for this. But using Err bitreich.org 70
i+the easiest way to go by writing a probe using a command shell, the Err bitreich.org 70
i+declaration can be really simple. Err bitreich.org 70
i+ Err bitreich.org 70
i+We are going to write a probe that will use curl to fetch an page and Err bitreich.org 70
i+then grep on the output to look for a pattern. The return code of grep Err bitreich.org 70
i+will be the return status of the probe, if grep finds the pattern, Err bitreich.org 70
i+it's a success, if not it's a failure. Err bitreich.org 70
i+ Err bitreich.org 70
i+In the following code, the "create-probe" part is a macro that will Err bitreich.org 70
i+write most of the code for you. Then, we use "command-return-code" Err bitreich.org 70
i+function which will execute the shell command passed as a string (or Err bitreich.org 70
i+as a list) and return the correct values in case of success or Err bitreich.org 70
i+failure. Err bitreich.org 70
i+ Err bitreich.org 70
i+ (create-probe Err bitreich.org 70
i+ check-http-pattern Err bitreich.org 70
i+ (command-return-code (format nil "curl ~a | grep -i ~a" Err bitreich.org 70
i+ (getf params :url) (getf params :pattern)))) Err bitreich.org 70
i+ Err bitreich.org 70
i+If you don't know LISP, "format" function works like "printf", using Err bitreich.org 70
i+"~a" instead of "%s". This is the only required thing to know if you Err bitreich.org 70
i+want to reuse the previous code. Err bitreich.org 70
i+ Err bitreich.org 70
i+Then we can call it like this : Err bitreich.org 70
i+ Err bitreich.org 70
i+ (=> notifier check-http-pattern :url "http://127.0.0.1"; :pattern "Powered by cl-yag") Err bitreich.org 70
i+ Err bitreich.org 70
i+ Err bitreich.org 70
i+Using plain LISP Err bitreich.org 70
i+---------------- Err bitreich.org 70
i+ Err bitreich.org 70
i+We have seen previously how tocreate new probes from a shell command, Err bitreich.org 70
i+but one may want to do it in LISP, allowing to use full features of Err bitreich.org 70
i+the language and even some libraries to check values in a database for Err bitreich.org 70
i+example. I recommend to read the "probes.lisp" file, it's the best way Err bitreich.org 70
i+to learn how to write a new probe. But as an example, we will learn Err bitreich.org 70
i+from the easiest probe included : file-exists Err bitreich.org 70
i+ Err bitreich.org 70
i+ (create-probe Err bitreich.org 70
i+ file-exists Err bitreich.org 70
i+ (let ((result (probe-file (getf params :path)))) Err bitreich.org 70
i+ (if result Err bitreich.org 70
i+ t Err bitreich.org 70
i+ (list nil "file not found")))) Err bitreich.org 70
i+ Err bitreich.org 70
i+Like before, we use the "create-probe" macro and give a name to the Err bitreich.org 70
i+probe. Then, we have to write some code, in the current case, check if Err bitreich.org 70
i+the file exists. Finally, if it is a success, we have to return **t**, Err bitreich.org 70
i+if it fails we return a list containing **nil** and a value or a Err bitreich.org 70
i+string. The second element in the list will replaced %result% in the Err bitreich.org 70
i+notification command, so you can use something explicit, a Err bitreich.org 70
i+concatenation of a message with the return value etc..". Parameters Err bitreich.org 70
i+should be get with getf from **params** variable, allowing to use a Err bitreich.org 70
i+default value in case it's not defined in the configuration file. Err bitreich.org 70
.
Response:
text/plain