From 571afc1b5d92b9b02f48ff589b9e0b638a986724 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 16:46:45 +0200 Subject: [PATCH 01/11] Use unused variable --- tinystatus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinystatus b/tinystatus index dbd0fad..df047f4 100755 --- a/tinystatus +++ b/tinystatus @@ -59,7 +59,7 @@ while IFS='\n' read -r line; do name="$(get_element 3 "${line}")" host="$(get_element 4 "${line}")" check "${ctype}" "${host}" "${name}" "${code}" & -done < "${1:-checks.list}" +done < "${1:-$checkfile}" wait cat << EOF From 491fdce44f3ec8a12c2cae25666f5ef5d85e2654 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 16:58:19 +0200 Subject: [PATCH 02/11] Add success-based exit code --- tinystatus | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinystatus b/tinystatus index df047f4..eed6c50 100755 --- a/tinystatus +++ b/tinystatus @@ -84,8 +84,10 @@ EOF outagenb=$(find ${tmp}/ko -mindepth 1 | grep -c 'status$') if [ ${outagenb} -ne 0 ]; then echo "" + exitcode=1 else echo "" + exitcode=0 fi cat << EOF

Services

@@ -120,3 +122,5 @@ cat </dev/null +# Allow the script execution itself to signal success, e.g. for use in healthchecks +exit ${exitcode} From d7a3feb6f377431e2c445873816f7e42deeae624 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 17:01:07 +0200 Subject: [PATCH 03/11] Use ISO8601 date format The manually formatted date string was very close to ISO8601 already, so just it directly. Conforms to standards, is much easier in code (less manual work), and carries timezone information. --- tinystatus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinystatus b/tinystatus index eed6c50..c80c6d9 100755 --- a/tinystatus +++ b/tinystatus @@ -106,7 +106,7 @@ for file in ${tmp}/ok/*.status; do done cat << EOF -

Last check: $(date +"%Y/%m/%d %H:%M:%S")

+

Last check: $(date -I'seconds')

EOF if [ -f "${incidentsfile}" ]; then echo '

Incidents

' From 1de60a20d71ace2652f25fafd137dc1df94c760c Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 17:03:37 +0200 Subject: [PATCH 04/11] Add command existence check for ping --- tinystatus | 1 + 1 file changed, 1 insertion(+) diff --git a/tinystatus b/tinystatus index c80c6d9..ded7797 100755 --- a/tinystatus +++ b/tinystatus @@ -51,6 +51,7 @@ check(){ command_exists 'curl' command_exists 'nc' +command_exists 'ping' mkdir -p "${tmp}/ok" "${tmp}/ko" || exit 1 while IFS='\n' read -r line; do From 6ec20342f00374c9f4baaa2b5337932c36d5eba0 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 17:25:25 +0200 Subject: [PATCH 05/11] Use comma-separated value text file CSV is a well-supported standard and makes things more predictable/easier to see where things go. --- README.md | 2 +- checks.csv | 4 ++++ checks.list | 4 ---- tinystatus | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 checks.csv delete mode 100644 checks.list diff --git a/README.md b/README.md index 5685834..51ba1f1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ An example site is available [here](https://lab.bdro.fr/tinystatus/). To install tinystatus: * Clone the repository and go to the created directory -* Edit the checks file `checks.list` +* Edit the checks file `checks.csv` * To add incidents or maintenance, edit `incidents.list` * Generate status page `./tinystatus > index.html` * Serve the page with your favorite web server diff --git a/checks.csv b/checks.csv new file mode 100644 index 0000000..76f0437 --- /dev/null +++ b/checks.csv @@ -0,0 +1,4 @@ +http, 200, Google Website, https://google.com +http, 404, Google 404, https://google.com/dummy +ping, 0, Google ping, 8.8.8.8 +port, 0, Google DNS, 8.8.8.8:53 diff --git a/checks.list b/checks.list deleted file mode 100644 index 07a1543..0000000 --- a/checks.list +++ /dev/null @@ -1,4 +0,0 @@ -http | 200 | Google website | https://google.com -http | 404 | Google 404 | https://google.com/dummy -ping | 0 | Google ping | 8.8.8.8 -port | 0 | Google dns | 8.8.8.8:53 diff --git a/tinystatus b/tinystatus index ded7797..89f0032 100755 --- a/tinystatus +++ b/tinystatus @@ -3,7 +3,7 @@ title=tinystatus timeout=10 tmp="$(mktemp -d)" -checkfile="${1:-checks.list}" +checkfile="${1:-checks.csv}" incidentsfile="${2:-incidents.list}" useragent="User-Agent: Mozilla/5.0 (X11; Linux x86_64; Debian) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" @@ -15,7 +15,7 @@ command_exists(){ } get_element(){ - echo "${2}" | awk -v col="${1}" -F'|' '{gsub(/^[ \t]+|[ \t]+$/, "", $col); print $col}' + echo "${2}" | awk -v col="${1}" -F',' '{gsub(/^[ \t]+|[ \t]+$/, "", $col); print $col}' } check(){ From 7816a006d20ec8e5d14dd54176651b9190047e25 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 16:58:19 +0200 Subject: [PATCH 06/11] Add success-based exit code --- tinystatus | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinystatus b/tinystatus index 838370b..2a9fa28 100755 --- a/tinystatus +++ b/tinystatus @@ -86,8 +86,10 @@ EOF outagenb=$(find ${tmp}/ko -mindepth 1 | grep -c 'status$') if [ ${outagenb} -ne 0 ]; then echo "
  • ${outagenb} Outage(s)
" + exitcode=1 else echo "
  • All Systems Operational
" + exitcode=0 fi cat << EOF

Services

@@ -122,3 +124,5 @@ cat </dev/null +# Allow the script execution itself to signal success, e.g. for use in healthchecks +exit ${exitcode} From 4bc6382e0a56f4a5f6e3b9b0458e365a4d973e43 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 17:01:07 +0200 Subject: [PATCH 07/11] Use ISO8601 date format The manually formatted date string was very close to ISO8601 already, so just it directly. Conforms to standards, is much easier in code (less manual work), and carries timezone information. --- tinystatus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinystatus b/tinystatus index 2a9fa28..7335a23 100755 --- a/tinystatus +++ b/tinystatus @@ -108,7 +108,7 @@ for file in ${tmp}/ok/*.status; do done cat << EOF -

Last check: $(date +"%Y/%m/%d %H:%M:%S")

+

Last check: $(date -I'seconds')

EOF if [ -f "${incidentsfile}" ]; then echo '

Incidents

' From 5bba428b4c04f5f75471c04010117cb520edca22 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 17:03:37 +0200 Subject: [PATCH 08/11] Add command existence check for ping --- tinystatus | 1 + 1 file changed, 1 insertion(+) diff --git a/tinystatus b/tinystatus index 7335a23..f2e7e34 100755 --- a/tinystatus +++ b/tinystatus @@ -53,6 +53,7 @@ check(){ command_exists 'curl' command_exists 'nc' +command_exists 'ping' mkdir -p "${tmp}/ok" "${tmp}/ko" || exit 1 while IFS='\n' read -r line; do From 11bddbb4faabd43e5b1bfc7d3c4c827b918be89d Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 17:25:25 +0200 Subject: [PATCH 09/11] Use comma-separated value text file CSV is a well-supported standard and makes things more predictable/easier to see where things go. --- README.md | 2 +- checks.csv | 6 ++++++ checks.list | 6 ------ tinystatus | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 checks.csv delete mode 100644 checks.list diff --git a/README.md b/README.md index 0208e72..1bb13b3 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ An example site is available [here](https://lab.bdro.fr/tinystatus/). To install tinystatus: * Clone the repository and go to the created directory -* Edit the checks file `checks.list` +* Edit the checks file `checks.csv` * To add incidents or maintenance, edit `incidents.list` * Generate status page `./tinystatus > index.html` * Serve the page with your favorite web server diff --git a/checks.csv b/checks.csv new file mode 100644 index 0000000..176f1b6 --- /dev/null +++ b/checks.csv @@ -0,0 +1,6 @@ +http, 200, Google Website, https://google.com +http, 404, Google 404, https://google.com/dummy +http4, 200, Google website (IPv4), https://google.com +http6, 200, Google website (IPv6), https://google.com +ping, 0, Google ping, 8.8.8.8 +port, 0, Google DNS, 8.8.8.8 53 diff --git a/checks.list b/checks.list deleted file mode 100644 index 7375b0b..0000000 --- a/checks.list +++ /dev/null @@ -1,6 +0,0 @@ -http | 200 | Google website | https://google.com -http4 | 200 | Google website (IPv4) | https://google.com -http6 | 200 | Google website (IPv6) | https://google.com -http | 404 | Google 404 | https://google.com/dummy -ping | 0 | Google ping | 8.8.8.8 -port | 0 | Google dns | 8.8.8.8 53 diff --git a/tinystatus b/tinystatus index f2e7e34..ea0b35b 100755 --- a/tinystatus +++ b/tinystatus @@ -3,7 +3,7 @@ title=tinystatus timeout=10 tmp="$(mktemp -d)" -checkfile="${1:-checks.list}" +checkfile="${1:-checks.csv}" incidentsfile="${2:-incidents.list}" useragent="User-Agent: Mozilla/5.0 (X11; Linux x86_64; Debian) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" @@ -15,7 +15,7 @@ command_exists(){ } get_element(){ - echo "${2}" | awk -v col="${1}" -F'|' '{gsub(/^[ \t]+|[ \t]+$/, "", $col); print $col}' + echo "${2}" | awk -v col="${1}" -F',' '{gsub(/^[ \t]+|[ \t]+$/, "", $col); print $col}' } check(){ From fc08556c783a9b6de48cc2813aaa1aff6d5d60ab Mon Sep 17 00:00:00 2001 From: BDR Date: Mon, 29 Mar 2021 21:25:41 +0200 Subject: [PATCH 10/11] Rebase with master --- README.md | 8 ++++---- incidents.list => incidents.txt | 0 tinystatus | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename incidents.list => incidents.txt (100%) diff --git a/README.md b/README.md index 1bb13b3..1c4a81b 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,15 @@ To install tinystatus: * Clone the repository and go to the created directory * Edit the checks file `checks.csv` -* To add incidents or maintenance, edit `incidents.list` +* To add incidents or maintenance, edit `incidents.txt` * Generate status page `./tinystatus > index.html` * Serve the page with your favorite web server ## Configuration file -The syntax of `checks.list` file is: +The syntax of `checks.csv` file is: ``` -Command | Expected Code | Status Text | Host to check +Command, Expected Code, Status Text, Host to check ``` Command can be: @@ -38,4 +38,4 @@ Command can be: * `port` - Check open port status There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6` for IPv4 or IPv6 only check. - +Note: `port4` and `port6` require OpenBSD `nc` binary. diff --git a/incidents.list b/incidents.txt similarity index 100% rename from incidents.list rename to incidents.txt diff --git a/tinystatus b/tinystatus index ea0b35b..454520c 100755 --- a/tinystatus +++ b/tinystatus @@ -4,7 +4,7 @@ title=tinystatus timeout=10 tmp="$(mktemp -d)" checkfile="${1:-checks.csv}" -incidentsfile="${2:-incidents.list}" +incidentsfile="${2:-incidents.txt}" useragent="User-Agent: Mozilla/5.0 (X11; Linux x86_64; Debian) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" command_exists(){ From 3d820a67cb4926d3bc33bee0e75de67f8ec40a82 Mon Sep 17 00:00:00 2001 From: BDR Date: Tue, 30 Mar 2021 17:42:11 +0200 Subject: [PATCH 11/11] Add error code on outage --- tinystatus | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tinystatus b/tinystatus index 454520c..1ad33f6 100755 --- a/tinystatus +++ b/tinystatus @@ -5,6 +5,7 @@ timeout=10 tmp="$(mktemp -d)" checkfile="${1:-checks.csv}" incidentsfile="${2:-incidents.txt}" +failonoutage=false useragent="User-Agent: Mozilla/5.0 (X11; Linux x86_64; Debian) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" command_exists(){ @@ -87,10 +88,8 @@ EOF outagenb=$(find ${tmp}/ko -mindepth 1 | grep -c 'status$') if [ ${outagenb} -ne 0 ]; then echo "
  • ${outagenb} Outage(s)
" - exitcode=1 else echo "
  • All Systems Operational
" - exitcode=0 fi cat << EOF

Services

@@ -123,7 +122,9 @@ cat < EOF -rm -r "${tmp}" 2>/dev/null -# Allow the script execution itself to signal success, e.g. for use in healthchecks -exit ${exitcode} +rm -r "${tmp}" 2>/dev/null +if [ "${failonoutage}" = true ]; then + exit "${outagenb}" +fi +