ソースを参照

Reformatted some parts of the script

Michael Honkoop 2 週間 前
コミット
67c9b886b5
1 ファイル変更27 行追加21 行削除
  1. 27 21
      localchecks/gogs-version.sh

+ 27 - 21
localchecks/gogs-version.sh

@@ -1,14 +1,12 @@
-#!/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
+# This file should be place on a/the Gogs (https://gogs.io) host in /usr/lib/che                                                          ck_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.
+# (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 ho                                                          ur, 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
+# Also do not forget to make this file executable with chmod +x /usr/lib/check_m                                                          k_agent/local/gogs-version.sh
 
 # (c) Michael Honkoop <mhonkoop@comsolve.nl>
 
@@ -21,46 +19,54 @@
 # url to check releases against
 RELEASEURL="https://api.github.com/repos/gogs/gogs/releases"
 
-# basepath of where gogs is installed
-BASEPATH="/opt/gogs/"
+# basepath of where gogs is installed (no trailing slash-forward)
+BASEPATH="/opt/gogs"
+
+# Gogs executable
+GOGS_BIN="${BASEPATH}/gogs"
+
+# Service name
+SERVICE="Gogs"
 
 ######################
-# The code below should not be changed, unless you know EXACTLY what you are doing.
+# The code below should not be changed, unless you know EXACTLY what you are doi                                                          ng.
 # 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"
+    echo "2 \"$SERVICE\" - $SERVICE localcheck requires jq package to be install                                                          ed"
     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."
+    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')
+GOGS_INSTALLED=$("$GOGS_BIN" --version | sed -nE 's/.*version ([0-9]+\.[0-9]+\.[                                                          0-9]+).*/\1/p')
+
+if [[ -z "$GOGS_INSTALLED" ]]; then
+    echo "3 \"$SERVICE\" - Gogs executable found, but returned no valid version"
+    exit 0
+fi
 
 # 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' "$RELEASEUR                                                          L" | jq -er 'map(select(.draft == false and .prerelease == false)) | .[0].tag_na                                                          me' | 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."
+    echo "1 \"$SERVICE\" - 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"
+    echo "0 \"$SERVICE\" - Gogs version $GOGS_INSTALLED is up to date."
+elif [[ "$(printf '%s\n' "$GOGS_INSTALLED" "$GOGS_AVAILABLE" | sort -V | tail -n                                                          1)" == "$GOGS_AVAILABLE" ]]; then
+    echo "1 \"$SERVICE\" - Update available: $GOGS_INSTALLED -> $GOGS_AVAILABLE"
     exit 0
-fi
+fi