directadmin.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  3. # License: GNU General Public License v2
  4. # Version 0.1 (initial release)
  5. #
  6. # Version 0.2
  7. # Updated output to have updateable compontents comma-sepoarated.
  8. #
  9. # Version 0.3
  10. # Removed a duplicate routine, and added more comments
  11. # Installation:
  12. # This file should be placed on a/the DirectAdmin host in /usr/lib/check_mk_agent/local
  13. #
  14. # (optional) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path
  15. # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400 for once per day.
  16. # Suggestion for this check is to run this once a day to minimize processing cost.
  17. #
  18. # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/direactadmin.sh
  19. ##########################################################################
  20. # Global definitions for the script - change if needed to fit your needs #
  21. ##########################################################################
  22. # Custombuild switch , set to 1 if you are using it.
  23. CustomBuild=1
  24. # Service Name
  25. SERVICE="DirectAdmin"
  26. #####################################################################
  27. # DO NOT CHANGE BELOW UNLESS YOU EXACTLY KNOW WHAT YOU ARE DOING #
  28. #####################################################################
  29. # Define global path of directAdmin
  30. if [[ "$CustomBuild" -eq 1 ]]
  31. then
  32. DirAdmin_Path="/usr/local/directadmin/custombuild"
  33. else
  34. DirAdmin_Path="/usr/local/directadmin"
  35. fi
  36. # store version information from DirectAdmin packages
  37. DirectAdmin_Versions_Update=$("$DirAdmin_Path"/build versions)
  38. # Define updates Array
  39. updates=()
  40. # Iterate over the collected data to find possible updates
  41. while read -r line; do
  42. if [[ "$line" =~ ^Latest\ version\ of\ (.+):\ (.+)$ ]]; then
  43. component="${BASH_REMATCH[1]}"
  44. latest="${BASH_REMATCH[2]}"
  45. elif [[ "$line" =~ ^Installed\ version\ of\ (.+):\ (.+)$ ]]; then
  46. installed="${BASH_REMATCH[2]}"
  47. # Compare versions using sort -V
  48. if [[ "$(printf '%s\n%s\n' "$installed" "$latest" | sort -V | head -n1)" != "$latest" ]]; then
  49. updates+=("$component")
  50. fi
  51. fi
  52. done <<< "$DirectAdmin_Versions_Update"
  53. # Report findings back to CheckMK
  54. if [[ ${#updates[@]} -eq 0 ]]; then
  55. echo "0 \"DirectAdmin\" - All DirectAdmin Versions are up to date"
  56. else
  57. update_list=$(IFS=,; echo "${updates[*]}")
  58. echo "1 \"$SERVICE\" - $SERVICE Versions ${update_list} have updates"
  59. fi