| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #!/bin/bash
- # Version 0.1 - initial start of this localcheck
- # Version 0.2 - refined, and commented code further
- # Current active version of the script
- SCRIPT_VERSION=0.2
- # Installation
- # This file should be place on a/the fusionauth host in /usr/lib/check_mk_agent/local
- #
- # (optional) if you want the check to run on a different schedule (like once per hour) put it in a subdirectory of above path
- # named to the number of seconds of the interval wanted, so 3600/ for once an hour, 86400 for once per day.
- #
- # Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/fusionauth-version.sh
- # (c) Michael Honkoop <mhonkoop@comsolve.nl>
- # License: GNU General Public License v2
- ######################
- # Configurable Parameters
- ######################
- # url to check releases against
- RELEASEURL="https://license.fusionauth.io/api/latest-version"
- # Service name
- SERVICE="FusionAuth"
- ######################
- # The code below should not be changed, unless you know EXACTLY what you are doing.
- # All configureable parameters are above this section.
- ######################
- # Check if curl package is present on the system (required for this check)
- if ! command -v curl >/dev/null 2>&1; then
- echo "2 \"$SERVICE\" - $SERVICE localcheck requires curl package to be installed"
- exit 0
- fi
- # Get currently installed package information of FusionAuth
- mapfile -t fusionauth_packages < <(rpm -qa 'fusionauth*')
- # Check if package-manager returned packages, if none found report it
- if [ "${#fusionauth_packages[@]}" -eq 0 ]; then
- echo "2 \"$SERVICE\" - No $SERVICE packages found on this host"
- exit 0
- fi
- # Get latest avaiable version information.
- FUSIONAUTH_VERSION_AVAIL=$(curl -fsS --connect-timeout 5 --max-time 10 "$RELEASEURL")
- curl_rc=$?
- # Validate return-code from curl
- if [ "$curl_rc" -ne 0 ]; then
- echo "3 \"$SERVICE\" - Unable to query release URL (curl exit code $curl_rc)"
- exit 0
- fi
- # Check if the query did return something, if not report it
- if [ -z "$FUSIONAUTH_VERSION_AVAIL" ];
- then
- echo "3 \"$SERVICE\" - No data received from release URL, can not determine latest release-version"
- exit 0
- fi
- # Validate that the query returned a version
- if [[ ! "$FUSIONAUTH_VERSION_AVAIL" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
- echo "3 \"$SERVICE\" - Unexpected response from release URL: $FUSIONAUTH_VERSION_AVAIL"
- exit 0
- fi
- outdated_packages=()
- for package in "${fusionauth_packages[@]}"; do
- if [[ "$package" != *"$FUSIONAUTH_VERSION_AVAIL"* ]]; then
- outdated_packages+=("$package")
- fi
- done
- if [ "${#outdated_packages[@]}" -eq 0 ]; then
- echo "0 \"$SERVICE\" - All $SERVICE packages are up to date ($FUSIONAUTH_VERSION_AVAIL)"
- else
- echo "1 \"$SERVICE\" - Latest version Available ($FUSIONAUTH_VERSION_AVAIL), Update required for: ${outdated_packages[*]}"
- fi
|