From 64988d2741de567481a90ba88e150400abf5f253 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Thu, 21 Jun 2012 11:08:09 +0200 Subject: [PATCH] [spam_cablage] ajout des fichiers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore-this: 9183ae6f46f7952242e55c6cf2d6e4c8 Ajout au dépot des deux scripts de rappel des câblages à effectuer. darcs-hash:20120621090809-28565-528cb9e0ea29b5cfe93c5a6aa556718a10c312e9.gz --- gestion/spam_cablages.py | 41 ++++++++++++++++++++++++++++++++++++++++ gestion/spam_cablages.sh | 8 ++++++++ 2 files changed, 49 insertions(+) create mode 100755 gestion/spam_cablages.py create mode 100755 gestion/spam_cablages.sh 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