From 41c586a56def91efac476581b843b972c6d49082 Mon Sep 17 00:00:00 2001 From: Greg Cockburn Date: Fri, 9 Apr 2021 14:12:00 +1000 Subject: [PATCH 1/2] add dns functionality --- README.md | 9 +++++---- checks.csv | 5 +++++ tinystatus | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1c4a81bdc..f57937bab 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ tinystatus generate an html status page via shell script. ## Features * Parallel checks -* HTTP, ping, port checks +* HTTP, ping, port, dns checks * HTTP expected status code (401, ...) -* Minimal dependencies (curl, nc and coreutils) +* Minimal dependencies (curl, nc, dig and coreutils) * Easy configuration and customisation * Incident history (manual) @@ -36,6 +36,7 @@ Command can be: * `http` - Check http status * `ping` - Check ping status * `port` - Check open port status +* dns` - Check dns status -There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6` for IPv4 or IPv6 only check. -Note: `port4` and `port6` require OpenBSD `nc` binary. +There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6, dns4, dns6` for IPv4 or IPv6 only check. +Note: `port4` and `port6` require OpenBSD `nc` binary; dns4 and dns6 require Bind9 dig binary; diff --git a/checks.csv b/checks.csv index fe0750933..3ab9b8668 100644 --- a/checks.csv +++ b/checks.csv @@ -4,3 +4,8 @@ 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 +dns6, 0, Google DNS Test 1, AAAA;www.google.com;2001:4860:4860::8888 +dns4, 0, Google DNS Test 2, AAAA;www.google.com;2001:4860:4860::8888 +dns6, 0, Google DNS Test 3, AA;www.google.com;8.8.8.8 +dns4, 0, Google DNS Test 4, AA;www.google.com;8.8.8.8 +dns, 0, Google DNS Test 5, AA;www.google.com;8.8.8.8 diff --git a/tinystatus b/tinystatus index 5e841fb7d..08d1c9a22 100755 --- a/tinystatus +++ b/tinystatus @@ -19,6 +19,10 @@ get_element(){ echo "${2}" | awk -v col="${1}" -F',' '{gsub(/^[ \t]+|[ \t]+$/, "", $col); print $col}' } +get_item(){ + echo "${2}" | awk -v col="${1}" -F';' '{gsub(/^[ \t]+|[ \t]+$/, "", $col); print $col}' +} + check(){ ctype="${1}" host="${2}" @@ -37,6 +41,13 @@ check(){ error="$(nc -${IPv}w "${timeout}" -zv ${host} 2>&1)" statuscode=$? [ "${statuscode}" -ne "${expectedcode}" ] && echo "${error}" > "${tmp}/ko/${name}.error";; + dns*) + rrtype=$(get_item 1 "${host}") + rrhost=$(get_item 2 "${host}") + dnsserver=$(get_item 3 "${host}") + dig +short -${IPv}u "${rrtype}" "${rrhost}" @"${dnsserver}" > "${tmp}/ko/${name}.tmp" 2>&1 + statuscode=$? + [ "${statuscode}" -ne "${expectedcode}" ] && mv "${tmp}/ko/${name}.tmp" "${tmp}/ko/${name}.error";; esac # verity status and write files @@ -55,6 +66,7 @@ check(){ command_exists 'curl' command_exists 'nc' command_exists 'ping' +command_exists 'dig' mkdir -p "${tmp}/ok" "${tmp}/ko" || exit 1 while IFS="$(printf '\n')" read -r line; do From 0a61cebe188ef07821a50abcda8feeb9471dcc5e Mon Sep 17 00:00:00 2001 From: Greg Cockburn Date: Fri, 9 Apr 2021 14:33:56 +1000 Subject: [PATCH 2/2] fix readme markdown --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f57937bab..8a1b503ef 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Command can be: * `http` - Check http status * `ping` - Check ping status * `port` - Check open port status -* dns` - Check dns status +* `dns` - Check dns status -There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6, dns4, dns6` for IPv4 or IPv6 only check. -Note: `port4` and `port6` require OpenBSD `nc` binary; dns4 and dns6 require Bind9 dig binary; +There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6`, `dns4`, `dns6` for IPv4 or IPv6 only check. +Note: `port4` and `port6` require OpenBSD `nc` binary; `dns4` and `dns6` require Bind9 `dig` binary;