#!/bin/bash
# SYNOPSIS
#	check_ncd
#
# DESCRIPTION
#	This NAGIOS plugin checks whether the last run NCM client front
#        end for invoking components returned an error or not
#
# AUTHOR
#	ctria@grid.auth.gr

OK=0
WARN=1
CRITICAL=2
UNKNOWN=3
PATH="/bin:/sbin:/usr/bin:/usr/sbin"

last_summary=`(for i in \`seq 10 -1 1\`; do zcat /var/log/ncm/ncd.log.$i.gz; done; cat  /var/log/ncm/ncd.log) | grep "warnings executing configure"|tail -n 1`

status=`echo $last_summary |awk -F"[" '{print $2}'|awk -F"]" '{print $1}'`

echo "$last_summary"
case $status in
  OK) exit $OK ;;
  ERROR) exit $CRITICAL ;;
  WARN) exit $WARN ;;
  *) exit $UNKNOWN ;;
esac

