| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #!/usr/bin/env python3
- #
- # (c) Michael Honkoop <mhonkoop@comsolve.nl>
- # 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()
|