scripts / monitoring.d / raspberrypi /
Newer Older
143 lines | 5.627kb
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
1
# vim: ft=sh
ajout du monitoring des diff...
Sébastien MARQUE authored on 2017-02-24
2
dir=$1
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
3

            
4
function nginx () {
5
    nc -zw2 127.0.0.1 80 || echo "injoignable sur port 80 local"
6
    nc -zw2 sebmarque.hd.free.fr 80 || echo "injoignable sur port 80 distant"
7
    nc -zw2 sebmarque.hd.free.fr 443 || echo "injoignable sur port 443 distant"
8
}
9

            
10
function searx () {
espace les tests des applis
Sébastien MARQUE authored on 2017-02-26
11
    _turn 5 || return
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
12
    nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888"
13
}
14

            
15
function gitprep () {
espace les tests des applis
Sébastien MARQUE authored on 2017-02-26
16
    _turn 5 || return
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
17
    nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020"
18
}
19

            
ajout du monitoring des diff...
Sébastien MARQUE authored on 2017-02-24
20
function webapps () {
espace les tests des applis
Sébastien MARQUE authored on 2017-02-26
21
    _turn 3 || return # test toutes les 3 heures
réécriture complète de l'aud...
Sébastien MARQUE authored on 2017-02-25
22
    awk -v sq="'" '
23
        /^[^#]+#\s*monitoring\s/ {
24
            if ($1 == "listen") {
fix gensub/awk warning
Sébastien MARQUE authored on 2018-12-06
25
                port = ":" gensub(";", "", "1", $2)
26
                proto = gensub(";", "", "1", $3) == "ssl" ? "https" : "http"
avertissement gensub sur 3èm...
Sébastien MARQUE authored on 2019-07-22
27
                pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/, "1", "1")
réécriture complète de l'aud...
Sébastien MARQUE authored on 2017-02-25
28
                if (proto == "https" && port == ":443") port = ""
29
            }
30
            if ($1 == "server_name") {
fix gensub/awk warning
Sébastien MARQUE authored on 2018-12-06
31
                server_name = gensub(";", "", "1", $2)
avertissement gensub sur 3èm...
Sébastien MARQUE authored on 2019-07-22
32
                sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/, "1", "1")
réécriture complète de l'aud...
Sébastien MARQUE authored on 2017-02-25
33
            }
34
            if ($1 == "location" && sname != "" && pname != "" && sname == pname) {
fix gensub/awk warning
Sébastien MARQUE authored on 2018-12-06
35
                l=gensub(/^\s*location\s[^\/]*(\/.*)\{\s*#\s*monitoring\s+(.+)$/,"\\1,\\2", "1")
réécriture complète de l'aud...
Sébastien MARQUE authored on 2017-02-25
36
                split(l, location, /\s*,\s*/)
37
                if (location[2] == sname) {
38
                    monitoring[location[2]][location[1]]["monitoring"] = location[3]
39
                    monitoring[location[2]][location[1]]["response_code"] = location[4]
40
                    monitoring[location[2]][location[1]]["url"] = proto "://" server_name port location[1] location[5]
41
                    if (location[6] != "")
42
                        monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq location[6] sq
43
                    else
44
                        monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq "Mozilla/5 (monitoring)" sq
45
                }
46
            }
47
        }
48
        END {
49
            for (mid in monitoring) {
50
                for (locid in monitoring[mid]) {
51
                    curl = sprintf("curl --silent --max-time 2 --output /dev/null --write-out %{response_code} --output /dev/null %s %s",
52
                          monitoring[mid][locid]["user-agent"],
53
                          monitoring[mid][locid]["url"])
54
                    curl | getline response_code
55
                    close(curl)
ne considère pas le code ret...
Sébastien MARQUE authored on 2017-08-18
56
                    if (response_code != monitoring[mid][locid]["response_code"] && response_code != "000")
réécriture complète de l'aud...
Sébastien MARQUE authored on 2017-02-25
57
                        printf("%s (%s)\n", monitoring[mid][locid]["monitoring"], response_code)
58
                }
59
            }
60
        }
61
    ' /etc/nginx/sites-enabled/*
ajout du monitoring des diff...
Sébastien MARQUE authored on 2017-02-24
62
}
63

            
ajoute monitoring extérieur ...
Sébastien MARQUE authored on 2019-07-22
64
function section () {
65
    nc -zw5 cloud.paris12.pcf.fr 443 || echo "cloud inaccessible"
66
    nc -zw5 cloud.paris12.pcf.fr 2200 || echo "section inaccessible"
67
}
68

            
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
69
function core_temp () {
70
    local min=60
71
    local level=("warning" "severe" "danger!")
72
    local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) ))
c'est bientôt l'été
Sébastien MARQUE authored on 2021-05-15
73
#    if test $step -gt 1; then
74
    if test $step -gt 5000; then # en été il fait plus chaud, c'est normal que ça monte à 60° régulièrement
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
75
        step=$((step / 10000))
fix typo
Sébastien MARQUE authored on 2018-12-06
76
        test $step -le 2 || step=2
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
77
        echo "${level[step]}: température > $((min + step * 10))°"
78
    fi
79
}
80

            
81
function core_alim () {
82
    eval $(/opt/vc/bin/vcgencmd measure_volts core)
improve volatge check
Sébastien MARQUE authored on 2018-12-06
83
    volt_fmt=${volt/\.}
84
    volt_fmt=${volt_fmt/V}
85
    test $volt_fmt -lt 12000 -o $volt_fmt -gt 15000 && echo "$volt"
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
86
}
87

            
refresh swap if possible
Sébastien MARQUE authored on 2021-01-01
88
function clean_swap () {
89
    _turn 2 || return
libère le cache plus réguliè...
Sébastien MARQUE authored on 2022-01-08
90
    echo 1 > /proc/sys/vm/drop_caches
91
    if LANG=C free -m | awk '
refresh swap if possible
Sébastien MARQUE authored on 2021-01-01
92
        /^Swap:/ {
93
            used = $3
94
        }
95
        END {
fix bad return code
seb authored on 2022-08-15
96
            bash_exit_code = !(used > 62)
97
            exit bash_exit_code
refresh swap if possible
Sébastien MARQUE authored on 2021-01-01
98
        }
99
    '; then
100
        systemctl stop dphys-swapfile \
101
        && systemctl stop zram        \
102
        && systemctl start zram       \
103
        && systemctl start dphys-swapfile \
104
        || echo 'erreur'
105
    fi
106
}
107

            
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
108
function mem_pressure () {
109
    local meminfo=($(</proc/meminfo))
110
    local level=(danger severe warning)
111
    local margin=30000
112
    for ((i=0; i<${#meminfo[@]}; i+=3)); do
113
        test ${meminfo[i]} == 'MemAvailable:' && break
114
    done
115
    meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 ))
116
    test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB"
117
}
118

            
vérifie existence d'albums p...
Sébastien MARQUE authored on 2018-12-06
119
function piwigo_private () {
120
    _turn 20 || return
121
    test "$(curl --silent 'http://192.168.0.71/photos/ws.php?format=json&method=pwg.categories.getList' | sum)" = "00569     1" || echo "albums visibles publiquement"
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
122
}
ajout vérification de nouvel...
Sébastien MARQUE authored on 2024-02-13
123

            
124
function snappymail_version () {
125
    _turn 24 || return
126
    local installed_version=$(</var/www/rainloop/data/VERSION)
127
    local release_url='https://api.github.com/repos/the-djmaze/snappymail/releases/latest'
128
    local version=$(curl -sL -H "Accept: application/vnd.github+json" $release_url | jq -r '.name | ltrimstr("v")')
129
    if test $version != $installed_version; then
130
        echo "nouvelle version dispo: $version"
131
    fi
132
}
133

            
134
function navidrome_version () {
135
    _turn 24 || return
136
    local installed_version=$(find ~navidrome/navidrome -printf "%C@")
137
    local release_url='https://api.github.com/repos/navidrome/navidrome/releases/latest'
138
    local version=$(curl -sL -H "Accept: application/vnd.github+json" $release_url \
139
                  | jq -r '.assets | .[] | select(.name | contains("linux_armv7")) | .updated_at | fromdateiso8601')
140
    if test $version -gt ${installed_version%.*}; then
141
        echo "nouvelle version dispo"
142
    fi
143
}