root / plugins / nextcloud / nextcloud_ @ 09b88141
Historique | Voir | Annoter | Télécharger (7,28 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# shellcheck shell=dash |
| 3 |
|
| 4 |
set -e |
| 5 |
|
| 6 |
: << =cut |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
nextcloud_ - Monitor usage of nextcloud instances |
| 11 |
|
| 12 |
=head1 APPLICABLE SYSTEMS |
| 13 |
|
| 14 |
Nexcloud instances |
| 15 |
|
| 16 |
=head1 CONFIGURATION |
| 17 |
|
| 18 |
Requires installed curl and jq, a command-line json processor. |
| 19 |
|
| 20 |
This is a wildcard plugin. To monitor a nextcloud instance, link |
| 21 |
nextcloud_<nextcloud-domain> to this file. You can even append a port |
| 22 |
(:8443) to the file if needed. For example, |
| 23 |
|
| 24 |
ln -s /usr/share/munin/plugins/nextcloud_ \ |
| 25 |
/etc/munin/plugins/nextcloud_cloud.domain.tld |
| 26 |
|
| 27 |
Set username and password in your munin-node configuration |
| 28 |
|
| 29 |
[nextcloud_cloud.domain.tld] |
| 30 |
env.username <nexcloud_user> |
| 31 |
env.password <nextcloud_password> |
| 32 |
env.api_path <default: /ocs/v2.php/apps/serverinfo/api/v1/info> |
| 33 |
env.scheme <default: https> |
| 34 |
env.timeout <default: 2s> |
| 35 |
env.updates_warning <default: 1> |
| 36 |
|
| 37 |
It's advised to set an app password (for this plugin) in your nextcloud |
| 38 |
instance and not to use the "real" password of your nextcloud user. |
| 39 |
|
| 40 |
=head1 AUTHOR |
| 41 |
|
| 42 |
Copyright (C) 2020 Sebastian L. (https://momou.ch) |
| 43 |
|
| 44 |
=head1 LICENSE |
| 45 |
|
| 46 |
GPLv2 |
| 47 |
|
| 48 |
=head1 MAGIC MARKERS |
| 49 |
|
| 50 |
#%# family=manual |
| 51 |
#%# capabilities=autoconf |
| 52 |
|
| 53 |
=cut |
| 54 |
|
| 55 |
# shellcheck disable=SC1090 |
| 56 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 57 |
|
| 58 |
if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
|
| 59 |
set -x |
| 60 |
fi |
| 61 |
|
| 62 |
API_PATH="${api_path:-/ocs/v2.php/apps/serverinfo/api/v1/info}?format=json"
|
| 63 |
DOMAIN="${0##*nextcloud_}"
|
| 64 |
SCHEME="${scheme:-https}://"
|
| 65 |
TIMEOUT="${timeout:-2}"
|
| 66 |
UPDATES_WARNING="${updates_warning:-1}"
|
| 67 |
CLEANDOMAIN="$(clean_fieldname "$DOMAIN")" |
| 68 |
USERNAME="${username:-}"
|
| 69 |
PASSWORD="${password:-}"
|
| 70 |
|
| 71 |
print_json_data() {
|
| 72 |
local FIRST="$1" |
| 73 |
local VALUE="U" |
| 74 |
shift 1 |
| 75 |
test -z "$FIRST" && echo "missing data for 'print_json_data "" $*'">&2 |
| 76 |
for KEY in "$@"; do |
| 77 |
if [ -n "$FIRST" ]; then |
| 78 |
VALUE=$(echo "$FIRST" | jq -cr ".$KEY") |
| 79 |
fi |
| 80 |
echo "$KEY.value $VALUE" |
| 81 |
done |
| 82 |
} |
| 83 |
|
| 84 |
fetch_url () {
|
| 85 |
curl -s -f -m "${TIMEOUT}" "$@"
|
| 86 |
} |
| 87 |
|
| 88 |
case $1 in |
| 89 |
|
| 90 |
autoconf) |
| 91 |
if [ ! -x "$(command -v curl)" ]; then |
| 92 |
echo "no (curl not found)" |
| 93 |
elif [ ! -x "$(command -v jq)" ]; then |
| 94 |
echo "no (jq not found)"exit 0 |
| 95 |
else |
| 96 |
fetch_url -I -u "$USERNAME:$PASSWORD" -I "${SCHEME}${DOMAIN}${API_PATH}" \
|
| 97 |
| grep -iq "Content-Type: application/json" \ |
| 98 |
&& echo "yes" \ |
| 99 |
|| echo "no (invalid or empty response from nextlcoud serverinfo api)" |
| 100 |
fi |
| 101 |
exit 0 |
| 102 |
;; |
| 103 |
config) |
| 104 |
|
| 105 |
cat << EOM |
| 106 |
multigraph nextcloud_users_$CLEANDOMAIN |
| 107 |
graph_title Nextcloud users on $DOMAIN |
| 108 |
graph_args --base 1000 -l 0 |
| 109 |
graph_printf %.0lf |
| 110 |
graph_vlabel connected users |
| 111 |
graph_info number of connected user |
| 112 |
graph_category cloud |
| 113 |
last5minutes.label last 5 minutes |
| 114 |
last5minutes.info users connected in the last 5 minutes |
| 115 |
last5minutes.min 0 |
| 116 |
last1hour.label last hour |
| 117 |
last1hour.info users connected in the last hour |
| 118 |
last1hour.min 0 |
| 119 |
last24hours.label last 24 hours |
| 120 |
last24hours.info users connected in the last 24 hours |
| 121 |
last24hours.min 0 |
| 122 |
num_users.label number of users |
| 123 |
num_users.info total number of users |
| 124 |
num_users.min 0 |
| 125 |
multigraph nextcloud_files_$CLEANDOMAIN |
| 126 |
graph_title Nextcloud files on $DOMAIN |
| 127 |
graph_args --base 1000 -l 0 |
| 128 |
graph_printf %.0lf |
| 129 |
graph_vlabel number of files |
| 130 |
graph_info number of files |
| 131 |
graph_category cloud |
| 132 |
num_files.label number of files |
| 133 |
num_files.info current number of files |
| 134 |
num_files.min 0 |
| 135 |
multigraph nextcloud_shares_$CLEANDOMAIN |
| 136 |
graph_title Nextcloud shares on $DOMAIN |
| 137 |
graph_args --base 1000 -l 0 |
| 138 |
graph_printf %.0lf |
| 139 |
graph_vlabel number of shares |
| 140 |
graph_info number of shares |
| 141 |
graph_category cloud |
| 142 |
num_shares.label total number of shares |
| 143 |
num_shares.info current over all total of shares |
| 144 |
num_shares.min 0 |
| 145 |
num_shares_user.label user shares |
| 146 |
num_shares_user.info current total of user shares |
| 147 |
num_shares_user.min 0 |
| 148 |
num_shares_groups.label group shares |
| 149 |
num_shares_groups.info current total of group shares |
| 150 |
num_shares_groups.min 0 |
| 151 |
num_shares_link.label link shares |
| 152 |
num_shares_link.info current total of link shares |
| 153 |
num_shares_link.min 0 |
| 154 |
num_shares_mail.label mail shares |
| 155 |
num_shares_mail.info current total of mail shares |
| 156 |
num_shares_mail.min 0 |
| 157 |
num_shares_room.label room shares |
| 158 |
num_shares_room.info current total of room shares |
| 159 |
num_shares_room.min 0 |
| 160 |
num_shares_link_no_password.label link shares without password protection |
| 161 |
num_shares_link_no_password.info current total of link shares without password protection |
| 162 |
num_shares_link_no_password.min 0 |
| 163 |
num_fed_shares_sent.label federated shares sent |
| 164 |
num_fed_shares_sent.info current total of federated shares sent |
| 165 |
num_fed_shares_sent.min 0 |
| 166 |
num_fed_shares_received.label federated shares received |
| 167 |
num_fed_shares_received.info current total of federated shares received |
| 168 |
num_fed_shares_received.min 0 |
| 169 |
multigraph nextcloud_dbsize_$CLEANDOMAIN |
| 170 |
graph_title Nextcloud database size on $DOMAIN |
| 171 |
graph_args --base 1024 -l 0 |
| 172 |
graph_vlabel size in bytes |
| 173 |
graph_info database database size in bytes |
| 174 |
graph_category cloud |
| 175 |
db_size.label database size in bytes |
| 176 |
db_size.info database size in bytes |
| 177 |
db_size.draw AREA |
| 178 |
db_size.min 0 |
| 179 |
multigraph nextcloud_storages_$CLEANDOMAIN |
| 180 |
graph_title Nextcloud storages on $DOMAIN |
| 181 |
graph_args --base 1000 -l 0 |
| 182 |
graph_printf %.0lf |
| 183 |
graph_vlabel number |
| 184 |
graph_info number of storages |
| 185 |
graph_category cloud |
| 186 |
num_storages.label total number of storages |
| 187 |
num_storages.info current total of storages |
| 188 |
num_storages.min 0 |
| 189 |
num_storages_local.label number of local storages |
| 190 |
num_storages_local.info current number of local storages |
| 191 |
num_storages_local.min 0 |
| 192 |
num_storages_home.label number of home storages |
| 193 |
num_storages_home.info current number of home storages |
| 194 |
num_storages_home.min 0 |
| 195 |
num_storages_other.label number of other storages |
| 196 |
num_storages_other.info current number of other storages |
| 197 |
num_storages_other.min 0 |
| 198 |
multigraph nextcloud_apps_$CLEANDOMAIN |
| 199 |
graph_title Nextcloud apps on $DOMAIN |
| 200 |
graph_args --base 1000 -l 0 |
| 201 |
graph_printf %.0lf |
| 202 |
graph_vlabel apps |
| 203 |
graph_info number of installed and updatable apps |
| 204 |
graph_category cloud |
| 205 |
num_updates_available.label available app updates |
| 206 |
num_updates_available.info number of available app updates |
| 207 |
num_updates_available.min 0 |
| 208 |
num_updates_available.warning ${UPDATES_WARNING}
|
| 209 |
num_installed.label installed apps |
| 210 |
num_installed.info number of installed apps |
| 211 |
num_installed.min 0 |
| 212 |
EOM |
| 213 |
exit 0 |
| 214 |
;; |
| 215 |
|
| 216 |
esac |
| 217 |
|
| 218 |
# Get JSON data |
| 219 |
JSONSTATS=$( |
| 220 |
fetch_url -u "$USERNAME:$PASSWORD" "${SCHEME}${DOMAIN}${API_PATH}" | sed 's/\\/\\\\/g' | jq -cr ".ocs.data" 2>&1
|
| 221 |
) |
| 222 |
USERS=$(echo "$JSONSTATS" | jq -cr ".activeUsers") |
| 223 |
STORAGE=$(echo "$JSONSTATS" | jq -cr ".nextcloud.storage") |
| 224 |
SHARES=$(echo "$JSONSTATS" | jq -cr ".nextcloud.shares") |
| 225 |
DBSIZE=$(echo "$JSONSTATS" | jq -cr ".server.database.size") |
| 226 |
APPS=$(echo "$JSONSTATS" | jq -cr ".nextcloud.system.apps") |
| 227 |
|
| 228 |
# users |
| 229 |
echo "multigraph nextcloud_users_$CLEANDOMAIN" |
| 230 |
print_json_data "$USERS" last5minutes last1hour last24hours |
| 231 |
print_json_data "$STORAGE" num_users |
| 232 |
|
| 233 |
# files |
| 234 |
echo "multigraph nextcloud_files_$CLEANDOMAIN" |
| 235 |
print_json_data "$STORAGE" num_files |
| 236 |
|
| 237 |
# storages |
| 238 |
echo "multigraph nextcloud_storages_$CLEANDOMAIN" |
| 239 |
print_json_data "$STORAGE" num_storages num_storages_local num_storages_home num_storages_other |
| 240 |
|
| 241 |
# shares |
| 242 |
echo "multigraph nextcloud_shares_$CLEANDOMAIN" |
| 243 |
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 |
| 244 |
|
| 245 |
# dbsize |
| 246 |
echo "multigraph nextcloud_dbsize_$CLEANDOMAIN" |
| 247 |
echo "db_size.value $DBSIZE" |
| 248 |
|
| 249 |
# apps |
| 250 |
echo "multigraph nextcloud_apps_$CLEANDOMAIN" |
| 251 |
print_json_data "$APPS" num_installed num_updates_available |
