Skip to content
Browse files


  • Loading branch information...
HariSekhon committed Jul 4, 2018
1 parent ade98a2 commit 23b5b9197ab048f845cd4370fbe53954f94f41a8
Showing with 82 additions and 0 deletions.
  1. +82 −0
@@ -0,0 +1,82 @@
#!/usr/bin/env python
# vim:ts=4:sts=4:sw=4:et
# Author: Hari Sekhon
# Date: 2016-07-25 14:57:36 +0100 (Mon, 25 Jul 2016)
# License: see accompanying Hari Sekhon LICENSE file
# If you're using my code you're welcome to connect with me on LinkedIn
# and optionally send me feedback to help steer this or other code I publish

Nagios Plugin to check a Git checkout working directory isn't a 'remote'
Requires the 'git' command in the $PATH, otherwise you can set the path to the git
executable using the environment variable GIT_PYTHON_GIT_EXECUTABLE
See also

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
#from __future__ import unicode_literals

import os
import sys
import traceback
import git
srcdir = os.path.abspath(os.path.dirname(__file__))
libdir = os.path.join(srcdir, 'pylib')
# pylint: disable=wrong-import-position
from git import InvalidGitRepositoryError
from harisekhon.utils import CriticalError, validate_directory
from harisekhon import NagiosPlugin
except ImportError as _:
print(traceback.format_exc(), end='')

__author__ = 'Hari Sekhon'
__version__ = '0.1'

class CheckGitCheckoutRemote(NagiosPlugin):

def __init__(self):
# Python 2.x
super(CheckGitCheckoutRemote, self).__init__()
# Python 3.x
# super().__init__()
self.msg = 'CheckGitCheckoutRemote msg not defined'

def add_options(self):
self.add_opt('-d', '--directory', action='store', help='Path to git checkout directory')

def run(self):
directory = self.get_opt('directory')
directory = os.path.abspath(directory)
repo = git.Repo(directory)
except InvalidGitRepositoryError:
raise CriticalError("directory '{}' does not contain a valid Git repository!".format(directory))
is_remote = repo.head.is_remote()
self.msg = "git checkout remote = '{}' for directory '{}'".format(is_remote, directory)
if is_remote:

if __name__ == '__main__':

0 comments on commit 23b5b91

Please sign in to comment.
You can’t perform that action at this time.