Improve script options
This commit is contained in:
parent
c25233e35a
commit
9debafb905
2 changed files with 65 additions and 32 deletions
8
README
8
README
|
@ -4,9 +4,11 @@ Nagios plugin to check Git Repository status
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Usage : ./check_git_config [directory] [-d]
|
Usage : ./check_git_config -g [directory] [-c|-r remote] [-d]
|
||||||
[directory] Git root directory (default : /srv/common)
|
-g [directory] Specify Git root directory (default : /srv/common)
|
||||||
[-d] Enable debug mode
|
-c Check Git remote state
|
||||||
|
-r [remote] Specify Git remote to check (default : origin)
|
||||||
|
-d Enable debug mode
|
||||||
|
|
||||||
Copyright
|
Copyright
|
||||||
---------
|
---------
|
||||||
|
|
|
@ -1,40 +1,59 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Nagios plugin to check Postgresql streamin replication state
|
# Nagios plugin to check Git repository status
|
||||||
#
|
|
||||||
# Could be use on Master or on standby node
|
|
||||||
#
|
|
||||||
# Requirement :
|
|
||||||
#
|
|
||||||
# On master node : Slaves must be able to connect with user PG_USER
|
|
||||||
# to database postgres as trust
|
|
||||||
#
|
|
||||||
# On standby node : PG_USER must be able to connect localy as trust
|
|
||||||
#
|
#
|
||||||
# Author : Benjamin Renard <brenard@easter-eggs.com>
|
# Author : Benjamin Renard <brenard@easter-eggs.com>
|
||||||
# Date : Wed, 14 Mar 2012 14:45:55 +0000
|
# Date : Wed, 14 Mar 2012 14:45:55 +0000
|
||||||
# Source : http://git.zionetrix.net/check_pg_streaming_replication
|
# Source : http://git.zionetrix.net/check_git_config
|
||||||
#
|
#
|
||||||
|
|
||||||
GIT_ROOT=/srv/common
|
GIT_ROOT=/srv/common
|
||||||
|
GIT_REMOTE=origin
|
||||||
|
DEBUG=0
|
||||||
|
CHECK_REMOTE=0
|
||||||
|
|
||||||
if [ "$1" == "-h" ]
|
function usage() {
|
||||||
then
|
echo "Usage : $0 -g [directory] [-c|-r remote] [-d]
|
||||||
echo "Usage : $0 [directory] [-d]
|
-g [directory] Specify Git root directory (default : $GIT_ROOT)
|
||||||
[directory] Git root directory (default : $GIT_ROOT)
|
-c Check Git remote state
|
||||||
[-d] Enable debug mode"
|
-r [remote] Specify Git remote to check (default : $GIT_REMOTE)
|
||||||
exit 0
|
-d Enable debug mode"
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
while getopts "g:r:cdh-:" OPTION
|
||||||
|
do
|
||||||
|
case "$OPTION" in
|
||||||
|
c)
|
||||||
|
CHECK_REMOTE=1
|
||||||
|
;;
|
||||||
|
g)
|
||||||
|
GIT_ROOT="${OPTARG}"
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
CHECK_REMOTE=1
|
||||||
|
GIT_REMOTE="${OPTARG}"
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
DEBUG=1
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid parameter -$OPTION"
|
||||||
|
echo
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
[ -n "$1" -a "$1" != "-d" ] && GIT_ROOT="$1"
|
|
||||||
[ ! -d "$GIT_ROOT" ] && echo "UNKNOWN : Git root directory does not exists !" && exit 3
|
[ ! -d "$GIT_ROOT" ] && echo "UNKNOWN : Git root directory does not exists !" && exit 3
|
||||||
[ ! -d "$GIT_ROOT/.git" ] && echo "UNKNOWN : Git root directory seem to not being a git repository." && exit 3
|
[ ! -d "$GIT_ROOT/.git" ] && echo "UNKNOWN : Git root directory seem to not being a git repository." && exit 3
|
||||||
|
|
||||||
cd $GIT_ROOT
|
cd $GIT_ROOT
|
||||||
|
|
||||||
DEBUG=0
|
|
||||||
[ "$1" == "-d" -o "$2" == "-d" ] && DEBUG=1
|
|
||||||
|
|
||||||
STATUS=$( git status -s )
|
STATUS=$( git status -s )
|
||||||
|
|
||||||
[ $DEBUG -eq 1 ] && echo -e "Status : $STATUS"
|
[ $DEBUG -eq 1 ] && echo -e "Status : $STATUS"
|
||||||
|
@ -43,11 +62,24 @@ if [ -n "$STATUS" ]
|
||||||
then
|
then
|
||||||
echo "WARNING : Git config repo on $( hostname ) not clean"
|
echo "WARNING : Git config repo on $( hostname ) not clean"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
elif [ $CHECK_REMOTE -eq 1 ]
|
||||||
[ $DEBUG -eq 1 ] && echo -n "Fecth : "
|
then
|
||||||
git fetch > /dev/null 2>&1
|
# Check remote exists
|
||||||
|
[ $DEBUG -eq 1 ] && echo -n "Check remote '$GIT_REMOTE' exist : "
|
||||||
|
git remote show "$GIT_REMOTE" > /dev/null 2>&1
|
||||||
res=$?
|
res=$?
|
||||||
[ $DEBUG -eq 1 ] && echo "done. (Return $?)"
|
[ $DEBUG -eq 1 ] && echo "done. (Return $res)"
|
||||||
|
|
||||||
|
if [ $res -ne 0 ]
|
||||||
|
then
|
||||||
|
echo "UNKNOWN : Unkown remote '$GIT_REMOTE'"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ $DEBUG -eq 1 ] && echo -n "Fecth : "
|
||||||
|
git fetch "$GIT_REMOTE" > /dev/null 2>&1
|
||||||
|
res=$?
|
||||||
|
[ $DEBUG -eq 1 ] && echo "done. (Return $res)"
|
||||||
|
|
||||||
if [ $res -ne 0 ]
|
if [ $res -ne 0 ]
|
||||||
then
|
then
|
||||||
|
@ -65,8 +97,7 @@ else
|
||||||
then
|
then
|
||||||
echo "CRITICAL : Git config not uptodate"
|
echo "CRITICAL : Git config not uptodate"
|
||||||
exit 2
|
exit 2
|
||||||
else
|
|
||||||
echo "OK"
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
echo "OK"
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue