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

[plugins/nextcloud_] Only use one call to JQ to parse and report the info

Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
Olivier Mehani 2020-11-27 12:26:13 +11:00 committed by Lars Kruse
parent 0ab1e127a2
commit cd759e2f5c

View file

@ -26,20 +26,21 @@ nextcloud_<nextcloud-domain> to this file. You can even append a port
Set username and password in your munin-node configuration 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.api_path <default: /ocs/v2.php/apps/serverinfo/api/v1/info>
env.scheme <default: https> env.scheme <default: https>
env.timeout <default: 2s> env.timeout <default: 2s>
env.updates_warning <default: 1> 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.
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2020 Sebastian L. (https://momou.ch) Copyright (C) 2020 Sebastian L. (https://momou.ch),
Olivier Mehani <shtrom+munin@ssji.net>
=head1 LICENSE =head1 LICENSE
@ -64,23 +65,10 @@ DOMAIN="${0##*nextcloud_}"
SCHEME="${scheme:-https}://" SCHEME="${scheme:-https}://"
TIMEOUT="${timeout:-2}" TIMEOUT="${timeout:-2}"
UPDATES_WARNING="${updates_warning:-1}" UPDATES_WARNING="${updates_warning:-1}"
CLEANDOMAIN="$(clean_fieldname "$DOMAIN")" CLEANDOMAIN="$(clean_fieldname "${DOMAIN}")"
USERNAME="${username:-}" USERNAME="${username:-}"
PASSWORD="${password:-}" PASSWORD="${password:-}"
print_json_data() {
local FIRST="$1"
local VALUE="U"
shift 1
test -z "$FIRST" && echo "missing data for 'print_json_data "" $*'">&2
for KEY in "$@"; do
if [ -n "$FIRST" ]; then
VALUE=$(echo "$FIRST" | jq -cr ".$KEY")
fi
echo "$KEY.value $VALUE"
done
}
fetch_url () { fetch_url () {
curl -s -f -m "${TIMEOUT}" "$@" curl -s -f -m "${TIMEOUT}" "$@"
} }
@ -93,18 +81,18 @@ case $1 in
elif [ ! -x "$(command -v jq)" ]; then elif [ ! -x "$(command -v jq)" ]; then
echo "no (jq not found)"exit 0 echo "no (jq not found)"exit 0
else else
fetch_url -I -u "$USERNAME:$PASSWORD" -I "${SCHEME}${DOMAIN}${API_PATH}" \ fetch_url -I -u "${USERNAME}:${PASSWORD}" -I "${SCHEME}${DOMAIN}${API_PATH}" \
| grep -iq "Content-Type: application/json" \ | grep -iq "Content-Type: application/json" \
&& echo "yes" \ && echo "yes" \
|| echo "no (invalid or empty response from nextlcoud serverinfo api)" || echo "no (invalid or empty response from nextcloud serverinfo api)"
fi fi
exit 0 exit 0
;; ;;
config) config)
cat << EOM cat << EOM
multigraph nextcloud_users_$CLEANDOMAIN multigraph nextcloud_users_${CLEANDOMAIN}
graph_title Nextcloud users on $DOMAIN graph_title Nextcloud users on ${DOMAIN}
graph_args --base 1000 -l 0 graph_args --base 1000 -l 0
graph_printf %.0lf graph_printf %.0lf
graph_vlabel connected users graph_vlabel connected users
@ -122,8 +110,8 @@ last24hours.min 0
num_users.label number of users num_users.label number of users
num_users.info total number of users num_users.info total number of users
num_users.min 0 num_users.min 0
multigraph nextcloud_files_$CLEANDOMAIN multigraph nextcloud_files_${CLEANDOMAIN}
graph_title Nextcloud files on $DOMAIN graph_title Nextcloud files on ${DOMAIN}
graph_args --base 1000 -l 0 graph_args --base 1000 -l 0
graph_printf %.0lf graph_printf %.0lf
graph_vlabel number of files graph_vlabel number of files
@ -132,8 +120,8 @@ graph_category cloud
num_files.label number of files num_files.label number of files
num_files.info current number of files num_files.info current number of files
num_files.min 0 num_files.min 0
multigraph nextcloud_shares_$CLEANDOMAIN multigraph nextcloud_shares_${CLEANDOMAIN}
graph_title Nextcloud shares on $DOMAIN graph_title Nextcloud shares on ${DOMAIN}
graph_args --base 1000 -l 0 graph_args --base 1000 -l 0
graph_printf %.0lf graph_printf %.0lf
graph_vlabel number of shares graph_vlabel number of shares
@ -166,8 +154,8 @@ num_fed_shares_sent.min 0
num_fed_shares_received.label federated shares received num_fed_shares_received.label federated shares received
num_fed_shares_received.info current total of federated shares received num_fed_shares_received.info current total of federated shares received
num_fed_shares_received.min 0 num_fed_shares_received.min 0
multigraph nextcloud_dbsize_$CLEANDOMAIN multigraph nextcloud_dbsize_${CLEANDOMAIN}
graph_title Nextcloud database size on $DOMAIN graph_title Nextcloud database size on ${DOMAIN}
graph_args --base 1024 -l 0 graph_args --base 1024 -l 0
graph_vlabel size in bytes graph_vlabel size in bytes
graph_info database database size in bytes graph_info database database size in bytes
@ -176,8 +164,8 @@ db_size.label database size in bytes
db_size.info database size in bytes db_size.info database size in bytes
db_size.draw AREA db_size.draw AREA
db_size.min 0 db_size.min 0
multigraph nextcloud_storages_$CLEANDOMAIN multigraph nextcloud_storages_${CLEANDOMAIN}
graph_title Nextcloud storages on $DOMAIN graph_title Nextcloud storages on ${DOMAIN}
graph_args --base 1000 -l 0 graph_args --base 1000 -l 0
graph_printf %.0lf graph_printf %.0lf
graph_vlabel number graph_vlabel number
@ -195,8 +183,8 @@ num_storages_home.min 0
num_storages_other.label number of other storages num_storages_other.label number of other storages
num_storages_other.info current number of other storages num_storages_other.info current number of other storages
num_storages_other.min 0 num_storages_other.min 0
multigraph nextcloud_apps_$CLEANDOMAIN multigraph nextcloud_apps_${CLEANDOMAIN}
graph_title Nextcloud apps on $DOMAIN graph_title Nextcloud apps on ${DOMAIN}
graph_args --base 1000 -l 0 graph_args --base 1000 -l 0
graph_printf %.0lf graph_printf %.0lf
graph_vlabel apps graph_vlabel apps
@ -215,37 +203,44 @@ EOM
esac esac
# Get JSON data
JSONSTATS=$(
fetch_url -u "$USERNAME:$PASSWORD" "${SCHEME}${DOMAIN}${API_PATH}" | sed 's/\\/\\\\/g' | jq -cr ".ocs.data" 2>&1
)
USERS=$(echo "$JSONSTATS" | jq -cr ".activeUsers")
STORAGE=$(echo "$JSONSTATS" | jq -cr ".nextcloud.storage")
SHARES=$(echo "$JSONSTATS" | jq -cr ".nextcloud.shares")
DBSIZE=$(echo "$JSONSTATS" | jq -cr ".server.database.size") DBSIZE=$(echo "$JSONSTATS" | jq -cr ".server.database.size")
APPS=$(echo "$JSONSTATS" | jq -cr ".nextcloud.system.apps")
# users # users
echo "multigraph nextcloud_users_$CLEANDOMAIN" fetch_url -u "${USERNAME}:${PASSWORD}" "${SCHEME}${DOMAIN}${API_PATH}" \
print_json_data "$USERS" last5minutes last1hour last24hours | sed 's/\\/\\\\/g' \
print_json_data "$STORAGE" num_users | jq -r '.ocs.data
| @text "
multigraph nextcloud_users_'${CLEANDOMAIN}'
last5minutes \(.activeUsers.last5minutes)
last1hour \(.activeUsers.last1hour)
last24hours \(.activeUsers.last24hours)
num_users \(.nextcloud.storage.num_users)
# files multigraph nextcloud_files_'${CLEANDOMAIN}'
echo "multigraph nextcloud_files_$CLEANDOMAIN" num_files \(.nextcloud.storage.num_files)
print_json_data "$STORAGE" num_files
# storages multigraph nextcloud_storages_'${CLEANDOMAIN}'
echo "multigraph nextcloud_storages_$CLEANDOMAIN" num_storages \(.nextcloud.storage.num_storages)
print_json_data "$STORAGE" num_storages num_storages_local num_storages_home num_storages_other num_storages_local \(.nextcloud.storage.num_storages_local)
num_storages_home \(.nextcloud.storage.num_storages_home)
num_storages_other \(.nextcloud.storage.num_storages_other)
# shares multigraph nextcloud_shares_'${CLEANDOMAIN}'
echo "multigraph nextcloud_shares_$CLEANDOMAIN" num_shares \(.nextcloud.shares.num_shares)
print_json_data "$SHARES" num_shares num_shares_user num_shares_groups num_shares_link num_shares_mail num_shares_room num_shares_link_no_password num_fed_shares_sent num_fed_shares_received num_shares_user \(.nextcloud.shares.num_shares_user)
num_shares_groups \(.nextcloud.shares.num_shares_groups)
num_shares_link \(.nextcloud.shares.num_shares_link)
num_shares_mail \(.nextcloud.shares.num_shares_mail)
num_shares_room \(.nextcloud.shares.num_shares_room)
num_shares_link_no_password \(.nextcloud.shares.num_shares_link_no_password)
num_fed_shares_sent \(.nextcloud.shares.num_fed_shares_sent)
num_fed_shares_received \(.nextcloud.shares.num_fed_shares_received)
# dbsize multigraph nextcloud_dbsize_'${CLEANDOMAIN}'
echo "multigraph nextcloud_dbsize_$CLEANDOMAIN" db_size \(.server.database.size)
echo "db_size.value $DBSIZE"
# apps multigraph nextcloud_apps_'${CLEANDOMAIN}'
echo "multigraph nextcloud_apps_$CLEANDOMAIN" num_installed \(.nextcloud.system.apps.num_installed)
print_json_data "$APPS" num_installed num_updates_available num_updates_available \(.nextcloud.system.apps.num_updates_available)
"' \
| sed 's/ null$/ U/'