1
0

edir-version.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. #
  3. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  4. #
  5. # License: GNU General Public License v2
  6. #
  7. # Version 0.1
  8. # - Initial release
  9. # Version 0.2
  10. # - Refined routines to cover output more accurately.
  11. import subprocess
  12. import sys
  13. # The process to be executed
  14. myexec = "ndsd"
  15. # The displayed service in Checkmk
  16. service = "eDirectory"
  17. # Attempt to run the executable
  18. try:
  19. output = subprocess.check_output(
  20. [myexec, "--version"],
  21. stderr=subprocess.STDOUT,
  22. universal_newlines=True
  23. )
  24. output_arr = output.split()
  25. # Output status when the executable returns expected result
  26. if len(output_arr) >= 4:
  27. print(
  28. f'0 "{service}" - Binary Version: '
  29. f'{output_arr[2]}, DS Version: {output_arr[3]}'
  30. )
  31. else:
  32. print(f'3 "{service}" - Unable to parse version output')
  33. # Executable not found
  34. except FileNotFoundError:
  35. print(f'3 "{service}" - {myexec} executable not found')
  36. # Executable exists, but returned an error
  37. except subprocess.CalledProcessError as e:
  38. print(f'2 "{service}" - {myexec} returned error: {e.returncode}')
  39. # Catch unexpected errors
  40. except Exception as e:
  41. print(f'3 "{service}" - Unexpected error: {e}')
  42. sys.exit(0)