Projet

Général

Profil

Révision 195a733d

ID195a733d5d6ed6377e61335a3e5432e49dbcc33e
Parent 1a614fb0
Enfant a7d44887

Ajouté par Olivier Mehani il y a environ 5 ans

[nextcloud_] Add support for --pidebug, and more parameters

Signed-off-by: Olivier Mehani <>

Voir les différences:

plugins/nextcloud/nextcloud_
28 28
[nextcloud_cloud.domain.tld]
29 29
env.username <nexcloud_user>
30 30
env.password <nextcloud_password>
31
env.api_path <default: /ocs/v2.php/apps/serverinfo/api/v1/info>
32
env.timeout <default: 2s>
31 33

  
32 34
It's advised to set an app password (for this plugin) in your nextcloud 
33 35
instance and not to use the "real" password of your nextcloud user.
......
47 49

  
48 50
=cut
49 51

  
52
# shellcheck disable=SC1090
50 53
. "$MUNIN_LIBDIR/plugins/plugin.sh"
51 54

  
52
API_PATH="/ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
55
if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
56
    set -x
57
fi
58

  
59
API_PATH="${api_path:-/ocs/v2.php/apps/serverinfo/api/v1/info}?format=json"
53 60
DOMAIN="${0##*nextcloud_}"
61
TIMEOUT="${timeout:-2}"
54 62
CLEANDOMAIN="$(clean_fieldname "$DOMAIN")"
55 63
USERNAME="${username:-}"
56 64
PASSWORD="${password:-}"
57 65

  
58 66
print_json_data() {
67
    # shellcheck disable=SC2039
59 68
    local FIRST="$1"
60 69
    [ -z "$FIRST" ] && exit 0
61 70
    shift 1
......
67 76

  
68 77
test_https() {
69 78
    [ -z "$DOMAIN" ] && exit 0
70
    curl -s -f -m 2 -I "https://$DOMAIN" > /dev/null && echo true && exit 0
79
    curl -s -f -m "${TIMEOUT}" -I "https://$DOMAIN" > /dev/null && echo true && exit 0
71 80
}
72 81

  
73 82
case $1 in
......
76 85
        if [ -x /usr/bin/curl ]; then
77 86
            if [ -x /usr/bin/jq ]; then
78 87
                [ "$(test_https)" ] && DOMAIN="https://$DOMAIN" || DOMAIN="http://$DOMAIN"
79
                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
88
                curl -s -f -m "${TIMEOUT}" -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
80 89
            else
81 90
                echo "no (jq not found)" && exit 0
82 91
            fi
......
202 211

  
203 212
# Get JSON data
204 213
[ "$(test_https)" ] && DOMAIN="https://$DOMAIN" || DOMAIN="http://$DOMAIN"
205
JSONSTATS=$(curl -s -f -m 2 -u "$USERNAME:$PASSWORD" "$DOMAIN$API_PATH" | sed 's/\\/\\\\/g' | jq -cr ".ocs.data")
214
JSONSTATS=$(curl -s -f -m "${TIMEOUT}" -u "$USERNAME:$PASSWORD" "$DOMAIN$API_PATH" | sed 's/\\/\\\\/g' | jq -cr ".ocs.data")
206 215
USERS=$(echo "$JSONSTATS" | jq -cr ".activeUsers")
207 216
STORAGE=$(echo "$JSONSTATS" | jq -cr ".nextcloud.storage")
208 217
SHARES=$(echo "$JSONSTATS" | jq -cr ".nextcloud.shares")

Formats disponibles : Unified diff