scripts / supervision.d / common-tests /
Newer Older
48 lines | 1.755kb
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
1
# vim: ft=sh
2

            
3
function _systemctl () {
4
    test -n "$1" || return
5
    eval $(systemctl show $1 | egrep '^(ExecMainStatus|Result|ActiveState|SubState|Type)=')
6
    if test -n "$Type"; then
7
           test $ExecMainStatus -eq 0 \
8
        && test $Result = 'success' \
9
        && test $ActiveState = 'active' \
10
        && [[ ( $Type =~ ^(simple|forking|notify)$ && $SubState = 'running' ) || ( $Type = 'oneshot' && $SubState = 'exited' ) ]] \
11
        || echo "état du service anormal"
12
    else
13
        echo "service $1 inexistant"
14
    fi
15
}
16

            
17
function sys_state () {
18
    local failed_units=
19
    eval $(systemctl show | egrep '^(SystemState|NFailedUnits)=')
20
    if test $SystemState != "running" -o $NFailedUnits -ne 0; then
21
        msg="$SystemState mode ($NFailedUnits units failed):%0a"
22
        msg+=$(systemctl --failed --no-legend | awk '
23
            {
24
                split($1, units, ".")
25
                failed[units[2]][units[1]]=1
26
                numfailed[units[2]]++
27
            }
28
            END {
29
                for (ut in failed) { 
30
                    printf("%s%%0a", ut)
31
                    for (un in failed[ut]) {
32
                        last = --numfailed[ut] == 0 ? 1 : 0
33
                        printf("%s %s%s", last ? "└─" : "├─", un, last ? "" : "%0a")
34
                    }
35
                }
36
            }')
37
    fi
38
}
ajout d'un test de mise à jo...
Sébastien MARQUE authored on 2017-02-22
39

            
40
function upgrades () {
41
    local log="/var/log/unattended-upgrades/unattended-upgrades.log"
42
    test -r $log || return
43
    local lastline=$(tail -1 $log)
44
    local lastentry=$(date +%s -d "$(cut -f1,2 -d' ' <<< $lastline)")
45
    test -n "$lastentry" || return
46
    local status=$(cut -f3 -d' ' <<< $lastline)
fix typo dans le test d'upgr...
Sébastien MARQUE authored on 2017-02-22
47
    test $(($lastentry + 86400)) -lt $now && echo "pas de mise à jour depuis le ${lastline%% *}"
ajout d'un test de mise à jo...
Sébastien MARQUE authored on 2017-02-22
48
}