fix vpn host naming
[distro-setup] / system-status
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 # usage: runs 4 times every 15 seconds unless any args are passed, then just runs once
6
7 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
8
9 source /a/bin/errhandle/err
10 status_file=/dev/shm/iank-status
11
12 shopt -s nullglob
13 shopt -s dotglob
14
15 lo() { /usr/local/bin/log-once "$@"; }
16
17 write-status() {
18 chars=()
19
20 glob=(/nocow/btrfs-stale/*)
21 if [[ -e ${glob[0]} ]]; then
22 chars+=("STALE!")
23 fi
24 glob=(/m/md/bounces/new/*)
25 if [[ -e ${glob[0]} ]]; then
26 chars+=("BOUNCE!")
27 lo -1 bounce "message in /m/md/bounces/new"
28 fi
29 glob=(/m/md/alerts/new/* /m/md/alerts/cur/*)
30 if [[ -e ${glob[0]} ]]; then
31 chars+=("ALERT!")
32 fi
33 if [[ -e /nocow/user/mailtest-failure ]]; then
34 chars+=("MAILPING!")
35 fi
36 if [[ -s /var/log/exim4/paniclog ]]; then
37 chars+=("PANIC!")
38 tail /var/log/exim4/paniclog | lo -1 paniclog
39 fi
40
41 source /a/bin/bash_unpublished/source-state
42 if [[ $MAIL_HOST == "$HOSTNAME" ]]; then
43 if [[ $(systemctl is-active btrbk.timer) != active ]]; then
44 chars+=("BTRBK.TIMER!")
45 lo -60 btrbk.timer "btrbk.timer not enabled"
46 fi
47
48 ## check if last snapshot was within an hour
49 vol=o
50 snaps=(/mnt/root/btrbk/$vol.20*)
51 now=$(date +%s)
52 maxtime=0
53 for s in ${snaps[@]}; do
54 file=${s##*/}
55 t=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${file#$vol.}) +%s)
56 if (( t > maxtime )); then
57 maxtime=$t
58 fi
59 done
60 if (( maxtime < now - 60*60 )); then
61 chars+=("OLD-SNAPSHOT!")
62 lo -1 old-snapshot "/o snapshot older than 1 hour"
63 fi
64 fi
65
66 cat /a/bin/bash_unpublished/source-state >$status_file
67
68 if [[ ${chars[*]} ]]; then
69 echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file
70 fi
71
72 }
73 write-status
74 if [[ $1 ]]; then
75 cat $status_file
76 exit 0
77 fi
78 for ((i=1; i<=3; i++)); do
79 sleep 15
80 write-status
81 done