Selaa lähdekoodia

Updated localchecks/directadmin.sh to v0.7

Rewritten component update detection as output format from DirectAdmin changed
Michael Honkoop 3 päivää sitten
vanhempi
sitoutus
4e128a7278
1 muutettua tiedostoa jossa 13 lisäystä ja 17 poistoa
  1. 13 17
      localchecks/directadmin.sh

+ 13 - 17
localchecks/directadmin.sh

@@ -16,9 +16,11 @@
 # - Updates status to be reported in CheckMK when prerequisites are missing.
 # Version 0.6:
 # - Added logic to also detect extension updates
+# Version 0.7
+# - Changed updated logic completely as Directadmin's output changed
 
 # Current active version of the script
-SCRIPT_VERSION=0.6
+SCRIPT_VERSION=0.7
 
 # Installation:
 # This file should be placed on a/the DirectAdmin host in /usr/lib/check_mk_agent/local
@@ -86,23 +88,17 @@ fi
 DirectAdmin_Versions_Update=$("$DA_PATH"/build versions)
 # Define updates Array
 updates=()
+
 # Iterate over the collected data to find possible updates
-while read -r line; do
-    if [[ "$line" =~ ^Latest\ version\ of\ (.+):\ (.+)$ ]]; then
-        component="${BASH_REMATCH[1]}"
-        latest="${BASH_REMATCH[2]}"
-    elif [[ "$line" =~ ^Installed\ version\ of\ (.+):\ (.+)$ ]]; then
-        installed="${BASH_REMATCH[2]}"
-
-        # Compare versions using sort -V
-        if [[ "$(printf '%s\n%s\n' "$installed" "$latest" | sort -V | head -n1)" != "$latest" ]]; then
-            updates+=("$component")
-        fi
-    # Check for PHP extension updates
-    elif [[ "$line" =~ ^(.+)[[:space:]]PHP[[:space:]]([0-9.]+)[[:space:]]extension[[:space:]].*[[:space:]]to[[:space>
+while IFS= read -r line; do
+
+
+    if [[ "$line" =~ ^(.+)[[:space:]]([0-9][^[:space:]]*).*to[[:space:]]([0-9][^[:space:]]*)[[:space:]]update[[:space:]]is[[:space:]]available ]]; then
+
         component="${BASH_REMATCH[1]}"
-        php_version="${BASH_REMATCH[2]}"
-        updates+=("$component PHP $php_version")
+        latest="${BASH_REMATCH[3]}"
+
+        updates+=("$component ($latest)")
     fi
 
 done <<< "$DirectAdmin_Versions_Update"
@@ -112,5 +108,5 @@ if [[ ${#updates[@]} -eq 0 ]]; then
     echo "0 \"$SERVICE Components\" - All $SERVICE Components are up to date"
 else
     update_list=$(IFS=,; echo "${updates[*]}")
-    echo "1 \"$SERVICE Components\" - $SERVICE Components ${update_list} have updates"
+    echo "1 \"$SERVICE Components\" - $SERVICE Components have updates: ${update_list}"
 fi