#!/usr/bin/python # # (c) Michael Honkoop # License: GNU General Public License v2 # Version 0.1 # - Initial release # Version 0.2 # - refined routines to cover output more accurately. # A similar check is available in this repository written in bash (edir-version.sh) # # If you want more then just a version-check on eDirectory, consider switching to the plugin/special agent for eDirectory. # This check should be placed in /usr/lib/check_mk_agent/local and made executable with `chmod +x edir-version.py` # The script assumes that you have exported the environment variables when installing eDirectory, if not it will fail/not get detected on discovery. import subprocess import sys # The process to be executed myexec = "ndsd" # the displayed service in CheckMK service = "eDirectory" # Attempt to run the executable, if successful output CheckMK formatted data, if not found return unknown status. try: output = subprocess.check_output( [myexec, "--version"], stderr=subprocess.STDOUT, universal_newlines=True ) output_arr = output.split() # output status when the executable returns expected result if len(output_arr) >= 4: print('0 "eDirectory" - Binary Version: {}, DS Version: {}'.format( output_arr[2], output_arr[3] )) else: print('3 "eDirectory" - Unable to parse version output') # Executable not found handling except FileNotFoundError: print('3 "eDirectory" - ndsd executable not found') exit() # Executable exists, but returned an error handling except subprocess.CalledProcessError as e: print('2 "eDirectory" - ndsd returned error: {}'.format(e.returncode)) exit() # Catch unexpected errors except Exception as e: print('3 "eDirectory" - Unexpected error: {}'.format(e)) exit()