[BACK]Return to check_rsnapshot CVS log [TXT][DIR] Up to [local] / nagios / check_rsnapshot

File: [local] / nagios / check_rsnapshot / check_rsnapshot (download)

Revision 1.2, Sun Oct 13 03:20:52 2013 UTC (10 years, 6 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +17 -7 lines

Better output, more useful for looking at what it is doing

Doesn't mean you don't have to look at logs sometimes, but maybe not most of the time.

#!/bin/sh
# $Id: check_rsnapshot,v 1.2 2013/10/13 03:20:52 andrew Exp $

# This relies on my run_rsnapshot wrapper that outputs things
# via syslog, so really to custom to be much use.

. /usr/local/libexec/nagios/utils.sh

grep rsnapshot /var/log/messages | tail -25 | (
  STATUS=UNKNOWN
  LAST_STATUS=
  CRITICAL=
  UNKNOWN=
  while read line; do
	LAST_STATUS=`echo $line | cut -c 1-15`

    if [ "$line" != "${line% Starting snapshot*}" ]; then
      STATUS=STARTED
	  CRITICAL=
	  UNKNOWN=
    elif [ "$line" != "${line% Finished snapshot*}" ]; then
      if [ $STATUS != 'CRITICAL' ]; then
        STATUS=FINISHED
      fi
    elif [ "$line" != "${line% ERROR*}" ]; then
      STATUS=CRITICAL
      [ -n "$CRITICAL" ] && CRITICAL="$CRITICAL\n"
	  CRITICAL="$CRITICAL ${line#*]:}"
    elif [ $STATUS != CRITICAL ]; then
      STATUS=UNKNOWN
      [ -n "$UNKNOWN" ] && UNKNOWN="$UNKNOWN\n"
	  UNKNOWN="$UNKNOWN ${line#*]:}"
    fi
  done

  [ $STATUS != UNKNOWN -a -n "$UNKNOWN" ] && UNKNOWN="\n$UNKNOWN"

  if [ $STATUS = "STARTED" -o $STATUS = "FINISHED" ]; then
	$ECHO "OK: $STATUS $LAST_STATUS $UNKNOWN"
	exit $STATE_OK
  elif [ $STATUS = UNKNOWN ]; then
	$ECHO "UNKNOWN: $LAST_STATUS $UNKNOWN"
	exit $STATE_UNKNOWN
  else
	$ECHO "CRITICAL: $LAST_STATUS $CRITICAL $UNKNOWN"
	exit $STATE_CRITICAL
  fi
)