1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

Merge pull request #1117 from shtrom/nextcloud_fixups

various fixups of the Nextcloud plugin
This commit is contained in:
Lars Kruse 2020-09-13 20:48:50 +02:00 committed by GitHub
commit 11861370c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# shellcheck shell=dash
set -e set -e
@ -28,6 +29,10 @@ Set username and password in your munin-node configuration
[nextcloud_cloud.domain.tld] [nextcloud_cloud.domain.tld]
env.username <nexcloud_user> env.username <nexcloud_user>
env.password <nextcloud_password> env.password <nextcloud_password>
env.api_path <default: /ocs/v2.php/apps/serverinfo/api/v1/info>
env.scheme <default: https>
env.timeout <default: 2s>
env.updates_warning <default: 1>
It's advised to set an app password (for this plugin) in your nextcloud It's advised to set an app password (for this plugin) in your nextcloud
instance and not to use the "real" password of your nextcloud user. instance and not to use the "real" password of your nextcloud user.
@ -47,44 +52,54 @@ GPLv2
=cut =cut
# shellcheck disable=SC1090
. "$MUNIN_LIBDIR/plugins/plugin.sh" . "$MUNIN_LIBDIR/plugins/plugin.sh"
API_PATH="/ocs/v2.php/apps/serverinfo/api/v1/info?format=json" if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
set -x
fi
API_PATH="${api_path:-/ocs/v2.php/apps/serverinfo/api/v1/info}?format=json"
DOMAIN="${0##*nextcloud_}" DOMAIN="${0##*nextcloud_}"
SCHEME="${scheme:-https}://"
TIMEOUT="${timeout:-2}"
UPDATES_WARNING="${updates_warning:-1}"
CLEANDOMAIN="$(clean_fieldname "$DOMAIN")" CLEANDOMAIN="$(clean_fieldname "$DOMAIN")"
USERNAME="${username:-}" USERNAME="${username:-}"
PASSWORD="${password:-}" PASSWORD="${password:-}"
print_json_data() { print_json_data() {
local FIRST="$1" local FIRST="$1"
[ -z "$FIRST" ] && exit 0 local VALUE="U"
shift 1 shift 1
test -z "$FIRST" && echo "missing data for 'print_json_data "" $*'">&2
for KEY in "$@"; do for KEY in "$@"; do
VALUE=$(echo "$FIRST" | jq -cr ".$KEY") if [ -n "$FIRST" ]; then
VALUE=$(echo "$FIRST" | jq -cr ".$KEY")
fi
echo "$KEY.value $VALUE" echo "$KEY.value $VALUE"
done done
} }
test_https() { fetch_url () {
[ -z "$DOMAIN" ] && exit 0 curl -s -f -m "${TIMEOUT}" "$@"
curl -s -f -m 2 -I "https://$DOMAIN" > /dev/null && echo true && exit 0
} }
case $1 in case $1 in
autoconf) autoconf)
if [ -x /usr/bin/curl ]; then if [ ! -x "$(command -v curl)" ]; then
if [ -x /usr/bin/jq ]; then echo "no (curl not found)"
[ "$(test_https)" ] && DOMAIN="https://$DOMAIN" || DOMAIN="http://$DOMAIN" elif [ ! -x "$(command -v jq)" ]; then
curl -s -f -m 2 -u "$USERNAME:$PASSWORD" -I "$DOMAIN$API_PATH" | grep -iq "Content-Type: application/json" && echo "yes" && exit 0 || echo "no (invalid or empty response from nextlcoud serverinfo api)" && exit 0 echo "no (jq not found)"exit 0
else else
echo "no (jq not found)" && exit 0 fetch_url -I -u "$USERNAME:$PASSWORD" -I "${SCHEME}${DOMAIN}${API_PATH}" \
fi | grep -iq "Content-Type: application/json" \
else && echo "yes" \
echo "no (/usr/bin/curl not found)" && exit 0 || echo "no (invalid or empty response from nextlcoud serverinfo api)"
fi fi
;; exit 0
;;
config) config)
cat << EOM cat << EOM
@ -190,7 +205,7 @@ graph_category cloud
num_updates_available.label available app updates num_updates_available.label available app updates
num_updates_available.info number of available app updates num_updates_available.info number of available app updates
num_updates_available.min 0 num_updates_available.min 0
num_updates_available.warning 1 num_updates_available.warning ${UPDATES_WARNING}
num_installed.label installed apps num_installed.label installed apps
num_installed.info number of installed apps num_installed.info number of installed apps
num_installed.min 0 num_installed.min 0
@ -201,8 +216,9 @@ EOM
esac esac
# Get JSON data # Get JSON data
[ "$(test_https)" ] && DOMAIN="https://$DOMAIN" || DOMAIN="http://$DOMAIN" JSONSTATS=$(
JSONSTATS=$(curl -s -f -m 2 -u "$USERNAME:$PASSWORD" "$DOMAIN$API_PATH" | sed 's/\\/\\\\/g' | jq -cr ".ocs.data") fetch_url -u "$USERNAME:$PASSWORD" "${SCHEME}${DOMAIN}${API_PATH}" | sed 's/\\/\\\\/g' | jq -cr ".ocs.data" 2>&1
)
USERS=$(echo "$JSONSTATS" | jq -cr ".activeUsers") USERS=$(echo "$JSONSTATS" | jq -cr ".activeUsers")
STORAGE=$(echo "$JSONSTATS" | jq -cr ".nextcloud.storage") STORAGE=$(echo "$JSONSTATS" | jq -cr ".nextcloud.storage")
SHARES=$(echo "$JSONSTATS" | jq -cr ".nextcloud.shares") SHARES=$(echo "$JSONSTATS" | jq -cr ".nextcloud.shares")