Rely on standards

This commit is contained in:
BDR 2021-03-30 21:47:39 +02:00
parent bf36d1c614
commit 6f13dd13df
5 changed files with 22 additions and 16 deletions

View file

@ -20,16 +20,16 @@ An example site is available [here](https://lab.bdro.fr/tinystatus/).
To install tinystatus: To install tinystatus:
* Clone the repository and go to the created directory * 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` * To add incidents or maintenance, edit `incidents.txt`
* 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 ## 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: Command can be:
@ -38,4 +38,4 @@ Command can be:
* `port` - Check open port status * `port` - Check open port status
There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6` for IPv4 or IPv6 only check. There are also `http4`, `http6`, `ping4`, `ping6`, `port4`, `port6` for IPv4 or IPv6 only check.
Note: `port4` and `port6` require OpenBSD `nc` binary.

6
checks.csv Normal file
View file

@ -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
1 http 200 Google Website https://google.com
2 http4 200 Google Website (IPv4) https://google.com
3 http6 200 Google Website (IPv6) https://google.com
4 http 404 Google 404 https://google.com/dummy
5 ping 0 Google ping 8.8.8.8
6 port 0 Google DNS 8.8.8.8 53

View file

@ -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

View file

@ -3,8 +3,9 @@
title=tinystatus title=tinystatus
timeout=10 timeout=10
tmp="$(mktemp -d)" tmp="$(mktemp -d)"
checkfile="${1:-checks.list}" checkfile="${1:-checks.csv}"
incidentsfile="${2:-incidents.list}" 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" 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(){ command_exists(){
@ -15,7 +16,7 @@ command_exists(){
} }
get_element(){ 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(){ check(){
@ -53,6 +54,7 @@ check(){
command_exists 'curl' command_exists 'curl'
command_exists 'nc' command_exists 'nc'
command_exists 'ping'
mkdir -p "${tmp}/ok" "${tmp}/ko" || exit 1 mkdir -p "${tmp}/ok" "${tmp}/ko" || exit 1
while IFS="$(printf '\n')" read -r line; do while IFS="$(printf '\n')" read -r line; do
@ -106,7 +108,7 @@ for file in "${tmp}/ok/"*.status; do
done done
cat << EOF cat << EOF
</ul> </ul>
<p class=small> Last check: $(date +"%Y/%m/%d %H:%M:%S")</p> <p class=small> Last check: $(date -I'seconds')</p>
EOF EOF
if [ -f "${incidentsfile}" ]; then if [ -f "${incidentsfile}" ]; then
echo '<h1>Incidents</h1>' echo '<h1>Incidents</h1>'
@ -120,5 +122,9 @@ cat <<EOF
</div> </div>
</body></html> </body></html>
EOF EOF
rm -r "${tmp}" 2>/dev/null
rm -r "${tmp}" 2>/dev/null
if [ "${failonoutage}" = true ]; then
exit "${outagenb}"
fi