]> Sergey Matveev's repositories - sgmon.git/blob - status.sh
d0c724378f3216ae9ffc015a149507dd7f295e2f
[sgmon.git] / status.sh
1 #!/bin/sh -e
2
3 catfiles() {
4     for f in $@ ; do
5         [ -s $f ] || continue
6         sed 's/&/\&amp;/g ; s/</\&lt;/g ; s/>/\&gt;/g' < $f
7     done
8 }
9
10 SGMONDIR="$(dirname "$(realpath -- "$0")")"
11 . "$SGMONDIR"/rc
12 probes="$("$SGMONDIR"/probelist.sh)"
13 gut=`mktemp`
14 bad=`mktemp`
15 trap "rm -fr $gut $bad" HUP PIPE INT QUIT TERM EXIT
16 cat <<EOF
17 <!DOCTYPE html>
18 <html><head><title>sgmon status $(date -Iseconds)</title></head><body>
19 <table border=1>
20 <tr><th>Status</th><th>probe</th><th>Last</th><th>Message</th></tr>
21 EOF
22 for probe in $probes ; do
23     if [ -s $probe/state/attempts ] ; then
24         read attempts < $probe/state/attempts || attempts=1
25         mtime=$(stat -t "%F %T" -f %Sm $probe/state/attempts)
26         [ -s max-attempts ] && read max_attempts < max-attempts || max_attempts=1
27         [ "$attempts" -lt "$max_attempts" ] &&
28             status="<b>Prefail</b>" || status="<b>FAIL</b>"
29         status="$status (${attempts}/${max_attempts})"
30         list=$bad
31     else
32         if [ -r $probe/state/ok ] ; then
33             mtime=$(stat -t "%F %T" -f %Sm $probe/state/ok)
34             status=OK
35         else
36             mtime=
37             status="???"
38         fi
39         list=$gut
40     fi
41     cat >>$list <<EOF
42 <tr>
43     <td>$status</td>
44     <td><tt><a name="$probe">$probe</a></tt></td>
45     <td><tt>$mtime</tt></td>
46     <td><pre>$(catfiles $probe/state/stdout $probe/state/stderr)</pre></td>
47 </tr>
48 EOF
49 done
50 cat $bad $gut
51 echo "</table></body></html>"