Creation of the basis for the supervision monitoring script

This commit is contained in:
Laurent Poujoulat 2020-06-29 18:56:08 +02:00 committed by root
parent 30156e94c1
commit b68858713d

View File

@ -0,0 +1,67 @@
#! /bin/bash
#
# Copyright (C) 2019 Laurent Poujoulat <lpoujoulat@april.org>
#
# This file is part of valise.chapril.org
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ================================================
# This checks for updates of nextcloud components.
# If any update is present, they are listed in human readable form on stdout, and 1 is returned,
# and if everything is OK, tell it on stdout "OK", and returns 0.
# ================================================
# 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"
}
# Returns script usage
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`
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`
getNcState "nextcloud.system.apps.num_updates_available"
fi
exit ${EXIT_RESULT}