From 3d22824472b0943db3b33829b2074628cc7f6fcf Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Thu, 2 May 2013 04:41:48 +0200 Subject: [PATCH] Added some additional checks and variables --- check_git_status | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/check_git_status b/check_git_status index 7ecdac9..e525282 100755 --- a/check_git_status +++ b/check_git_status @@ -7,21 +7,43 @@ # > nagios ALL=(root) NOPASSWD: /usr/local/lib/nagios/plugins/check_git_status /etc # should do the job. +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 + +GIT="/usr/bin/git" + REPO="${1}" -if [ -z "${REPO}" -o ! -d "${REPO}" ] +if [ ! -x ${GIT} ] then - echo 'No repo specified or no such repo'; - exit 3 + echo "Can't execute ${GIT}" + exit $STATE_UNKNOWN fi -cd "${REPO}" || exit 3 +if [ $# -lt 1 ] +then + echo "Usage: $0 " + exit $STATE_UNKNOWN +fi -if [ -z "$(git ls-files --modified --deleted --others --exclude-standard)" ] +if [ -z "${REPO}/.git" -o ! -d "${REPO}/.git" ] +then + echo "No repo specified or ${REPO} is not a git repo"; + exit $STATE_UNKNOWN +fi + +cd "${REPO}" || exit $STATE_UNKNOWN + +if [ -z "$(${GIT} ls-files --modified --deleted --others --exclude-standard)" ] then echo "No uncommited changes in ${REPO}" - exit 0 + exit $STATE_OK else echo "Uncommited changes in ${REPO}" - exit 1 + exit $STATE_WARNING fi + +echo "Someting went wrong" +exit $STATE_UNKNOWN