1
0

fusionauth-version.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # Version 0.1 - initial start of this localcheck
  3. # Version 0.2 - refined, and commented code further
  4. # Version 0.3 - updated status reporting to CheckMK when prerequisites fail for the Localcheck
  5. # Current active version of the script
  6. SCRIPT_VERSION=0.3
  7. # Installation
  8. # This file should be place on a/the fusionauth host in /usr/lib/check_mk_agent/local
  9. #
  10. # (Reccomended, but optional) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path
  11. # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400 for once per day.
  12. #
  13. # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/fusionauth-version.sh
  14. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  15. # License: GNU General Public License v2
  16. ######################
  17. # Configurable Parameters
  18. ######################
  19. # url to check releases against
  20. RELEASEURL="https://license.fusionauth.io/api/latest-version"
  21. # Service name
  22. SERVICE="FusionAuth"
  23. ######################
  24. # The code below should not be changed, unless you know EXACTLY what you are doing.
  25. # All configureable parameters are above this section.
  26. ######################
  27. # Check if curl package is present on the system (required for this check)
  28. if ! command -v curl >/dev/null 2>&1; then
  29. echo "3 \"$SERVICE\" - $SERVICE localcheck requires curl package to be installed"
  30. exit 0
  31. fi
  32. # Get currently installed package information of FusionAuth
  33. mapfile -t fusionauth_packages < <(rpm -qa 'fusionauth*')
  34. # Check if package-manager returned packages, if none found report it
  35. if [ "${#fusionauth_packages[@]}" -eq 0 ]; then
  36. echo "3 \"$SERVICE\" - No $SERVICE packages found on this host"
  37. exit 0
  38. fi
  39. # Get latest avaiable version information.
  40. FUSIONAUTH_VERSION_AVAIL=$(curl -fsS --connect-timeout 5 --max-time 10 "$RELEASEURL")
  41. curl_rc=$?
  42. # Validate return-code from curl
  43. if [ "$curl_rc" -ne 0 ]; then
  44. echo "3 \"$SERVICE\" - Unable to query release URL (curl exit code $curl_rc)"
  45. exit 0
  46. fi
  47. # Check if the query did return something, if not report it
  48. if [ -z "$FUSIONAUTH_VERSION_AVAIL" ];
  49. then
  50. echo "3 \"$SERVICE\" - No data received from release URL, can not determine latest release-version"
  51. exit 0
  52. fi
  53. # Validate that the query returned a version
  54. if [[ ! "$FUSIONAUTH_VERSION_AVAIL" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  55. echo "3 \"$SERVICE\" - Unexpected response from release URL: $FUSIONAUTH_VERSION_AVAIL"
  56. exit 0
  57. fi
  58. outdated_packages=()
  59. for package in "${fusionauth_packages[@]}"; do
  60. if [[ "$package" != *"$FUSIONAUTH_VERSION_AVAIL"* ]]; then
  61. outdated_packages+=("$package")
  62. fi
  63. done
  64. if [ "${#outdated_packages[@]}" -eq 0 ]; then
  65. echo "0 \"$SERVICE\" - All $SERVICE packages are up to date ($FUSIONAUTH_VERSION_AVAIL)"
  66. else
  67. echo "1 \"$SERVICE\" - Latest version Available ($FUSIONAUTH_VERSION_AVAIL), Update required for: ${outdated_packages[*]}"
  68. fi