directadmin.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  3. # License: GNU General Public License v2
  4. # Version 0.1:
  5. # - initial release
  6. # Version 0.2:
  7. # - Updated output to have updateable compontents comma-sepoarated.
  8. # Version 0.3:
  9. # - Removed a duplicate routine, and added more comments
  10. # Version 0.4:
  11. # - Added check for DirectAdmin Core => Rediscovery is required if you had a previous version installed !
  12. # Version 0.5:
  13. # - Updates status to be reported in CheckMK when prerequisites are missing.
  14. # Version 0.6:
  15. # - Added logic to also detect extension updates
  16. # Version 0.7
  17. # - Changed updated logic completely as Directadmin's output changed
  18. # Current active version of the script
  19. SCRIPT_VERSION=0.7
  20. # Installation:
  21. # This file should be placed on a/the DirectAdmin host in /usr/lib/check_mk_agent/local
  22. #
  23. # (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
  24. # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400/ for once per day.
  25. # Suggestion for this check is to run this once a day to minimize processing cost.
  26. #
  27. # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/direactadmin.sh
  28. ##########################################################################
  29. # Global definitions for the script - change if needed to fit your needs #
  30. ##########################################################################
  31. # Custombuild switch , set to 1 if you are using it.
  32. CustomBuild=1
  33. # Service Name
  34. SERVICE="DirectAdmin"
  35. #####################################################################
  36. # DO NOT CHANGE BELOW UNLESS YOU EXACTLY KNOW WHAT YOU ARE DOING #
  37. #####################################################################
  38. # Check if da command is present
  39. if ! command -v da >/dev/null 2>&1; then
  40. echo "3 \"$SERVICE Core\" - $SERVICE executable was not found."
  41. fi
  42. # Read installed DirectAdmin (core) version
  43. DA_INSTALLED=$(da version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
  44. # Check if a version was returned
  45. if [[ -z "$DA_INSTALLED" ]]; then
  46. echo "3 \"$SERVICE Core\" - Unable to determine DirectAdmin Core version"
  47. fi
  48. # Read latest available DirectAdmin (core) version
  49. DA_AVAILABLE=$(da update --check 2>&1 | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
  50. # Check if a version was returned
  51. if [[ -z "$DA_AVAILABLE" ]]; then
  52. echo "3 \"$SERVICE Core\" - Unable to determine available $SERVICE Core version"
  53. fi
  54. # Compare installed DirectAdmin version to available version
  55. if [[ "$DA_INSTALLED" = "$DA_AVAILABLE" ]]; then
  56. echo "0 \"$SERVICE Core\" - $SERVICE Core is up to date: ($DA_INSTALLED)"
  57. elif [[ "$DA_INSTALLED" < "$DA_AVAILABLE" ]]; then
  58. echo "1 \"$SERVICE Core\" - $SERVICE Core Update available: ($DA_AVAILABLE), Installed: ($DA_INSTALLED)"
  59. elif [[ "$DA_INSTALLED" > "$DA_AVAILABLE" ]]; then
  60. echo "2 \"$SERVICE Core\" - $SERVICE Core installed: ($DA_INSTALLED) is higher then available: ($DA_AVAILABLE)"
  61. fi
  62. # Define global path of directAdmin
  63. if [[ "$CustomBuild" -eq 1 ]]
  64. then
  65. DA_PATH="/usr/local/directadmin/custombuild"
  66. else
  67. DA_PATH="/usr/local/directadmin"
  68. fi
  69. # store version information from DirectAdmin packages
  70. DirectAdmin_Versions_Update=$("$DA_PATH"/build versions)
  71. # Define updates Array
  72. updates=()
  73. # Iterate over the collected data to find possible updates
  74. while IFS= read -r line; do
  75. if [[ "$line" =~ ^(.+)[[:space:]]([0-9][^[:space:]]*).*to[[:space:]]([0-9][^[:space:]]*)[[:space:]]update[[:space:]]is[[:space:]]available ]]; then
  76. component="${BASH_REMATCH[1]}"
  77. latest="${BASH_REMATCH[3]}"
  78. updates+=("$component ($latest)")
  79. fi
  80. done <<< "$DirectAdmin_Versions_Update"
  81. # Report findings back to CheckMK
  82. if [[ ${#updates[@]} -eq 0 ]]; then
  83. echo "0 \"$SERVICE Components\" - All $SERVICE Components are up to date"
  84. else
  85. update_list=$(IFS=,; echo "${updates[*]}")
  86. echo "1 \"$SERVICE Components\" - $SERVICE Components have updates: ${update_list}"
  87. fi