1
0

edir-version.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. #
  3. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  4. # License: GNU General Public License v2
  5. # Version 0.1
  6. # - Initial release
  7. # Version 0.2
  8. # - refined routines to cover output more accurately.
  9. # A similar check is available in this repository written in bash (edir-version.sh)
  10. #
  11. # If you want more then just a version-check on eDirectory, consider switching to the plugin/special agent for eDirectory.
  12. # This check should be placed in /usr/lib/check_mk_agent/local and made executable with `chmod +x edir-version.py`
  13. # The script assumes that you have exported the environment variables when installing eDirectory, if not it will fail/not get detected on discovery.
  14. import subprocess
  15. import sys
  16. # The process to be executed
  17. myexec = "ndsd"
  18. # the displayed service in CheckMK
  19. service = "eDirectory"
  20. # Attempt to run the executable, if successful output CheckMK formatted data, if not found return unknown status.
  21. try:
  22. output = subprocess.check_output(
  23. [myexec, "--version"],
  24. stderr=subprocess.STDOUT,
  25. universal_newlines=True
  26. )
  27. output_arr = output.split()
  28. # output status when the executable returns expected result
  29. if len(output_arr) >= 4:
  30. print('0 "eDirectory" - Binary Version: {}, DS Version: {}'.format(
  31. output_arr[2], output_arr[3]
  32. ))
  33. else:
  34. print('3 "eDirectory" - Unable to parse version output')
  35. # Executable not found handling
  36. except FileNotFoundError:
  37. print('3 "eDirectory" - ndsd executable not found')
  38. exit()
  39. # Executable exists, but returned an error
  40. except subprocess.CalledProcessError as e:
  41. print('2 "eDirectory" - ndsd returned error: {}'.format(e.returncode))
  42. exit()
  43. # Catch unexpected errors
  44. except Exception as e:
  45. print('3 "eDirectory" - Unexpected error: {}'.format(e))
  46. exit()