directadmin.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Installation:
  9. # This file should be placed on a/the DirectAdmin host in /usr/lib/check_mk_agent/local
  10. #
  11. # (optional) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path
  12. # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400 for once per day.
  13. # Suggestion for this check is to run this once a day to minimize processing cost.
  14. #
  15. # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/direactadmin.sh
  16. ##########################################################################
  17. # Global definitions for the script - change if needed to fit your needs #
  18. ##########################################################################
  19. # Custombuild switch , set to 1 if you are using it.
  20. CustomBuild=1
  21. #####################################################################
  22. # DO NOT CHANGE BELOW UNLESS YOU EXACTLY KNOW WHAT YOU ARE DOING #
  23. #####################################################################
  24. # Define global path of directAdmin
  25. if [ $CustomBuild -eq 1 ]
  26. then
  27. DirAdmin_Path="/usr/local/directadmin/custombuild"
  28. else
  29. DirAdmin_Path="/usr/local/directadmin"
  30. fi
  31. # Check DirectAdmin Core updates
  32. DirectAdmin_Core_Update=$($DirAdmin_Path/build update)
  33. if [[ $DirectAdmin_Core_Update == *"is already latest" ]]
  34. then
  35. echo "0 \"DirectAdmin_Core\" - DirectAdmin core all up to date"
  36. else
  37. echo "1 \"DirectAdmin_Core\" - DirectAdmin core has a newer version available - consider updating"
  38. fi
  39. # Check DirectAdmin Core updates
  40. DirectAdmin_Core_Update=$($DirAdmin_Path/build update)
  41. if [[ $DirectAdmin_Core_Update == *"is already latest" ]]
  42. then
  43. echo "0 \"DirectAdmin_Core\" - DirectAdmin core all up to date"
  44. else
  45. echo "1 \"DirectAdmin_Core\" - DirectAdmin core has a newer version available - consider updating"
  46. fi
  47. # store version information from DirectAdmin packages
  48. DirectAdmin_Versions_Update=$($DirAdmin_Path/build versions)
  49. #Define updates Array
  50. updates=()
  51. # iterate over the collected data to find possible updates
  52. while read -r line; do
  53. if [[ $line =~ ^Latest\ version\ of\ (.+):\ (.+)$ ]]; then
  54. component="${BASH_REMATCH[1]}"
  55. latest="${BASH_REMATCH[2]}"
  56. elif [[ $line =~ ^Installed\ version\ of\ (.+):\ (.+)$ ]]; then
  57. installed="${BASH_REMATCH[2]}"
  58. # Compare versions using sort -V
  59. if [[ "$(printf '%s\n%s\n' "$installed" "$latest" | sort -V | head -n1)" != "$latest" ]]; then
  60. updates+=("$component")
  61. fi
  62. fi
  63. done <<< "$DirectAdmin_Versions_Update"
  64. if [[ ${#updates[@]} -eq 0 ]]; then
  65. echo "0 \"DirectAdmin\" - All DirectAdmin Versions are up to date"
  66. else
  67. update_list=$(IFS=,; echo "${updates[*]}")
  68. echo "1 \"DirectAdmin\" - DirectAdmin Versions ${update_list} have updates"
  69. fi