Add IPv6 support

This commit is contained in:
BDR 2021-03-29 20:55:23 +02:00
parent fa070af0ec
commit 01893d422a
3 changed files with 34 additions and 16 deletions

View file

@ -25,3 +25,17 @@ To install tinystatus:
* Generate status page `./tinystatus > index.html` * Generate status page `./tinystatus > index.html`
* Serve the page with your favorite web server * Serve the page with your favorite web server
## Configuration file
The syntax of `checks.list` file is:
```
Command | Expected Code | Status Text | Host to check
```
Command can be:
* `http` - Check http status
* `ping` - Check ping status
* `port` - Check open port status
There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6` for IPv4 or IPv6 only check.

View file

@ -1,4 +1,6 @@
http | 200 | Google website | https://google.com http | 200 | Google website | https://google.com
http | 404 | Google 404 | https://google.com/dummy http4 | 200 | Google website (IPv4) | https://google.com
ping | 0 | Google ping | 8.8.8.8 http6 | 200 | Google website (IPv6) | https://google.com
port | 0 | Google dns | 8.8.8.8:53 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

View file

@ -24,17 +24,19 @@ check(){
name="${3}" name="${3}"
expectedcode="${4}" expectedcode="${4}"
if [ ${ctype} = 'http' ]; then IPv="$(echo "${ctype}" | grep -o '[0-9]$')"
statuscode="$(curl -sSkLo /dev/null -H "${useragent}" -m "${timeout}" -w "%{http_code}" "${host}" 2> "${tmp}/ko/${name}.error")" case "${ctype}" in
elif [ ${ctype} = 'port' ]; then http*)
error="$(nc -w "${timeout}" -zv $(echo "${host}" | sed 's,:, ,') 2>&1)" statuscode="$(curl -${IPv}sSkLo /dev/null -H "${useragent}" -m "${timeout}" -w "%{http_code}" "${host}" 2> "${tmp}/ko/${name}.error")";;
statuscode=$? ping*)
[ ${statuscode} -ne 0 ] && echo "${error}" > "${tmp}/ko/${name}.error" ping -W${IPv} "${timeout}" -c 1 "${host}" >/dev/null 2>&1
elif [ ${ctype} = 'ping' ]; then statuscode=$?
ping -W "${timeout}" -c 1 "${host}" >/dev/null 2>&1 [ ${statuscode} -ne ${expectedcode} ] && echo 'Host unreachable' > "${tmp}/ko/${name}.error";;
statuscode=$? port*)
[ ${statuscode} -ne 0 ] && echo 'Host unreachable' > "${tmp}/ko/${name}.error" error="$(nc -w${IPv} "${timeout}" -zv ${host} 2>&1)"
fi statuscode=$?
[ ${statuscode} -ne ${expectedcode} ] && echo "${error}" > "${tmp}/ko/${name}.error";;
esac
# verity status and write files # verity status and write files
if [ ${statuscode} -eq ${expectedcode} ]; then if [ ${statuscode} -eq ${expectedcode} ]; then
@ -59,7 +61,7 @@ while IFS='\n' read -r line; do
name="$(get_element 3 "${line}")" name="$(get_element 3 "${line}")"
host="$(get_element 4 "${line}")" host="$(get_element 4 "${line}")"
check "${ctype}" "${host}" "${name}" "${code}" & check "${ctype}" "${host}" "${name}" "${code}" &
done < "${1:-checks.list}" done < "${checkfile}"
wait wait
cat << EOF cat << EOF