|
@@ -1,20 +1,25 @@
|
|
|
#!/bin/bash
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
-# Version 1.5
|
|
|
|
|
-#
|
|
|
|
|
-# v1.5 CHANGES:
|
|
|
|
|
-# - added enhancement sugestion made by briand on checkmk forum to make the version-compare more granular
|
|
|
|
|
-# v1.4 CHANGES:
|
|
|
|
|
-# - added extra logic to deal with unresponsive or empty response from release-url
|
|
|
|
|
-# v1.3 CHANGES:
|
|
|
|
|
-# - Added check for configured apache-user and basepath exist.
|
|
|
|
|
-# v1.2 CHANGES:
|
|
|
|
|
-# - Updated nextcloud release check to actually get latest version from the release-url
|
|
|
|
|
|
|
+# v1.0:
|
|
|
|
|
+# - Initial release of the script
|
|
|
# v1.1 CHANGES:
|
|
# v1.1 CHANGES:
|
|
|
# - Updated query for installed version to versionstring instead of version
|
|
# - Updated query for installed version to versionstring instead of version
|
|
|
|
|
+# v1.2 CHANGES:
|
|
|
|
|
+# - Updated nextcloud release check to actually get latest version from the release-url
|
|
|
|
|
+# v1.3 CHANGES:
|
|
|
|
|
+# - Added check for configured apache-user and basepath exist.
|
|
|
|
|
+# v1.4 CHANGES:
|
|
|
|
|
+# - added extra logic to deal with unresponsive or empty response from release-url
|
|
|
|
|
+# v1.5 CHANGES:
|
|
|
|
|
+# - added enhancement sugestion made by briand on checkmk forum to make the version-compare more granular
|
|
|
|
|
+# Version 1.6 CHANGES:
|
|
|
|
|
+# - Restructured and refined variables, also added additional comments per line of code
|
|
|
#
|
|
#
|
|
|
# WARNING: Current logic in the check will report wrong version as upgrade when a release is withdrawn from a/the release-url.
|
|
# WARNING: Current logic in the check will report wrong version as upgrade when a release is withdrawn from a/the release-url.
|
|
|
|
|
|
|
|
|
|
+# Current active version of the script
|
|
|
|
|
+SCRIPT_VERSION=1.6
|
|
|
|
|
+
|
|
|
# Installation:
|
|
# Installation:
|
|
|
# This file should be place on a/the nextcloud host in /usr/lib/check_mk_agent/local
|
|
# This file should be place on a/the nextcloud host in /usr/lib/check_mk_agent/local
|
|
|
#
|
|
#
|
|
@@ -27,15 +32,21 @@
|
|
|
|
|
|
|
|
# License: GNU General Public License v2
|
|
# License: GNU General Public License v2
|
|
|
|
|
|
|
|
|
|
+######################
|
|
|
|
|
+# Configurable Parameters
|
|
|
|
|
+######################
|
|
|
|
|
+
|
|
|
|
|
+# url to check releases against
|
|
|
RELEASEURL="https://download.nextcloud.com/server/releases/"
|
|
RELEASEURL="https://download.nextcloud.com/server/releases/"
|
|
|
|
|
|
|
|
#basepath of Nextcloud's occ executable
|
|
#basepath of Nextcloud's occ executable
|
|
|
|
|
+BASEPATH="/var/www/nextcloud"
|
|
|
|
|
|
|
|
-BASEPATH="/var/www/html"
|
|
|
|
|
|
|
+# set the correct user for running the commands (either apache or www-data, this depends on your Linux-Distribution)
|
|
|
|
|
+APACHEUSER="www-data"
|
|
|
|
|
|
|
|
-# set the correct user for running the commands ( either apache or www-data, this depends on your Linux-Distribution)
|
|
|
|
|
-
|
|
|
|
|
-APACHEUSER="apache"
|
|
|
|
|
|
|
+# Service name
|
|
|
|
|
+SERVICE="NextCloud"
|
|
|
|
|
|
|
|
# Set how exact the version-comparison should be - enhancement suggested by briand at checkmk forum
|
|
# Set how exact the version-comparison should be - enhancement suggested by briand at checkmk forum
|
|
|
#
|
|
#
|
|
@@ -45,31 +56,33 @@ APACHEUSER="apache"
|
|
|
# 1 → XX (major only)
|
|
# 1 → XX (major only)
|
|
|
VERSION_FIELDS=2
|
|
VERSION_FIELDS=2
|
|
|
|
|
|
|
|
|
|
+# Service name
|
|
|
|
|
+SERVICE="NextCloud"
|
|
|
|
|
+
|
|
|
######################
|
|
######################
|
|
|
# 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 doing.
|
|
|
# All configureable parameters are above this section.
|
|
# All configureable parameters are above this section.
|
|
|
######################
|
|
######################
|
|
|
|
|
|
|
|
# check if jq package is present on the system
|
|
# check if jq package is present on the system
|
|
|
-/usr/bin/which jq >/dev/null 2>&1
|
|
|
|
|
-if [ $? -ne 0 ]; then
|
|
|
|
|
- echo "2 \"NextCloud\" - NextCloud localcheck requires jq package to be installed"
|
|
|
|
|
- echo "2 \"NextCloud Apps\" - NextCloud localcheck requires jq package to be installed"
|
|
|
|
|
- exit;
|
|
|
|
|
|
|
+if ! command -v curl >/dev/null 2>&1; then
|
|
|
|
|
+ echo "2 \"$SERVICE\" - $SERVICE localcheck requires jq package to be installed"
|
|
|
|
|
+ echo "2 \"$SERVICE Apps\" - $SERVICE Apps localcheck requires jq package to be installed"
|
|
|
|
|
+ exit 0
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# check if configured apache user exists
|
|
# check if configured apache user exists
|
|
|
if ! id -u "$APACHEUSER" >/dev/null 2>&1; then
|
|
if ! id -u "$APACHEUSER" >/dev/null 2>&1; then
|
|
|
- echo "2 \"NextCloud\" - NextCloud localcheck webserver user does not exist, check configuration!"
|
|
|
|
|
- echo "2 \"NextCloud Apps\" - NextCloud localcheck webserver user does not exist, check configuration!"
|
|
|
|
|
- exit;
|
|
|
|
|
|
|
+ echo "2 \"$SERVICE\" - $SERVICE localcheck webserver user does not exist, check configuration!"
|
|
|
|
|
+ echo "2 \"$SERVICE Apps\" - $SERVICE Apps localcheck webserver user does not exist, check configuration!"
|
|
|
|
|
+ exit 0
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# check if configured basepath exists
|
|
# check if configured basepath exists
|
|
|
if [ ! -d "$BASEPATH" ]; then
|
|
if [ ! -d "$BASEPATH" ]; then
|
|
|
- echo "2 \"NextCloud\" - NextCloud localcheck could not find configured basepath, check configuration!"
|
|
|
|
|
- echo "2 \"NextCloud Apps\" - NextCloud localcheck could not find configured basepath, check configuration!"
|
|
|
|
|
- exit;
|
|
|
|
|
|
|
+ echo "2 \"$SERVICE\" - $SERVICE localcheck could not find configured basepath, check configuration!"
|
|
|
|
|
+ echo "2 \"$SERVICE Apps\" - $SERVICE Apps localcheck could not find configured basepath, check configuration!"
|
|
|
|
|
+ exit 0
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# Get current installed Nextcloud version-information
|
|
# Get current installed Nextcloud version-information
|
|
@@ -77,32 +90,35 @@ fi
|
|
|
|
|
|
|
|
NCINSTALLED=$(sudo -u "$APACHEUSER" php "$BASEPATH"/occ status --output=json | jq -r '.versionstring' | cut -d. -f1-"$VERSION_FIELDS")
|
|
NCINSTALLED=$(sudo -u "$APACHEUSER" php "$BASEPATH"/occ status --output=json | jq -r '.versionstring' | cut -d. -f1-"$VERSION_FIELDS")
|
|
|
|
|
|
|
|
-# Get latest avaiable version information
|
|
|
|
|
|
|
+# Get latest avaiable (core) version information
|
|
|
# In v29.x.x this has changed outputs <name-of-instance> <version>,
|
|
# In v29.x.x this has changed outputs <name-of-instance> <version>,
|
|
|
|
|
|
|
|
NCAVAILABLE=$(curl -s --connect-timeout 5 --fail-with-body "$RELEASEURL" | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//' | cut -d. -f1-"$VERSION_FIELDS")
|
|
NCAVAILABLE=$(curl -s --connect-timeout 5 --fail-with-body "$RELEASEURL" | sed -e 's/<[^>]*>//g' | grep -o "^nextcloud.*.zip" | tail -n1 | cut -d'-' -f 2 | sed 's/.\{4\}$//' | cut -d. -f1-"$VERSION_FIELDS")
|
|
|
|
|
|
|
|
# if the check on the release-url is not returning a version - report status
|
|
# if the check on the release-url is not returning a version - report status
|
|
|
if [ -z "$NCAVAILABLE" ]; then
|
|
if [ -z "$NCAVAILABLE" ]; then
|
|
|
- echo "1 \"NextCloud\" - 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 for $SERVICE Core"
|
|
|
|
|
+
|
|
|
# compare resuts of installed and available version and report update available if they differ
|
|
# compare resuts of installed and available version and report update available if they differ
|
|
|
elif [ "$NCINSTALLED" != "$NCAVAILABLE" ]; then
|
|
elif [ "$NCINSTALLED" != "$NCAVAILABLE" ]; then
|
|
|
- echo "1 \"NextCloud\" - A new NextCloud version ($NCAVAILABLE)is available, running version $NCINSTALLED please upgrade"
|
|
|
|
|
|
|
+ echo "1 \"$SERVICE\" - A new $SERVICE Core version ($NCAVAILABLE) is available, running Core version is: $NCINSTALLED please upgrade"
|
|
|
else
|
|
else
|
|
|
sudo -u "$APACHEUSER" php "$BASEPATH"/occ status -e
|
|
sudo -u "$APACHEUSER" php "$BASEPATH"/occ status -e
|
|
|
if [ $? -eq 0 ]; then
|
|
if [ $? -eq 0 ]; then
|
|
|
- echo "0 \"NextCloud\" - NextCloud all up to date"
|
|
|
|
|
|
|
+ echo "0 \"$SERVICE\" - $SERVICE all up to date"
|
|
|
elif [ $? -eq 1 ]; then
|
|
elif [ $? -eq 1 ]; then
|
|
|
- echo "1 \"NextCloud\" - NextCloud maintenance-mode is enabled"
|
|
|
|
|
|
|
+ echo "1 \"$SERVICE\" - $SERVICE maintenance-mode is enabled"
|
|
|
elif [ $? -eq 2 ]; then
|
|
elif [ $? -eq 2 ]; then
|
|
|
- echo "2 \"NextCloud\" - NextCloud Core needs updating"
|
|
|
|
|
|
|
+ echo "2 \"$SERVICE\" - $SERVICE Core needs updating"
|
|
|
fi
|
|
fi
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
APPRESULT=$(sudo -u "$APACHEUSER" php "$BASEPATH"/occ app:update --showonly)
|
|
APPRESULT=$(sudo -u "$APACHEUSER" php "$BASEPATH"/occ app:update --showonly)
|
|
|
if [[ "$APPRESULT" == *"All apps are up-to-date"* ]]; then
|
|
if [[ "$APPRESULT" == *"All apps are up-to-date"* ]]; then
|
|
|
- echo "0 \"NextCloud Apps\" - NextCloud Apps all up to date"
|
|
|
|
|
|
|
+ echo "0 \"$SERVICE Apps\" - $SERVICE Apps all up to date"
|
|
|
|
|
+ exit 0
|
|
|
else
|
|
else
|
|
|
UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
|
|
UPDATECOUNT=$(echo "$APPRESULT" | wc -l)
|
|
|
- echo "1 \"NextCloud Apps\" - $UPDATECOUNT NextCloud Apps requires updates"
|
|
|
|
|
|
|
+ echo "1 \"$SERVICE Apps\" - $UPDATECOUNT $SERVICE Apps requires updates"
|
|
|
|
|
+ exit 0
|
|
|
fi
|
|
fi
|