diff --git a/gestion/spam_cablages.py b/gestion/spam_cablages.py new file mode 100755 index 00000000..d24d1898 --- /dev/null +++ b/gestion/spam_cablages.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -!- encoding: utf-8 -!- +# SPAM_CABLAGES.PY -- Spamme respbats pour rappeler les cablages a effectuer + +import psycopg2 +from collections import defaultdict + +TEMPLATE = u""" +Cablages a effectuer : +%(cablages)s +--\u0020 +L'intranet du Cr@ns""" + +TEMPLATE_BATIMENT = u""" +Batiment %(batiment)s +%(prises)s""" + +def get_cablages(): + """Recupere la liste des cablages a effectuer""" + conn = psycopg2.connect("user=crans dbname=switchs host=pgsql.adm.crans.org") + cur = conn.cursor() + cur.execute("SELECT batiment, chambre, prise_crans FROM prises WHERE cablage_effectue = FALSE") + res = defaultdict(list) + for batiment, chambre, prise_crans in cur.fetchall(): + res[batiment].append(chambre) + + return res + +CABLAGES = get_cablages() + +if not CABLAGES: + exit(1) + +CORPS_BATIMENTS = [] + +for batiment in sorted(CABLAGES.keys()): + ubatiment = batiment.upper() + prises = ", ".join(["%s%s" % (ubatiment, chambre) for chambre in sorted(CABLAGES[batiment])]) + CORPS_BATIMENTS.append(TEMPLATE_BATIMENT % { "prises": prises, "batiment": ubatiment }) + +print (TEMPLATE % { "cablages": "".join(CORPS_BATIMENTS) }) diff --git a/gestion/spam_cablages.sh b/gestion/spam_cablages.sh new file mode 100755 index 00000000..c36341c0 --- /dev/null +++ b/gestion/spam_cablages.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if /usr/scripts/gestion/spam_cablages.py &> /dev/null; then + /usr/scripts/gestion/spam_cablages.py | mail \ + -a "X-Crans-Intranet: cablage" \ + -a "From: \"L'intranet du Cr@ns\" " \ + -s "[Câblage] Résumé des câblages à effectuer" respbats@crans.org +fi