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`
* 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 | 404 | Google 404 | https://google.com/dummy
ping | 0 | Google ping | 8.8.8.8
port | 0 | Google dns | 8.8.8.8:53
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

View file

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