From 3e2ae023880858ba5a89479a299e0dbc31c8993c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 23 Jan 2020 17:53:23 +0200 Subject: [PATCH] Added an example of capturing and submitting log output. Fixes #315 --- templates/docs/attaching_logs.html | 34 +++++++++++++++++++ templates/docs/attaching_logs.md | 44 +++++++++++++++++++++++++ templates/docs/signalling_failures.html | 1 + templates/docs/signalling_failures.md | 2 ++ templates/front/base_docs.html | 1 + 5 files changed, 82 insertions(+) create mode 100644 templates/docs/attaching_logs.html create mode 100644 templates/docs/attaching_logs.md diff --git a/templates/docs/attaching_logs.html b/templates/docs/attaching_logs.html new file mode 100644 index 00000000..01d1e72f --- /dev/null +++ b/templates/docs/attaching_logs.html @@ -0,0 +1,34 @@ +

Attaching Logs

+

SITE_NAME ping endpoints accept HTTP HEAD, GET and POST request methods.

+

When using HTTP POST, you can include arbitrary payload in the request body. +If the request body looks like a UTF-8 string, SITE_NAME will log the first 10 kilobytes of +the request body, so you can inspect it later.

+

Logging Command Output

+

In this example, we run certbot renew, capture its output, and submit +the captured output to SITE_NAME:

+
#!/bin/sh
+
+m=$(/usr/bin/certbot renew 2>&1)
+curl -fsS --retry 3 -X POST --data-raw "$m" PING_URL
+
+ + +

In Combination with the /fail Endpoint

+

We can extend the previous example and signal either success or failure +depending on the exit code:

+
#!/bin/sh
+
+url=PING_URL
+
+m=$(/usr/bin/certbot renew 2>&1)
+
+if [ $? -ne 0 ]; then url=$url/fail; fi
+curl -fsS --retry 3 -X POST --data-raw "$m" $url
+
+ + +

As One-Liner

+

Finally, all of the above can be packaged in a single line. The one-line +version can be put directly in crontab, without using a wrapper script.

+
m=$(/usr/bin/certbot renew 2>&1); curl -fsS -X POST --data-raw "$m" "PING_URL$([ $? -ne 0 ] && echo -n /fail)"
+
\ No newline at end of file diff --git a/templates/docs/attaching_logs.md b/templates/docs/attaching_logs.md new file mode 100644 index 00000000..71dcf440 --- /dev/null +++ b/templates/docs/attaching_logs.md @@ -0,0 +1,44 @@ +# Attaching Logs + +SITE_NAME ping endpoints accept HTTP HEAD, GET and POST request methods. + +When using HTTP POST, **you can include arbitrary payload in the request body**. +If the request body looks like a UTF-8 string, SITE_NAME will log the first 10 kilobytes of +the request body, so you can inspect it later. + +## Logging Command Output + +In this example, we run `certbot renew`, capture its output, and submit +the captured output to SITE_NAME: + +```bash +#!/bin/sh + +m=$(/usr/bin/certbot renew 2>&1) +curl -fsS --retry 3 -X POST --data-raw "$m" PING_URL +``` + +## In Combination with the `/fail` Endpoint + +We can extend the previous example and signal either success or failure +depending on the exit code: + +```bash +#!/bin/sh + +url=PING_URL + +m=$(/usr/bin/certbot renew 2>&1) + +if [ $? -ne 0 ]; then url=$url/fail; fi +curl -fsS --retry 3 -X POST --data-raw "$m" $url +``` + +## As One-Liner + +Finally, all of the above can be packaged in a single line. The one-line +version can be put directly in crontab, without using a wrapper script. + +```bash +m=$(/usr/bin/certbot renew 2>&1); curl -fsS -X POST --data-raw "$m" "PING_URL$([ $? -ne 0 ] && echo -n /fail)" +``` \ No newline at end of file diff --git a/templates/docs/signalling_failures.html b/templates/docs/signalling_failures.html index 3d76b33c..1855ae93 100644 --- a/templates/docs/signalling_failures.html +++ b/templates/docs/signalling_failures.html @@ -3,6 +3,7 @@ Requesting the /fail URL will immediately mark the check as "down". You can use this feature to minimize the delay from your monitored service failing to you getting a notification.

+

Python

Below is a skeleton code example in Python which signals a failure when the work function returns an unexpected value or throws an exception:

import requests
diff --git a/templates/docs/signalling_failures.md b/templates/docs/signalling_failures.md
index 49fe04f9..45e2b0dd 100644
--- a/templates/docs/signalling_failures.md
+++ b/templates/docs/signalling_failures.md
@@ -5,6 +5,8 @@ Requesting the `/fail` URL will immediately mark the check as "down".
 You can use this feature to minimize the delay from your monitored service failing
 to you getting a notification.
 
+## Python
+
 Below is a skeleton code example in Python which signals a failure when the
 work function returns an unexpected value or throws an exception:
 
diff --git a/templates/front/base_docs.html b/templates/front/base_docs.html
index 2a727a2f..fe4645d1 100644
--- a/templates/front/base_docs.html
+++ b/templates/front/base_docs.html
@@ -14,6 +14,7 @@
         {% include "front/docs_nav_item.html" with slug="monitoring_cron_jobs" title="Monitoring cron jobs" %}
         {% include "front/docs_nav_item.html" with slug="signalling_failures" title="Signalling failures" %}
         {% include "front/docs_nav_item.html" with slug="measuring_script_run_time" title="Measuring script run time" %}
+        {% include "front/docs_nav_item.html" with slug="attaching_logs" title="Attaching logs" %}
 
         
         {% include "front/docs_nav_item.html" with slug="bash" title="Bash" %}