From 95e2503320959c60c5a22bc77f94556cc4b9f532 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Mon, 15 Sep 2014 21:59:07 +0200 Subject: [PATCH] who2b: --warn-tpe => mail si tpe pas au 2B --- gestion/mail/template/missing_tpe/From/fr | 1 + gestion/mail/template/missing_tpe/README | 2 ++ gestion/mail/template/missing_tpe/Subject/fr | 1 + gestion/mail/template/missing_tpe/To/fr | 1 + gestion/mail/template/missing_tpe/X-Mailer/fr | 1 + gestion/mail/template/missing_tpe/body/fr | 11 +++++++++++ gestion/tools/who2b | 2 +- gestion/tools/who2b.py | 19 +++++++++++++++++-- 8 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 gestion/mail/template/missing_tpe/From/fr create mode 100644 gestion/mail/template/missing_tpe/README create mode 100644 gestion/mail/template/missing_tpe/Subject/fr create mode 100644 gestion/mail/template/missing_tpe/To/fr create mode 100644 gestion/mail/template/missing_tpe/X-Mailer/fr create mode 100644 gestion/mail/template/missing_tpe/body/fr diff --git a/gestion/mail/template/missing_tpe/From/fr b/gestion/mail/template/missing_tpe/From/fr new file mode 100644 index 00000000..504e62a8 --- /dev/null +++ b/gestion/mail/template/missing_tpe/From/fr @@ -0,0 +1 @@ +respbats@crans.org diff --git a/gestion/mail/template/missing_tpe/README b/gestion/mail/template/missing_tpe/README new file mode 100644 index 00000000..a407dc23 --- /dev/null +++ b/gestion/mail/template/missing_tpe/README @@ -0,0 +1,2 @@ +Envoyé si le tpe n'est pas branché au 2B. Appelé par un cron à des horaires +où il est censé s'y trouver. diff --git a/gestion/mail/template/missing_tpe/Subject/fr b/gestion/mail/template/missing_tpe/Subject/fr new file mode 100644 index 00000000..7a014ec5 --- /dev/null +++ b/gestion/mail/template/missing_tpe/Subject/fr @@ -0,0 +1 @@ +Le TPE n'est pas revenu au 2B ! diff --git a/gestion/mail/template/missing_tpe/To/fr b/gestion/mail/template/missing_tpe/To/fr new file mode 100644 index 00000000..e6199f75 --- /dev/null +++ b/gestion/mail/template/missing_tpe/To/fr @@ -0,0 +1 @@ +{{to}} diff --git a/gestion/mail/template/missing_tpe/X-Mailer/fr b/gestion/mail/template/missing_tpe/X-Mailer/fr new file mode 100644 index 00000000..f5d9c869 --- /dev/null +++ b/gestion/mail/template/missing_tpe/X-Mailer/fr @@ -0,0 +1 @@ +{{ mailer }} diff --git a/gestion/mail/template/missing_tpe/body/fr b/gestion/mail/template/missing_tpe/body/fr new file mode 100644 index 00000000..7ad19b13 --- /dev/null +++ b/gestion/mail/template/missing_tpe/body/fr @@ -0,0 +1,11 @@ +Bonjour, + +Ce mail automatique signale l'absence du terminal bancaire. La permanence Crans +étant terminée, le terminal devrait normalement se trouver au 2B. Si le +terminal s'y trouve, merci de le brancher au réseau. + +L'état de connectivité du terminal est disponible sur la page d'autostatus : +http://autostatus.crans.org + +-- +who2b diff --git a/gestion/tools/who2b b/gestion/tools/who2b index e68eb233..06de234c 100755 --- a/gestion/tools/who2b +++ b/gestion/tools/who2b @@ -5,4 +5,4 @@ if [ `hostname` != "vo" ]; then exit 1 fi -sudo -u root /usr/scripts/gestion/tools/who2b.py +sudo -u root /usr/scripts/gestion/tools/who2b.py "$@" diff --git a/gestion/tools/who2b.py b/gestion/tools/who2b.py index 957b51ec..e265f0e6 100755 --- a/gestion/tools/who2b.py +++ b/gestion/tools/who2b.py @@ -11,8 +11,15 @@ from affich_tools import coul, cprint from whos import aff from socket import gethostname from os import system +from gestion.mail import generate +from utils.sendmail import actually_sendmail -def liste_2b(): +def missing_tpe(): + dst = 'respbats@crans.org' + mail = generate('missing_tpe', {'to': dst}) + actually_sendmail('respbats@crans.org', [dst], mail) + +def liste_2b(warn_mail=[]): '''Cette fonction permet de savoir s'il y a du monde au 2B.''' sw = hpswitch('backbone.adm') @@ -34,6 +41,7 @@ def liste_2b(): "00:1c:2e:56:1a:20": "minigiga (switch)", "00:40:8c:7f:4a:b5": "tinybrother", "00:24:8c:44:3b:70": "vo", + "54:7f:54:77:ca:be": "terminal", } # Machines branchée sur la prise @@ -65,6 +73,9 @@ def liste_2b(): for expectedMac in expected.iterkeys(): if expectedMac not in macs: cprint("Machine %s manquante !" % expected[expectedMac], 'rouge') + if expected[expectedMac] in warn_mail: + missing_tpe() + print("envoi d'un mail") # Affichage des machines cprint('---=== Machines du Crans ===---', 'bleu') aff(machines_crans, mtech=True) @@ -85,4 +96,8 @@ def liste_2b(): cprint("---=== Il semble n'y avoir personne au 2B ... ===---", 'rouge') if __name__ == '__main__': - liste_2b() + if '--warn-tpe' in sys.argv: + liste_2b(warn_mail=["terminal"]) + else: + liste_2b() +