]> Sergey Matveev's repositories - sgmon.git/blob - status.sh
Remove state symlink too
[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 cat <<EOF
14 <!DOCTYPE html>
15 <html><head><title>sgmon status $(date -Iseconds)</title></head><body>
16 <table border=1>
17 <tr><th>Status</th><th>probe</th><th>Last</th><th>Message</th></tr>
18 EOF
19 for probe in $probes ; do
20     if [ -s $probe/state/attempts ] ; then
21         read attempts < $probe/state/attempts || attempts=1
22         mtime=$(stat -t "%F %T" -f %Sm $probe/state/attempts)
23         [ -s max-attempts ] && read max_attempts < max-attempts || max_attempts=1
24         [ "$attempts" -lt "$max_attempts" ] &&
25             status="<b>Prefail</b>" || status="<b>FAIL</b>"
26         status="$status (${attempts}/${max_attempts})"
27     else
28         if [ -r $probe/state/ok ] ; then
29             mtime=$(stat -t "%F %T" -f %Sm $probe/state/ok)
30             status=OK
31         else
32             mtime=
33             status="???"
34         fi
35     fi
36     cat <<EOF
37 <tr>
38     <td>$status</td>
39     <td><tt><a name="$probe">$probe</a></tt></td>
40     <td><tt>$mtime</tt></td>
41     <td><pre>$(catfiles $probe/state/stdout $probe/state/stderr)</pre></td>
42 </tr>
43 EOF
44 done
45 echo "</table></body></html>"