Преглед изворни кода

Initial release of simplesaml_version_check.sh

Michael Honkoop пре 4 дана
родитељ
комит
20371b70a4
1 измењених фајлова са 89 додато и 0 уклоњено
  1. 89 0
      localchecks/simplesaml_version_check.sh

+ 89 - 0
localchecks/simplesaml_version_check.sh

@@ -0,0 +1,89 @@
+#!/bin/bash
+
+# (c) Michael Honkoop <mhonkoop@comsolve.nl>
+
+# License: GNU General Public License v2
+
+# Version 0.1:
+# - initial release
+
+# Current active version of the script
+SCRIPT_VERSION=0.1
+
+# Installation:
+# This file should be placed on a/the host running SimpleSamlPHP in /usr/lib/check_mk_agent/local
+#
+# (reccomended) 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.
+# Suggestion for this check is to run this once a day to minimize processing cost.
+#
+# Also do not forget to make this file executable with chmod +x /usr/lib/check_mk_agent/local/simplesaml_version_check.sh
+
+##########################################################################
+# Global definitions for the script - change if needed to fit your needs #
+##########################################################################
+
+# Define path to where SimpleSalmPHP is installed
+BASEPATH="/opt/simplesamlphp"
+
+# Version (json) file reference
+VERSION_FILE="composer.json"
+
+# url to check releases against
+RELEASEURL="https://api.github.com/repos/simplesamlphp/simplesamlphp/releases"
+
+# Service Name to be shown in Check_MK
+SERVICE="SimpleSAMLphp_Version"
+
+
+#####################################################################
+# DO NOT CHANGE BELOW UNLESS YOU EXACTLY KNOW WHAT YOU ARE DOING    #
+#####################################################################
+
+# Check if jq package is present on the system (required for this check)
+if ! command -v jq >/dev/null 2>&1; then
+    echo "2 \"$SERVICE\" - $SERVICE localcheck requires jq package to be installed"
+    exit 0
+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 presence of SimpleSAMLPhp and report if not found
+if [[ ! -f "$BASEPATH/$VERSION_FILE" ]]; then
+    echo "2 \"$SERVICE\" - No local version information found in: $$BASEPATH/$VERSION_FILE check localcheck configuration."
+    exit 0
+fi
+# Get installed version information via composer.json or version file
+if [ -f "$BASEPATH/$VERSION_FILE" ]; then
+    INSTALLED_VERSION=$(jq -r '.version // empty' "$BASEPATH/$VERSION_FILE")
+    INSTALLED_VERSION="${INSTALLED_VERSION#v}"
+else
+    # Fallback to checking directory name if version isn't in composer.json
+    INSTALLED_VERSION="Unknown"
+fi
+
+# Get latest avaiable version information from github.
+#AVAILABLE_VERSION=$(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//')
+AVAILABLE_VERSION=$(curl -fsSL -H 'Accept: application/vnd.github+json' --connect-timeout 5 --max-time 15 "$RELEASEURL" | jq -r '.[] | select(.draft == false and .prerelease == false) | .tag_name' | sed 's/^v//' | sort -V | tail -n1)
+# Error handling / Evaluate results
+if [ -z "$AVAILABLE_VERSION" ]; then
+    # Issue Warn state when failing to fetch data from GitHub.
+    echo "1 \"$SERVICE\" - Could not fetch the latest version from GitHub API."
+    exit 0
+elif [ "$VERSION_FILE" = "Unknown" ]; then
+    # Issue Warn state when local/installed version could not be determined.
+    echo "1 \"$SERVICE\" - Cannot detect installed version at $VERSION_FILE."
+    exit 0
+elif [ "$INSTALLED_VERSION" = "$AVAILABLE_VERSION" ]; then
+    # Set OK state when installed and latest release versnion match.
+    echo "0 \"$SERVICE\" - SimpleSAMLphp is up to date ($VERSION_FILE)."
+    exit 0
+else
+    # WARN: Update available
+    echo "1 \"$SERVICE\" - Update available! Installed: $INSTALLED_VERSION, Available: $AVAILABLE_VERSION."
+    exit 0
+fi