#!/usr/bin/env python3 # # (c) Michael Honkoop # # License: GNU General Public License v2 # # Version 0.1 # - Initial release # Version 0.2 # - Refined routines to cover output more accurately. # This Localcheck purely checks a/the version of the installed eDirectory. # If you want to monitor eDirectory more in-Depth, then concider using the plugin/Special Agent import subprocess import sys # The process to be executed myexec = "ndsd" # The displayed service in Checkmk service = "eDirectory" # Attempt to run the executable 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( f'0 "{service}" - Binary Version: ' f'{output_arr[2]}, DS Version: {output_arr[3]}' ) else: print(f'3 "{service}" - Unable to parse version output') # Executable not found except FileNotFoundError: print(f'3 "{service}" - {myexec} executable not found') # Executable exists, but returned an error except subprocess.CalledProcessError as e: print(f'2 "{service}" - {myexec} returned error: {e.returncode}') # Catch unexpected errors except Exception as e: print(f'3 "{service}" - Unexpected error: {e}') sys.exit(0)