apps / sms / bot.monitoring /
Newer Older
82 lines | 2.215kb
supervision du service de SM...
Sébastien authored on 2022-06-03
1
#!/bin/bash
2

            
bloque la supervision pendan...
Sébastien authored on 2022-08-20
3
if test -e /dev/shm/smsbot.envoi_en_cours; then
4
    rm -f /dev/shm/smsbot.envoi.ok /dev/shm/smsbot.reception.ok
5
    exit
6
fi
supervision du service de SM...
Sébastien authored on 2022-06-03
7

            
8
eval $(systemctl show smsbot --property=ActiveState)
9
test -n "$ActiveState" && test "$ActiveState" = 'active' || exit 1
10

            
11
NOW=$(date +%s)
12

            
13
/usr/local/bin/smsapi "supervision réception" || exit 2
14
        
15
function test_reception () {
16
    flag=0
17
    for i in $(seq ${2:-180}); do
18
        sleep ${3:-10}
19
        if test -e "$1"; then
20
            reception=$(stat -c %Y "$1")
21
            test $reception -gt $NOW && flag=1 && break
22
        fi
23
    done
24
    test $flag -ne 0
25
}
26

            
27
function hilink () {
28
    perl -e '
29
        use HiPi qw( :hilink );
30
        use Encode qw(encode decode);
31
        use HiPi::Huawei::E3531;
32
        my $hlink = HiPi::Huawei::E3531->new();
33
        my $reponse = $hlink->get_'$1'();
34
        print "$reponse->{Count}\n";
35
        for ($i = $reponse->{Count} - 1; $i >= 0; $i--) {
36
            my $msg = $reponse->{Messages}[$i];
37
            foreach my $k (keys(%$msg)) {
38
                if ($k == "Content") {
39
                    $msg->{$k} = encode("utf8", $msg->{$k});
40
                }
41
                print "$k: $msg->{$k}\n";
42
            }
43
            print "\n";
44
        }
45
    '
46
}
47

            
48
function device_reboot () {
49
    perl -e '
50
        use HiPi qw( :hilink );
51
        use Encode qw(encode decode);
52
        use HiPi::Huawei::E3531;
53
        my $hlink = HiPi::Huawei::E3531->new();
54
        my $reponse = $hlink->device_reboot();
55
    '
56
}
57

            
58
if ! test_reception /dev/shm/smsbot.reception.ok; then
59
    msg='problème de réception'
60
elif ! test_reception /dev/shm/smsbot.envoi.ok; then
61
    msg="problème d'envoi"
62
fi
63

            
64
if test -n "$msg"; then
65
    msmtp contact@paris12.pcf.fr << EOM
66
Subject: SMSBOT $msg
67

            
68
$(systemctl status smsbot)
69

            
70
INBOX:
71
$(hilink inbox)
72

            
73
OUTBOX:
74
$(hilink outbox)
75

            
76
JOURNAL:
77
$(sudo /bin/journalctl -u smsbot | tail)
78

            
79
$(if test "$msg" = "problème d'envoi"; then sudo /bin/systemctl restart smsbot && echo "smsbot relancé" || echo "erreur $?"; fi)
80
$(if test "$msg" = "problème de réception"; then sudo /bin/systemctl stop smsbot && device_reboot && sleep 30 && sudo /bin/systemctl start smsbot && echo "device rebooté" || echo "erreur $?"; fi)
81
EOM
82
fi