scripts / monitoring.d / raspberrypi /
Newer Older
100 lines | 4.012kb
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 () {
11
    nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888"
12
}
13

            
14
function gitprep () {
15
    nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020"
16
}
17

            
18
function cherrymusic () {
19
    nc -zw2 127.0.0.1 8080 || echo "injoignable sur port 8080"
20
}
21

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

            
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
65
function core_temp () {
66
    local min=60
67
    local level=("warning" "severe" "danger!")
68
    local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) ))
69
    if test $step -gt 0; then
70
        step=$((step / 10000))
71
        test $step -le 3 || step=2
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)
78
    test $volt == "1.2000V" || echo "$volt"
79
}
80

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

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