scripts / monitoring.d / raspberrypi /
Newer Older
97 lines | 4.037kb
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"
27
                pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/, "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)
32
                sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/, "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

            
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
64
function core_temp () {
65
    local min=60
66
    local level=("warning" "severe" "danger!")
67
    local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) ))
ne pas tenir compte des aler...
Sébastien MARQUE authored on 2019-02-17
68
    if test $step -gt 1; then
adapte vérif de température ...
Sébastien MARQUE authored on 2018-12-06
69
#    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
70
        step=$((step / 10000))
fix typo
Sébastien MARQUE authored on 2018-12-06
71
        test $step -le 2 || step=2
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
72
        echo "${level[step]}: température > $((min + step * 10))°"
73
    fi
74
}
75

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

            
83
function mem_pressure () {
84
    local meminfo=($(</proc/meminfo))
85
    local level=(danger severe warning)
86
    local margin=30000
87
    for ((i=0; i<${#meminfo[@]}; i+=3)); do
88
        test ${meminfo[i]} == 'MemAvailable:' && break
89
    done
90
    meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 ))
91
    test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB"
92
}
93

            
vérifie existence d'albums p...
Sébastien MARQUE authored on 2018-12-06
94
function piwigo_private () {
95
    _turn 20 || return
96
    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
97
}