From 6faa1ec942e53aa216c2c72fe14611ea8c4a778d Mon Sep 17 00:00:00 2001 From: Laurent Poujoulat Date: Tue, 30 Jun 2020 12:01:03 +0200 Subject: [PATCH] Changed the way to check for updates. As the REST API is incomplete and don't returns core updates (!), we workaround that by calling occ update:check --- monitoring/check_valisechaprilorg_update | 40 ++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/monitoring/check_valisechaprilorg_update b/monitoring/check_valisechaprilorg_update index 1d6e566..4d04c78 100755 --- a/monitoring/check_valisechaprilorg_update +++ b/monitoring/check_valisechaprilorg_update @@ -25,15 +25,7 @@ # ================================================ # Configuration data -CURL_CREDENTIAL="/etc/valise.chapril.org/curl_credential" - -# Extract a json value by path (given as argument) -# The global JSON state is expected to be in NEXTCLOUD_STATE -# Only give the path part within the ocs.data section -getNcState() -{ - echo ${NEXTCLOUD_STATE} | jq ".ocs.data.$1" -} +NEXTCLOUD_ROOT="/var/www/valise.chapril.org" # Returns script usage function usage() @@ -41,22 +33,38 @@ function usage() echo "Usage: $(basename $0)" } - # Main entry point EXIT_RESULT=1 -# Read and store the current service state -NEXTCLOUD_STATE=`curl --silent --netrc-file ${CURL_CREDENTIAL} http://localhost/ocs/v2.php/apps/serverinfo/api/v1/info?format=json` - +# Usage check if [ "$#" -ne 0 ] then usage else - # Read and store the current service state - NEXTCLOUD_STATE=`curl --silent --netrc-file ${CURL_CREDENTIAL} http://localhost/ocs/v2.php/apps/serverinfo/api/v1/info?format=json` + # Currently, nor the serverinfo API, nor the occ command has a clean way of checking both the core and apps update status + # So we trick this by calling the occ update:check command and processing the output + cd ${NEXTCLOUD_ROOT} + UPDATE_LIST=$(sudo -u www-data php occ update:check) + + if [ $? != 0 ] + then + echo "Failed to check Nextcloud update" + else + + # OK, we have the human readable status, let's process it + echo ${UPDATE_LIST} | grep -q "Everything up to date" + + if [ $? == 0 ] + then + echo "OK" + EXIT_RESULT=0 + else + echo ${UPDATE_LIST} + fi + + fi - getNcState "nextcloud.system.apps.num_updates_available" fi exit ${EXIT_RESULT}