|
@@ -1,6 +1,10 @@
|
|
|
#!/bin/bash
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Version 0.1 - initial start of this localcheck
|
|
# Version 0.1 - initial start of this localcheck
|
|
|
|
|
+# Version 0.2 - introduced additional logic to also deal with a local installed version being higher then available from the release-url.
|
|
|
|
|
+
|
|
|
|
|
+# Current active version of the script
|
|
|
|
|
+SCRIPT_VERSION=0.2
|
|
|
|
|
|
|
|
# Installation
|
|
# Installation
|
|
|
# This file should be place on a/the Gogs (https://gogs.io) host in /usr/lib/check_mk_agent/local
|
|
# This file should be place on a/the Gogs (https://gogs.io) host in /usr/lib/check_mk_agent/local
|
|
@@ -35,13 +39,19 @@ SERVICE="Gogs"
|
|
|
# All configureable parameters are above this section.
|
|
# All configureable parameters are above this section.
|
|
|
######################
|
|
######################
|
|
|
|
|
|
|
|
-# check if jq package is present on the system (required for this check)
|
|
|
|
|
|
|
+# Check if jq package is present on the system (required for this check)
|
|
|
command -v jq >/dev/null 2>&1
|
|
command -v jq >/dev/null 2>&1
|
|
|
if [ $? -ne 0 ]; then
|
|
if [ $? -ne 0 ]; then
|
|
|
echo "2 \"$SERVICE\" - $SERVICE localcheck requires jq package to be installed"
|
|
echo "2 \"$SERVICE\" - $SERVICE localcheck requires jq package to be installed"
|
|
|
exit 0
|
|
exit 0
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+# 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
|
|
|
|
|
+
|
|
|
# Check Gogs binary presence and report if not found
|
|
# Check Gogs binary presence and report if not found
|
|
|
if [[ ! -x "$GOGS_BIN" ]]; then
|
|
if [[ ! -x "$GOGS_BIN" ]]; then
|
|
|
echo "2 \"$SERVICE\" - Gogs executable not found: $GOGS_BIN check localcheck configuration."
|
|
echo "2 \"$SERVICE\" - Gogs executable not found: $GOGS_BIN check localcheck configuration."
|
|
@@ -49,7 +59,7 @@ if [[ ! -x "$GOGS_BIN" ]]; then
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# Get current installed Gogs version-information
|
|
# Get current installed Gogs version-information
|
|
|
-GOGS_INSTALLED=$("$GOGS_BIN" --version | sed -nE 's/.*version ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p')
|
|
|
|
|
|
|
+GOGS_INSTALLED=$("$GOGS_BIN" --version 2>/dev/null | sed -nE 's/.*version ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p')
|
|
|
|
|
|
|
|
if [[ -z "$GOGS_INSTALLED" ]]; then
|
|
if [[ -z "$GOGS_INSTALLED" ]]; then
|
|
|
echo "3 \"$SERVICE\" - Gogs executable found, but returned no valid version"
|
|
echo "3 \"$SERVICE\" - Gogs executable found, but returned no valid version"
|
|
@@ -57,11 +67,11 @@ if [[ -z "$GOGS_INSTALLED" ]]; then
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# Get latest avaiable version information.
|
|
# Get latest avaiable version information.
|
|
|
-GOGS_AVAILABLE=$(curl -fsSL -H 'Accept: application/vnd.github+json' "$RELEASEURL" | jq -er 'map(select(.draft == false and .prerelease == false)) | .[0].tag_name' | sed 's/^v//')
|
|
|
|
|
|
|
+GOGS_AVAILABLE=$(curl -fsSL -H 'Accept: application/vnd.github+json' --connect-timeout 5 --max-time 15 "$RELEASEURL" | jq -er 'map(select(.draft == false and .prerelease == false)) | .[0].tag_name' | sed 's/^v//')
|
|
|
|
|
|
|
|
# Return status when latest version information could not be retrieved.
|
|
# Return status when latest version information could not be retrieved.
|
|
|
if [[ -z "$GOGS_AVAILABLE" || "$GOGS_AVAILABLE" == "null" ]]; then
|
|
if [[ -z "$GOGS_AVAILABLE" || "$GOGS_AVAILABLE" == "null" ]]; then
|
|
|
- echo "1 \"$SERVICE\" - No data received from release-URL, can not determine latest release-version."
|
|
|
|
|
|
|
+ echo "3 \"$SERVICE\" - No data received from release-URL, can not determine latest release-version."
|
|
|
exit 0
|
|
exit 0
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
@@ -71,4 +81,7 @@ if [[ "$GOGS_INSTALLED" == "$GOGS_AVAILABLE" ]]; then
|
|
|
elif [[ "$(printf '%s\n' "$GOGS_INSTALLED" "$GOGS_AVAILABLE" | sort -V | tail -n1)" == "$GOGS_AVAILABLE" ]]; then
|
|
elif [[ "$(printf '%s\n' "$GOGS_INSTALLED" "$GOGS_AVAILABLE" | sort -V | tail -n1)" == "$GOGS_AVAILABLE" ]]; then
|
|
|
echo "1 \"$SERVICE\" - Update available: $GOGS_INSTALLED -> $GOGS_AVAILABLE"
|
|
echo "1 \"$SERVICE\" - Update available: $GOGS_INSTALLED -> $GOGS_AVAILABLE"
|
|
|
exit 0
|
|
exit 0
|
|
|
-fi
|
|
|
|
|
|
|
+else
|
|
|
|
|
+ echo "0 \"$SERVICE\" - Gogs version $GOGS_INSTALLED is newer than latest release $GOGS_AVAILABLE."
|
|
|
|
|
+ exit 0
|
|
|
|
|
+fi
|