|
@@ -1,21 +1,13 @@
|
|
|
#!/usr/bin/env python3
|
|
#!/usr/bin/env python3
|
|
|
#
|
|
#
|
|
|
# (c) Michael Honkoop <mhonkoop@comsolve.nl>
|
|
# (c) Michael Honkoop <mhonkoop@comsolve.nl>
|
|
|
-
|
|
|
|
|
|
|
+#
|
|
|
# License: GNU General Public License v2
|
|
# License: GNU General Public License v2
|
|
|
-
|
|
|
|
|
|
|
+#
|
|
|
# Version 0.1
|
|
# Version 0.1
|
|
|
# - Initial release
|
|
# - Initial release
|
|
|
# Version 0.2
|
|
# 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.
|
|
|
|
|
|
|
+# - Refined routines to cover output more accurately.
|
|
|
|
|
|
|
|
import subprocess
|
|
import subprocess
|
|
|
import sys
|
|
import sys
|
|
@@ -23,10 +15,10 @@ import sys
|
|
|
# The process to be executed
|
|
# The process to be executed
|
|
|
myexec = "ndsd"
|
|
myexec = "ndsd"
|
|
|
|
|
|
|
|
-# the displayed service in CheckMK
|
|
|
|
|
|
|
+# The displayed service in Checkmk
|
|
|
service = "eDirectory"
|
|
service = "eDirectory"
|
|
|
|
|
|
|
|
-# Attempt to run the executable, if successful output CheckMK formatted data, if not found return unknown status.
|
|
|
|
|
|
|
+# Attempt to run the executable
|
|
|
try:
|
|
try:
|
|
|
output = subprocess.check_output(
|
|
output = subprocess.check_output(
|
|
|
[myexec, "--version"],
|
|
[myexec, "--version"],
|
|
@@ -36,25 +28,25 @@ try:
|
|
|
|
|
|
|
|
output_arr = output.split()
|
|
output_arr = output.split()
|
|
|
|
|
|
|
|
-# output status when the executable returns expected result
|
|
|
|
|
|
|
+ # Output status when the executable returns expected result
|
|
|
if len(output_arr) >= 4:
|
|
if len(output_arr) >= 4:
|
|
|
- print('0 "eDirectory" - Binary Version: {}, DS Version: {}'.format(
|
|
|
|
|
- output_arr[2], output_arr[3]
|
|
|
|
|
- ))
|
|
|
|
|
|
|
+ print(
|
|
|
|
|
+ f'0 "{service}" - Binary Version: '
|
|
|
|
|
+ f'{output_arr[2]}, DS Version: {output_arr[3]}'
|
|
|
|
|
+ )
|
|
|
else:
|
|
else:
|
|
|
- print('3 "eDirectory" - Unable to parse version output')
|
|
|
|
|
|
|
+ print(f'3 "{service}" - Unable to parse version output')
|
|
|
|
|
|
|
|
-# Executable not found handling
|
|
|
|
|
|
|
+# Executable not found
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print('3 "eDirectory" - ndsd executable not found')
|
|
|
|
|
- exit()
|
|
|
|
|
|
|
+ print(f'3 "{service}" - {myexec} executable not found')
|
|
|
|
|
|
|
|
# Executable exists, but returned an error
|
|
# Executable exists, but returned an error
|
|
|
except subprocess.CalledProcessError as e:
|
|
except subprocess.CalledProcessError as e:
|
|
|
- print('2 "eDirectory" - ndsd returned error: {}'.format(e.returncode))
|
|
|
|
|
- exit()
|
|
|
|
|
|
|
+ print(f'2 "{service}" - {myexec} returned error: {e.returncode}')
|
|
|
|
|
|
|
|
# Catch unexpected errors
|
|
# Catch unexpected errors
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print('3 "eDirectory" - Unexpected error: {}'.format(e))
|
|
|
|
|
- exit()
|
|
|
|
|
|
|
+ print(f'3 "{service}" - Unexpected error: {e}')
|
|
|
|
|
+
|
|
|
|
|
+sys.exit(0)
|