diff --git a/README.md b/README.md index 0208e72..1c4a81b 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,16 @@ 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` -* To add incidents or maintenance, edit `incidents.list` +* Edit the checks file `checks.csv` +* 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/checks.csv b/checks.csv new file mode 100644 index 0000000..fe07509 --- /dev/null +++ b/checks.csv @@ -0,0 +1,6 @@ +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/checks.list b/checks.list deleted file mode 100644 index afa77ab..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/incidents.list b/incidents.txt similarity index 100% rename from incidents.list rename to incidents.txt diff --git a/tinystatus b/tinystatus index 7f82c08..cb6f8d2 100755 --- a/tinystatus +++ b/tinystatus @@ -3,8 +3,9 @@ title=tinystatus timeout=10 tmp="$(mktemp -d)" -checkfile="${1:-checks.list}" -incidentsfile="${2:-incidents.list}" +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(){ @@ -15,7 +16,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(){ @@ -53,6 +54,7 @@ check(){ command_exists 'curl' command_exists 'nc' +command_exists 'ping' mkdir -p "${tmp}/ok" "${tmp}/ko" || exit 1 while IFS="$(printf '\n')" read -r line; do @@ -106,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

' @@ -120,5 +122,9 @@ cat < EOF -rm -r "${tmp}" 2>/dev/null + +rm -r "${tmp}" 2>/dev/null +if [ "${failonoutage}" = true ]; then + exit "${outagenb}" +fi