Browse Source

Initial version of the localcheck gogs-version.sh

Michael Honkoop 2 tuần trước cách đây
mục cha
commit
92ce301703
1 tập tin đã thay đổi với 66 bổ sung0 xóa
  1. 66 0
      localchecks/gogs-version.sh

+ 66 - 0
localchecks/gogs-version.sh

@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Version 0.1 - initial start of this localcheck
+
+# Installation
+# This file should be place on a/the Gogs (https://gogs.io) 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/gogs-version.sh
+
+# (c) Michael Honkoop <mhonkoop@comsolve.nl>
+
+# License: GNU General Public License v2
+
+######################
+# Configurable Parameters
+######################
+
+# url to check releases against
+RELEASEURL="https://api.github.com/repos/gogs/gogs/releases"
+
+# basepath of where gogs is installed
+BASEPATH="/opt/gogs/"
+
+######################
+# The code below should not be changed, unless you know EXACTLY what you are doing.
+# All configureable parameters are above this section.
+######################
+
+# check if jq package is present on the system (required for this check)
+command -v jq >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+    echo "2 \"Gogs\" - Gogs localcheck requires jq package to be installed"
+    exit 0
+fi
+
+# binary path
+GOGS_BIN="${BASEPATH}/gogs"
+
+# Check Gogs binary presence and report if not found
+if [[ ! -x "$GOGS_BIN" ]]; then
+    echo "2 \"$SERVICE\" - Gogs executable not found: $GOGS_BIN check localcheck configuration."
+    exit 0
+fi
+
+# Get current installed Gogs version-information
+GOGS_INSTALLED=$("$GOGS_BIN" --version | sed -nE 's/.*version ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p')
+
+# 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//')
+
+# Return status when latest version information could not be retrieved.
+if [[ -z "$GOGS_AVAILABLE" || "$GOGS_AVAILABLE" == "null" ]]; then
+    echo "1 \"Gogs\" - No data received from release-URL, can not determine latest release-version."
+    exit 0
+fi
+
+# Compare installed version to available version
+if [[ "$GOGS_INSTALLED" == "$GOGS_AVAILABLE" ]]; then
+    echo "0 \"Gogs\" - Gogs version $GOGS_INSTALLED is up to date."
+elif [[ "$(printf '%s\n' "$GOGS_INSTALLED" "$GOGS_AVAILABLE" | sort -V | tail -n1)" == "$GOGS_AVAILABLE" ]]; then
+    echo "1 \"Gogs\" - Update available: $GOGS_INSTALLED -> $GOGS_AVAILABLE"
+    exit 0
+fi