scripts / monitoring.d / raspberrypi /
Newer Older
99 lines | 4.038kb
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") {
25
                port = ":" gensub(";", "", "", $2)
26
                proto = gensub(";", "", "", $3) == "ssl" ? "https" : "http"
27
                pname = gensub(/^\s*listen\s.+#\s*monitoring\s+/,"", "")
28
                if (proto == "https" && port == ":443") port = ""
29
            }
30
            if ($1 == "server_name") {
31
                server_name = gensub(";", "", "", $2)
32
                sname = gensub(/^\s*server_name\s.+#\s*monitoring\s+/,"", "")
33
            }
34
            if ($1 == "location" && sname != "" && pname != "" && sname == pname) {
35
                l=gensub(/^\s*location\s[^\/]*(\/.*)\{\s*#\s*monitoring\s+(.+)$/,"\\1,\\2", "")
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) ))
68
    if test $step -gt 0; then
69
        step=$((step / 10000))
70
        test $step -le 3 || step=2
71
        echo "${level[step]}: température > $((min + step * 10))°"
72
    fi
73
}
74

            
75
function core_alim () {
76
    eval $(/opt/vc/bin/vcgencmd measure_volts core)
77
    test $volt == "1.2000V" || echo "$volt"
78
}
79

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

            
91
function mpd_tablette () {
92
    local tablette=192.168.0.53
93
    local port=6600
MPD remonte le montage NFS à...
Sébastien MARQUE authored on 2017-02-25
94
    local media='/media/musique'
rétabli test tablette
Sébastien MARQUE authored on 2017-08-18
95
    local nfs=$(ss -no state established 'sport = :nfs' dst $tablette | grep -c $)
96
    test $nfs -lt 2 && echo "tablette non connectée à la zique"
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
97
    nc -zw2 $tablette $port || echo "MPD injoignable"
correction typo
Sébastien MARQUE authored on 2017-02-25
98
    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
99
}