X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=system-status;h=f39f03176fdae290843d45ea851641ade5b21056;hb=23883bc99075d156fb9aecce6ec6fb68277a8367;hp=231e61083f0a03eb4f4168b01ec257896b2a4443;hpb=f6501ed8450080e799b9293a2b38f3381e791db4;p=distro-setup diff --git a/system-status b/system-status index 231e610..f39f031 100755 --- a/system-status +++ b/system-status @@ -2,37 +2,78 @@ # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later +# usage: runs 4 times every 15 seconds unless any args are passed, then just runs once + if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -f=/dev/shm/iank-status +status_file=/dev/shm/iank-status + +shopt -s nullglob +shopt -s dotglob + +lo() { /usr/local/bin/log-once -1 "$@"; } write-status() { chars=() - if test -e /nocow/btrfs-stale/*; then + glob=(/nocow/btrfs-stale/*) + if [[ -e $glob ]] ; then chars+=("STALE!") fi - if test -e /m/md/bounces/new/*; then + glob=(/m/md/bounces/new/*) + if [[ -e $glob ]]; then chars+=("BOUNCE!") + lo bounce "message in /m/md/bounces/new" + fi + glob=(/m/md/alerts/new/* /m/md/alerts/cur/*) + if [[ -e $glob ]]; then + chars+=("ALERT!") fi if [[ -e /nocow/user/mailtest-failure ]]; then chars+=("MAILPING!") + lo mailping "mailtest-check didnt see mail from send-test-forward" fi if [[ -s /var/log/exim4/paniclog ]]; then chars+=("PANIC!") + tail /var/log/exim4/paniclog | lo paniclog fi - cat /a/bin/bash_unpublished/source-state >$f + source /a/bin/bash_unpublished/source-state + if [[ $MAIL_HOST == $HOSTNAME ]]; then + if [[ $(systemctl is-active btrbk.timer) != active ]]; then + chars+=("BTRBK-TIMER!") + fi + + ## check if last snapshot was within an hour + vol=o + snaps=(/mnt/root/btrbk/$vol.20*) + now=$(date +%s) + maxtime=0 + for s in ${snaps[@]}; do + file=${s##*/} + t=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${file#$vol.}) +%s) + if (( t > maxtime )); then + maxtime=$t + fi + done + if (( maxtime < now - 60*60 )); then + chars+=("OLD-SNAPSHOT!") + fi + fi + + cat /a/bin/bash_unpublished/source-state >$status_file if [[ $chars ]]; then - echo "ps_char=\"${chars[*]} \$ps_char\"" >>$f + echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file fi + } write-status if [[ $@ ]]; then + cat $status_file exit 0 fi for ((i=1; i<=3; i++)); do