scripts / monitoring.d / raspberrypi /
Newer Older
104 lines | 4.152kb
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

            
20
function cherrymusic () {
espace les tests des applis
Sébastien MARQUE authored on 2017-02-26
21
    _turn 5 || return
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
22
    nc -zw2 127.0.0.1 8080 || echo "injoignable sur port 8080"
23
}
24

            
ajout du monitoring des diff...
Sébastien MARQUE authored on 2017-02-24
25
function webapps () {
espace les tests des applis
Sébastien MARQUE authored on 2017-02-26
26
    _turn 3 || return # test toutes les 3 heures
réécriture complète de l'aud...
Sébastien MARQUE authored on 2017-02-25
27
    awk -v sq="'" '
28
        /^[^#]+#\s*monitoring\s/ {
29
            if ($1 == "listen") {
30
                port = ":" gensub(";", "", "", $2)
31
                proto = gensub(";", "", "", $3) == "ssl" ? "https" : "http"
32
                pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/,"", "")
33
                if (proto == "https" && port == ":443") port = ""
34
            }
35
            if ($1 == "server_name") {
36
                server_name = gensub(";", "", "", $2)
37
                sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/,"", "")
38
            }
39
            if ($1 == "location" && sname != "" && pname != "" && sname == pname) {
40
                l=gensub(/^\s*location\s[^\/]*(\/.*)\{\s*#\s*monitoring\s+(.+)$/,"\\1,\\2", "")
41
                split(l, location, /\s*,\s*/)
42
                if (location[2] == sname) {
43
                    monitoring[location[2]][location[1]]["monitoring"] = location[3]
44
                    monitoring[location[2]][location[1]]["response_code"] = location[4]
45
                    monitoring[location[2]][location[1]]["url"] = proto "://" server_name port location[1] location[5]
46
                    if (location[6] != "")
47
                        monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq location[6] sq
48
                    else
49
                        monitoring[location[2]][location[1]]["user-agent"] = "--user-agent " sq "Mozilla/5 (monitoring)" sq
50
                }
51
            }
52
        }
53
        END {
54
            for (mid in monitoring) {
55
                for (locid in monitoring[mid]) {
56
                    curl = sprintf("curl --silent --max-time 2 --output /dev/null --write-out %{response_code} --output /dev/null %s %s",
57
                          monitoring[mid][locid]["user-agent"],
58
                          monitoring[mid][locid]["url"])
59
                    curl | getline response_code
60
                    close(curl)
ne considère pas le code ret...
Sébastien MARQUE authored on 2017-08-18
61
                    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
62
                        printf("%s (%s)\n", monitoring[mid][locid]["monitoring"], response_code)
63
                }
64
            }
65
        }
66
    ' /etc/nginx/sites-enabled/*
ajout du monitoring des diff...
Sébastien MARQUE authored on 2017-02-24
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) ))
73
    if test $step -gt 0; then
74
        step=$((step / 10000))
75
        test $step -le 3 || step=2
76
        echo "${level[step]}: température > $((min + step * 10))°"
77
    fi
78
}
79

            
80
function core_alim () {
81
    eval $(/opt/vc/bin/vcgencmd measure_volts core)
82
    test $volt == "1.2000V" || echo "$volt"
83
}
84

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

            
96
function mpd_tablette () {
97
    local tablette=192.168.0.53
98
    local port=6600
MPD remonte le montage NFS à...
Sébastien MARQUE authored on 2017-02-25
99
    local media='/media/musique'
rétabli test tablette
Sébastien MARQUE authored on 2017-08-18
100
    local nfs=$(ss -no state established 'sport = :nfs' dst $tablette | grep -c $)
101
    test $nfs -lt 2 && echo "tablette non connectée à la zique"
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
102
    nc -zw2 $tablette $port || echo "MPD injoignable"
correction typo
Sébastien MARQUE authored on 2017-02-25
103
    test $(showmount --all --no-headers | grep -c $tablette:$media) -eq 1 || echo "$media pas exporté"
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
104
}