directadmin.sh 2.8 KB

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