fusionauth-version.sh 2.8 KB

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