#!/bin/sh -e catfiles() { for f in $@ ; do [ -s $f ] || continue sed 's/&/\&/g ; s//\>/g' < $f done } SGMONDIR="$(dirname "$(realpath -- "$0")")" . "$SGMONDIR"/rc probes="$("$SGMONDIR"/probelist.sh)" gut=`mktemp` bad=`mktemp` trap "rm -fr $gut $bad" HUP PIPE INT QUIT TERM EXIT cat < sgmon status $(date -Iseconds) EOF for probe in $probes ; do if [ -s $probe/state/attempts ] ; then read attempts < $probe/state/attempts || attempts=1 mtime=$(stat -t "%F %T" -f %Sm $probe/state/attempts) [ -s max-attempts ] && read max_attempts < max-attempts || max_attempts=1 [ "$attempts" -lt "$max_attempts" ] && status="Prefail" || status="FAIL" status="$status (${attempts}/${max_attempts})" list=$bad else if [ -r $probe/state/ok ] ; then mtime=$(stat -t "%F %T" -f %Sm $probe/state/ok) status=OK else mtime= status="???" fi list=$gut fi cat >>$list < EOF done cat $bad $gut echo "
StatusProbeLastMessage
$status $probe $mtime
$(catfiles $probe/state/stdout $probe/state/stderr)
"