minor alerts improvements
[distro-setup] / check-remote-mailqs
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
6
7 source /a/bin/errhandle/err
8
9 shopt -s nullglob
10 shopt -s dotglob
11
12 # this list duplicated in brc2 ralerts
13 for h in bk je li frodo kwwg x3wg x2wg kdwg sywg; do
14 statedir=/b/bash_unpublished/mailq-state
15 statefile=$statedir/$h
16 [[ -d $statedir ]] || continue
17 if [[ $HOSTNAME == "${h%wg}" ]]; then
18 rm -f $statefile
19 continue
20 fi
21 if c=$(timeout -v 10 ssh root@$h.b8.nz /usr/local/bin/check-mailq 2>&1 ); then
22 rm -f $statefile
23 if [[ $c ]]; then
24 echo q:$h=$c
25 fi
26 else
27 if [[ -s $statefile ]]; then
28 logsec=$(date +%s -d "$(head -n1 $statefile | awk '{print $1,$2}')")
29 nowsec=$(date +%s)
30 if (( logsec < nowsec - 60*60*48 )); then
31 echo $0: host $h ssh /usr/local/bin/check-mailq fail for over 48 hours
32 fi
33 fi
34 printf "%s\n" "$c" | ts "%F %T" >> $statefile
35 fi
36 done