... | ... |
@@ -229,6 +229,17 @@ sub inbox_sms_parse { |
229 | 229 |
$cfg::user{"message pour un destinataire"} => sub { |
230 | 230 |
$outbox_sms_queue->enqueue([$1, $msg->{Content}]); |
231 | 231 |
}, |
232 |
+ $cfg::user{"supervision"} => sub { |
|
233 |
+ if ($1 eq 'réception') { |
|
234 |
+ $outbox_sms_queue->insert(0, [$msg->{Phone}, "supervision envoi"]); |
|
235 |
+ open my $fh, '>', '/dev/shm/smsbot.reception.ok'; |
|
236 |
+ close $fh; |
|
237 |
+ } |
|
238 |
+ elsif ($1 eq 'envoi') { |
|
239 |
+ open my $fh, '>', '/dev/shm/smsbot.envoi.ok'; |
|
240 |
+ close $fh; |
|
241 |
+ } |
|
242 |
+ }, |
|
232 | 243 |
$cfg::user{"ping"} => sub { |
233 | 244 |
my $envoi_en_cours = ''; |
234 | 245 |
if ($outbox_sms_queue->pending() > 0) { |
... | ... |
@@ -0,0 +1,78 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+ |
|
4 |
+eval $(systemctl show smsbot --property=ActiveState) |
|
5 |
+test -n "$ActiveState" && test "$ActiveState" = 'active' || exit 1 |
|
6 |
+ |
|
7 |
+NOW=$(date +%s) |
|
8 |
+ |
|
9 |
+/usr/local/bin/smsapi "supervision réception" || exit 2 |
|
10 |
+ |
|
11 |
+function test_reception () { |
|
12 |
+ flag=0 |
|
13 |
+ for i in $(seq ${2:-180}); do |
|
14 |
+ sleep ${3:-10} |
|
15 |
+ if test -e "$1"; then |
|
16 |
+ reception=$(stat -c %Y "$1") |
|
17 |
+ test $reception -gt $NOW && flag=1 && break |
|
18 |
+ fi |
|
19 |
+ done |
|
20 |
+ test $flag -ne 0 |
|
21 |
+} |
|
22 |
+ |
|
23 |
+function hilink () { |
|
24 |
+ perl -e ' |
|
25 |
+ use HiPi qw( :hilink ); |
|
26 |
+ use Encode qw(encode decode); |
|
27 |
+ use HiPi::Huawei::E3531; |
|
28 |
+ my $hlink = HiPi::Huawei::E3531->new(); |
|
29 |
+ my $reponse = $hlink->get_'$1'(); |
|
30 |
+ print "$reponse->{Count}\n"; |
|
31 |
+ for ($i = $reponse->{Count} - 1; $i >= 0; $i--) { |
|
32 |
+ my $msg = $reponse->{Messages}[$i]; |
|
33 |
+ foreach my $k (keys(%$msg)) { |
|
34 |
+ if ($k == "Content") { |
|
35 |
+ $msg->{$k} = encode("utf8", $msg->{$k}); |
|
36 |
+ } |
|
37 |
+ print "$k: $msg->{$k}\n"; |
|
38 |
+ } |
|
39 |
+ print "\n"; |
|
40 |
+ } |
|
41 |
+ ' |
|
42 |
+} |
|
43 |
+ |
|
44 |
+function device_reboot () { |
|
45 |
+ perl -e ' |
|
46 |
+ use HiPi qw( :hilink ); |
|
47 |
+ use Encode qw(encode decode); |
|
48 |
+ use HiPi::Huawei::E3531; |
|
49 |
+ my $hlink = HiPi::Huawei::E3531->new(); |
|
50 |
+ my $reponse = $hlink->device_reboot(); |
|
51 |
+ ' |
|
52 |
+} |
|
53 |
+ |
|
54 |
+if ! test_reception /dev/shm/smsbot.reception.ok; then |
|
55 |
+ msg='problème de réception' |
|
56 |
+elif ! test_reception /dev/shm/smsbot.envoi.ok; then |
|
57 |
+ msg="problème d'envoi" |
|
58 |
+fi |
|
59 |
+ |
|
60 |
+if test -n "$msg"; then |
|
61 |
+ msmtp contact@paris12.pcf.fr << EOM |
|
62 |
+Subject: SMSBOT $msg |
|
63 |
+ |
|
64 |
+$(systemctl status smsbot) |
|
65 |
+ |
|
66 |
+INBOX: |
|
67 |
+$(hilink inbox) |
|
68 |
+ |
|
69 |
+OUTBOX: |
|
70 |
+$(hilink outbox) |
|
71 |
+ |
|
72 |
+JOURNAL: |
|
73 |
+$(sudo /bin/journalctl -u smsbot | tail) |
|
74 |
+ |
|
75 |
+$(if test "$msg" = "problème d'envoi"; then sudo /bin/systemctl restart smsbot && echo "smsbot relancé" || echo "erreur $?"; fi) |
|
76 |
+$(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) |
|
77 |
+EOM |
|
78 |
+fi |