#!/bin/bash # (c) Michael Honkoop # License: GNU General Public License v2 # Version 0.1: # - initial release # Version 0.2: # - Updated output to have updateable compontents comma-sepoarated. # Version 0.3: # - Removed a duplicate routine, and added more comments # Version 0.4: # - Added check for DirectAdmin Core => Rediscovery is required if you had a previous version installed ! # Current active version of the script SCRIPT_VERSION=0.4 # Installation: # This file should be placed on a/the DirectAdmin host in /usr/lib/check_mk_agent/local # # (optional/reccomended) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400/ for once per day. # Suggestion for this check is to run this once a day to minimize processing cost. # # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/direactadmin.sh ########################################################################## # Global definitions for the script - change if needed to fit your needs # ########################################################################## # Custombuild switch , set to 1 if you are using it. CustomBuild=1 # Service Name SERVICE="DirectAdmin" ##################################################################### # DO NOT CHANGE BELOW UNLESS YOU EXACTLY KNOW WHAT YOU ARE DOING # ##################################################################### # Check if da command is present if ! command -v da >/dev/null 2>&1; then echo "2 \"$SERVICE Core\" - $SERVICE executable was not found." fi # Read installed DirectAdmin (core) version DA_INSTALLED=$(da version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) # Check if a version was returned if [[ -z "$DA_INSTALLED" ]]; then echo "2 \"$SERVICE Core\" - Unable to determine DirectAdmin Core version" fi # Read latest available DirectAdmin (core) version DA_AVAILABLE=$(da update --check 2>&1 | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) # Check if a version was returned if [[ -z "$DA_AVAILABLE" ]]; then echo "2 \"$SERVICE Core\" - Unable to determine available $SERVICE Core version" fi # Compare installed DirectAdmin version to available version if [[ "$DA_INSTALLED" = "$DA_AVAILABLE" ]]; then echo "0 \"$SERVICE Core\" - $SERVICE Core is up to date: ($DA_INSTALLED)" elif [[ "$DA_INSTALLED" < "$DA_AVAILABLE" ]]; then echo "1 \"$SERVICE Core\" - $SERVICE Core Update available: ($DA_AVAILABLE), Installed: ($DA_INSTALLED)" elif [[ "$DA_INSTALLED" > "$DA_AVAILABLE" ]]; then echo "2 \"$SERVICE Core\" - $SERVICE Core installed: ($DA_INSTALLED) is higher then available: ($DA_AVAILABLE)" fi # Define global path of directAdmin if [[ "$CustomBuild" -eq 1 ]] then DA_PATH="/usr/local/directadmin/custombuild" else DA_PATH="/usr/local/directadmin" fi # store version information from DirectAdmin packages 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 fi done <<< "$DirectAdmin_Versions_Update" # Report findings back to CheckMK 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" fi