#!/bin/sh
#
# Push to Uptime Kuma
#
# 20250517  Kimmo Suominen
#

# CRON:
# * * * * * $HOME/.cron/link-monitor > /dev/null

PATH=/usr/bin
export PATH

URL=https://hzz.status.gw.fi/api/push

PROG="${0##*/}"

die()
{
    echo "${PROG}: ${@}" 1>&2
    exit 1
}

tokenfile="${HOME}/.config/${PROG}/token"
test -f "${tokenfile}" ||
die 'No token found'
token="$(sed '/^#/ d;' "${tokenfile}")"

ping="$(
  ping -q -n -c 1 -w 5 is.kimmo.online |
  sed -n '/^rtt/ {s,^.*= ,,; s,/.*$,,; p;}'
)"

curl -s "${URL}/${token}?status=up&msg=OK&ping=${ping}"
