#!/usr/bin/env bash # author: Daniel Sommer # license: MIT url="https://notify.velvettear.de/ups" user="velvettear" password="\$Velvet90" [[ -z "$1" ]] && printf "error: no argument specified\n" 1>&2 && exit 1 ups="eaton" charge="$(upsc $ups battery.charge 2> /dev/null)" time="$(upsc $ups battery.runtime 2> /dev/null)" time="$(date -d@$time -u '+%H:%M:%S')" title="$(printf "$1" | tr '[:upper:]' '[:lower:]')" prio="default" if [[ "$title" == "online" ]]; then msg="$ups is running on line power battery @ $charge% | $time" emoji="electric_plug" elif [[ "$title" == "onbatt" ]]; then msg="$ups is running on battery battery @ $charge% | $time" prio="high" emoji="battery" elif [[ "$title" == "lowbatt" ]]; then msg="$ups's battery is running low battery @ $charge% | $time" prio="max" emoji="exclamation" elif [[ "$title" == "fsd" ]]; then msg="forced shutdown in progress" prio="max" emoji="bangbang" elif [[ "$title" == "commok" ]]; then msg="communication with $ups established" emoji="heavy_check_mark" elif [[ "$title" == "commbad" ]]; then msg="communication with $ups lost" prio="high" emoji="x" elif [[ "$title" == "shutdown" ]]; then msg="shutdown in progress" prio="max" emoji="bangbang" elif [[ "$title" == "replbatt" ]]; then msg="$ups's battery is dying and needs to be replaced" prio="urgent" emoji="skull_and_crossbones" elif [[ "$title" == "nocomm" ]]; then msg="$ups is currently unavailable" prio="high" emoji="interrobang" elif [[ "$title" == "noparent" ]]; then msg="upsmon parent process died and no further actions are possible" prio="high" emoji="skull" elif [[ "$title" == "cal" ]]; then msg="$ups is currently calibrating" emoji="gear" elif [[ "$title" == "off" ]]; then msg="$ups is administratively off or asleep" emoji="grey_exclamation" elif [[ "$title" == "notoff" ]]; then msg="$ups is no longer administratively off or asleep" emoji="grey_exclamation" elif [[ "$title" == "bypass" ]]; then msg="$ups is currently bypassed" emoji="grey_exclamation" elif [[ "$title" == "notbypass" ]]; then msg="$ups is no longer bypassed" emoji="grey_exclamation" else printf "error: argument unknown\n" 1>&2 && exit 1 fi curl -u $user:$password -d "$msg" -H "Title: $title" -H "Priority: $prio" -H "Tags: $emoji" $url