From d7de6476b7f6685234344135151dccfe5ddad48c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C4=93teris=20Caune?=
Date: Tue, 28 Jan 2020 16:44:32 +0200
Subject: [PATCH] Tweaking shell script examples
---
templates/docs/bash.html | 64 +++++++++++++++-----------
templates/docs/bash.md | 64 +++++++++++++++-----------
templates/docs/configuring_checks.html | 4 +-
templates/docs/configuring_checks.md | 4 +-
templates/docs/python.html | 8 +---
templates/docs/python.md | 10 +---
templates/front/base_docs.html | 4 +-
7 files changed, 84 insertions(+), 74 deletions(-)
diff --git a/templates/docs/bash.html b/templates/docs/bash.html
index 9d2ddd97..e2971731 100644
--- a/templates/docs/bash.html
+++ b/templates/docs/bash.html
@@ -1,34 +1,44 @@
-Shell scripts
+Shell Scripts
You can easily add SITE_NAME monitoring to a shell script. All you
-have to do is make a HTTP request at the end of the script. curl and wget
-are two common command line HTTP clients for that.
-Using curl
+have to do is make a HTTP request at the end of the script.
+curl and
+wget
+are two common command line HTTP clients you can use.
+# Sending a HTTP GET request with curl:
+curl --retry 3 PING_URL
+
+# Silent version (no stdout/stderr output unless curl hits an error):
+curl -fsS --retry 3 PING_URL
+
+# Sending a HTTP GET request with wget:
+wget PING_URL -O /dev/null
+
+
+
+Signalling Failure from Shell Scripts
+You can append /fail
to any ping URL and use the resulting URL to actively
+signal a failure. The below example:
+
+- runs
/usr/bin/certbot renew
+- if the certbot command is successful (exit code 0), send HTTP GET to
PING_URL
+- otherwise, send HTTP GET to
PING_URL/fail
+
#!/bin/sh
-# Exit immediately if any command exits with a non-zero status:
-set -e
+# Payload here:
+/usr/bin/certbot renew
+# Ping SITE_NAME
+curl --retry 3 "PING_URL$([ $? -ne 0 ] && echo -n /fail)"
+
-# Do the work here
-echo "Pretending to to make backups..."
-sleep 5
-echo "Backup complete!"
-# As the last thing, ping SITE_NAME using curl:
-curl --retry 3 PING_URL
-
-
-
-Using wget
+Logging Command Output
+When pinging with HTTP POST, you can put extra diagnostic information in request
+body. If the request body looks like a valid UTF-8 string, SITE_NAME
+will accept and store first 10KB of the request body.
+In the below example, certbot's output is captured and submitted via HTTP POST:
#!/bin/sh
-# Exit immediately if any command exits with a non-zero status:
-set -e
-
-# Do the work here
-echo "Pretending to to generate reports..."
-sleep 5
-echo "Report generation complete!"
-
-# As the last thing, ping SITE_NAME using wget:
-wget PING_URL -O /dev/null
-
\ No newline at end of file
+m=$(/usr/bin/certbot renew 2>&1)
+curl -fsS --retry 3 -X POST --data-raw "$m" PING_URL
+
\ No newline at end of file
diff --git a/templates/docs/bash.md b/templates/docs/bash.md
index 05f9b660..a853cf95 100644
--- a/templates/docs/bash.md
+++ b/templates/docs/bash.md
@@ -1,39 +1,51 @@
-# Shell scripts
+# Shell Scripts
You can easily add SITE_NAME monitoring to a shell script. All you
-have to do is make a HTTP request at the end of the script. curl and wget
-are two common command line HTTP clients for that.
+have to do is make a HTTP request at the end of the script.
+[curl](https://curl.haxx.se/docs/manpage.html) and
+[wget](https://www.gnu.org/software/wget/manual/wget.html)
+are two common command line HTTP clients you can use.
-## Using curl
+```bash
+# Sending a HTTP GET request with curl:
+curl --retry 3 PING_URL
-```bash hl_lines="12"
-#!/bin/sh
+# Silent version (no stdout/stderr output unless curl hits an error):
+curl -fsS --retry 3 PING_URL
-# Exit immediately if any command exits with a non-zero status:
-set -e
+# Sending a HTTP GET request with wget:
+wget PING_URL -O /dev/null
+```
-# Do the work here
-echo "Pretending to to make backups..."
-sleep 5
-echo "Backup complete!"
+## Signalling Failure from Shell Scripts
-# As the last thing, ping SITE_NAME using curl:
-curl --retry 3 PING_URL
-```
+You can append `/fail` to any ping URL and use the resulting URL to actively
+signal a failure. The below example:
-## Using wget
+* runs `/usr/bin/certbot renew`
+* if the certbot command is successful (exit code 0), send HTTP GET to `PING_URL`
+* otherwise, send HTTP GET to `PING_URL/fail`
-```bash hl_lines="12"
+```bash
#!/bin/sh
-# Exit immediately if any command exits with a non-zero status:
-set -e
+# Payload here:
+/usr/bin/certbot renew
+# Ping SITE_NAME
+curl --retry 3 "PING_URL$([ $? -ne 0 ] && echo -n /fail)"
+```
-# Do the work here
-echo "Pretending to to generate reports..."
-sleep 5
-echo "Report generation complete!"
+## Logging Command Output
-# As the last thing, ping SITE_NAME using wget:
-wget PING_URL -O /dev/null
-```
\ No newline at end of file
+When pinging with HTTP POST, you can put extra diagnostic information in request
+body. If the request body looks like a valid UTF-8 string, SITE_NAME
+will accept and store first 10KB of the request body.
+
+In the below example, certbot's output is captured and submitted via HTTP POST:
+
+```bash
+#!/bin/sh
+
+m=$(/usr/bin/certbot renew 2>&1)
+curl -fsS --retry 3 -X POST --data-raw "$m" PING_URL
+```
diff --git a/templates/docs/configuring_checks.html b/templates/docs/configuring_checks.html
index 4e5e3c30..3f6847c3 100644
--- a/templates/docs/configuring_checks.html
+++ b/templates/docs/configuring_checks.html
@@ -25,7 +25,7 @@ what to do in case of failures, where to look for additional information.
for monitoring processes that are expected to run at relatively regular time
intervals: once an hour, once a day, once a week.
-For simple schedules you configure two time durations, Period and Grace Time.
+For simple schedules you configure two time durations, Period and Grace Time.
- Period: the expected time between pings
- Grace Time: when a check is late, how long to wait before sending an alert.
@@ -33,7 +33,7 @@ Use this variable to account for small, expected deviations in job execution tim
Cron Schedules
Use "cron" for monitoring processes with more complex schedules, and to ensure
-jobs run at the correct time (not just at correct intervals).
+jobs run at the correct time (not just at correct time intervals).
You will need to specify Cron Expression, Server's Time Zone and Grace Time.
diff --git a/templates/docs/configuring_checks.md b/templates/docs/configuring_checks.md
index aa1d973c..b40df23f 100644
--- a/templates/docs/configuring_checks.md
+++ b/templates/docs/configuring_checks.md
@@ -32,7 +32,7 @@ intervals: once an hour, once a day, once a week.
![Editing the period and grace time](IMG_URL/edit_simple_schedule.png)
-For simple schedules you configure two time durations, **Period** and **Grace Time**.
+For simple schedules you configure two time durations, Period and Grace Time.
* **Period**: the expected time between pings
* **Grace Time**: when a check is late, how long to wait before sending an alert.
@@ -41,7 +41,7 @@ Use this variable to account for small, expected deviations in job execution tim
## Cron Schedules
Use "cron" for monitoring processes with more complex schedules, and to ensure
-jobs run **at the correct time** (not just at correct intervals).
+jobs run **at the correct time** (not just at correct time intervals).
![Editing cron schedule](IMG_URL/edit_cron_schedule.png)
diff --git a/templates/docs/python.html b/templates/docs/python.html
index 7a490b98..f5ff16b1 100644
--- a/templates/docs/python.html
+++ b/templates/docs/python.html
@@ -19,14 +19,8 @@
-You can include additional diagnostic information in the in the request body (for POST requests), or in the "User-Agent" request header:
+You can include additional diagnostic information in the in the request body (for POST requests):
# Passing diagnostic information in the POST body:
import requests
requests.post("PING_URL", data="temperature=-7")
-
-
-
-# Passing diagnostic information in the User-Agent header:
-import requests
-requests.get("PING_URL", headers={"User-Agent": "temperature=-7"})
\ No newline at end of file
diff --git a/templates/docs/python.md b/templates/docs/python.md
index 809643ca..14cb63d1 100644
--- a/templates/docs/python.md
+++ b/templates/docs/python.md
@@ -22,16 +22,10 @@ import urllib
urllib.urlopen("PING_URL")
```
-You can include additional diagnostic information in the in the request body (for POST requests), or in the "User-Agent" request header:
+You can include additional diagnostic information in the in the request body (for POST requests):
```python
# Passing diagnostic information in the POST body:
import requests
requests.post("PING_URL", data="temperature=-7")
-```
-
-```python
-# Passing diagnostic information in the User-Agent header:
-import requests
-requests.get("PING_URL", headers={"User-Agent": "temperature=-7"})
-```
+```
\ No newline at end of file
diff --git a/templates/front/base_docs.html b/templates/front/base_docs.html
index 36552c4c..67b08803 100644
--- a/templates/front/base_docs.html
+++ b/templates/front/base_docs.html
@@ -17,8 +17,8 @@
{% 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" %}
+
+ {% include "front/docs_nav_item.html" with slug="bash" title="Shell Scripts" %}
{% include "front/docs_nav_item.html" with slug="python" title="Python" %}
{% include "front/docs_nav_item.html" with slug="ruby" title="Ruby" %}
{% include "front/docs_nav_item.html" with slug="php" title="PHP" %}