1
0

edir-version.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # This Localcheck purely checks a/the version of the installed eDirectory.
  12. # If you want to monitor eDirectory more in-Depth, then concider using the plugin/Special Agent
  13. import subprocess
  14. import sys
  15. # The process to be executed
  16. myexec = "ndsd"
  17. # The displayed service in Checkmk
  18. service = "eDirectory"
  19. # Attempt to run the executable
  20. try:
  21. output = subprocess.check_output(
  22. [myexec, "--version"],
  23. stderr=subprocess.STDOUT,
  24. universal_newlines=True
  25. )
  26. output_arr = output.split()
  27. # Output status when the executable returns expected result
  28. if len(output_arr) >= 4:
  29. print(
  30. f'0 "{service}" - Binary Version: '
  31. f'{output_arr[2]}, DS Version: {output_arr[3]}'
  32. )
  33. else:
  34. print(f'3 "{service}" - Unable to parse version output')
  35. # Executable not found
  36. except FileNotFoundError:
  37. print(f'3 "{service}" - {myexec} executable not found')
  38. # Executable exists, but returned an error
  39. except subprocess.CalledProcessError as e:
  40. print(f'2 "{service}" - {myexec} returned error: {e.returncode}')
  41. # Catch unexpected errors
  42. except Exception as e:
  43. print(f'3 "{service}" - Unexpected error: {e}')
  44. sys.exit(0)