From 571afc1b5d92b9b02f48ff589b9e0b638a986724 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Mon, 29 Mar 2021 16:46:45 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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(){