Make clear that it is a Nagios plugin and cleaner code

This commit is contained in:
Laurent Poujoulat 2020-07-01 14:40:14 +02:00 committed by root
parent 62f23dc0bf
commit f60c0c1dc3

View File

@ -22,11 +22,22 @@
# This checks for updates of nextcloud components. # 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, # 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. # and if everything is OK, tell it on stdout "OK", and returns 0.
#
# This is a Nagios plugin and thus follows its return code standards
# ================================================ # ================================================
# Configuration data # Configuration data
NEXTCLOUD_ROOT="/var/www/valise.chapril.org" NEXTCLOUD_ROOT="/var/www/valise.chapril.org"
# Constants for return codes
readonly NS_OK=0
readonly NS_WARNING=1
readonly NS_CRITICAL=1
readonly NS_UNKNOWN=1
# Returns script usage # Returns script usage
function usage() function usage()
{ {
@ -36,7 +47,7 @@ function usage()
# Main entry point # Main entry point
# By default, we assume to fail # By default, we assume to fail
EXIT_RESULT=1 EXIT_RESULT=${NS_UNKNOWN}
# Usage check # Usage check
if [ "$#" -ne 0 ] if [ "$#" -ne 0 ]
@ -51,6 +62,7 @@ else
if [ $? != 0 ] if [ $? != 0 ]
then then
EXIT_RESULT=${NS_CRITICAL}
echo "Failed to check Nextcloud update" echo "Failed to check Nextcloud update"
else else
@ -59,9 +71,10 @@ else
if [ $? == 0 ] if [ $? == 0 ]
then then
EXIT_RESULT=${NS_OK}
echo "OK" echo "OK"
EXIT_RESULT=0
else else
EXIT_RESULT=${NS_WARNING}
echo ${UPDATE_LIST} echo ${UPDATE_LIST}
fi fi