From c25233e35ac008cddc9ad39cc88074b202740c8e Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 3 Dec 2013 16:05:37 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + README | 30 ++++++++++++++++++++ check_git_config | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 .gitignore create mode 100644 README create mode 100755 check_git_config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/README b/README new file mode 100644 index 0000000..9198f6e --- /dev/null +++ b/README @@ -0,0 +1,30 @@ +Nagios plugin to check Git Repository status +============================================ + +Usage +----- + + Usage : ./check_git_config [directory] [-d] + [directory] Git root directory (default : /srv/common) + [-d] Enable debug mode + +Copyright +--------- + +Copyright (c) 2013 Benjamin Renard + +License +------- + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License version 2 +as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. diff --git a/check_git_config b/check_git_config new file mode 100755 index 0000000..ae5db09 --- /dev/null +++ b/check_git_config @@ -0,0 +1,72 @@ +#!/bin/bash +# +# Nagios plugin to check Postgresql streamin replication state +# +# 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 +# Date : Wed, 14 Mar 2012 14:45:55 +0000 +# Source : http://git.zionetrix.net/check_pg_streaming_replication +# + +GIT_ROOT=/srv/common + +if [ "$1" == "-h" ] +then + echo "Usage : $0 [directory] [-d] + [directory] Git root directory (default : $GIT_ROOT) + [-d] Enable debug mode" + exit 0 +fi + +[ -n "$1" -a "$1" != "-d" ] && GIT_ROOT="$1" +[ ! -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 + +cd $GIT_ROOT + +DEBUG=0 +[ "$1" == "-d" -o "$2" == "-d" ] && DEBUG=1 + +STATUS=$( git status -s ) + +[ $DEBUG -eq 1 ] && echo -e "Status : $STATUS" + +if [ -n "$STATUS" ] +then + echo "WARNING : Git config repo on $( hostname ) not clean" + exit 1 +else + [ $DEBUG -eq 1 ] && echo -n "Fecth : " + git fetch > /dev/null 2>&1 + res=$? + [ $DEBUG -eq 1 ] && echo "done. (Return $?)" + + if [ $res -ne 0 ] + then + echo "UNKNOWN : Error fetching remote" + exit 3 + fi + + HEAD="$( git show HEAD|grep ^commit )" + [ $DEBUG -eq 1 ] && echo "Local : $HEAD" + + ORIGIN="$( git show origin|grep ^commit )" + [ $DEBUG -eq 1 ] && echo "Remote : $ORIGIN" + + if [ "$HEAD" != "$ORIGIN" ] + then + echo "CRITICAL : Git config not uptodate" + exit 2 + else + echo "OK" + exit 0 + fi +fi