ソースを参照

Update 'localchecks/edir-version.py'

Michael Honkoop 2 日 前
親
コミット
437c341194
1 ファイル変更、17 行追加、25 行削除
  1. 17 25
      localchecks/edir-version.py

+ 17 - 25
localchecks/edir-version.py

@@ -1,21 +1,13 @@
 #!/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.
+# - Refined routines to cover output more accurately.
 
 import subprocess
 import sys
@@ -23,10 +15,10 @@ import sys
 # The process to be executed
 myexec = "ndsd"
 
-# the displayed service in CheckMK
+# The displayed service in Checkmk
 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:
     output = subprocess.check_output(
         [myexec, "--version"],
@@ -36,25 +28,25 @@ try:
 
     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:
-        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:
-        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:
-    print('3 "eDirectory" - ndsd executable not found')
-    exit()
+    print(f'3 "{service}" - {myexec} executable not found')
 
 # Executable exists, but returned an error
 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
 except Exception as e:
-    print('3 "eDirectory" - Unexpected error: {}'.format(e))
-    exit()
+    print(f'3 "{service}" - Unexpected error: {e}')
+
+sys.exit(0)