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:

+
#!/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.

Editing the period and grace time

-

For simple schedules you configure two time durations, Period and Grace Time.

+

For simple schedules you configure two time durations, Period and Grace Time.

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

You will need to specify Cron Expression, Server's Time Zone and Grace Time.