Formatage a la whos

darcs-hash:20061007014122-f6463-b11ff66df90af6a84d9e8ca8e864ab24e1f99ff1.gz
This commit is contained in:
cohen 2006-10-07 03:41:22 +02:00
parent 465a512248
commit 92990afeb7

View file

@ -1,8 +1,8 @@
#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Ajout d'un whos aux mails d'arpwatch
# Auteur : Stéphane Glondu
# Ajout d'un whos et d'un tracage aux mails d'arpwatch
# Auteurs : Stéphane Glondu, Cyril Cohen
# Licence : GPLv2
import sys, os, sre, smtplib
@ -23,12 +23,17 @@ def info_machine(mac):
machines = db.search("mac=%s" % mac)['machine']
for m in machines:
adh = m.proprietaire()
r = u"""
Recherche LDAP sur la MAC %(mac)s :
Nom de machine : %(nomMach)s , IP : %(ip)s, Prise : %(prise)s
Proprietaire : %(nomAdh)s, chambre %(chbre)s
""" % { "mac":mac, "nomMach":m.nom(), "ip":m.ip(), "prise":m.prise(),"nomAdh":adh.Nom(), "chbre":adh.chbre()}
s += r
r = whos.machine_details(m)
# On supprime les couleurs
r = sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m', '', r)
s += r
if len(machines)==0 :
s += u"""
Recherche LDAP sur la MAC %s : aucune machine trouvee
""" % mac
return s
def trace_machine(mac):
@ -50,11 +55,11 @@ if __name__ == "__main__":
except:
# En cas d'exception, on envoie le traceback
import traceback
texte += '\n'
texte += '\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
texte += '\n-- \narpwatch_sendmail.py\n'
texte += u'\n'
texte += u'\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
texte += u'\n-- \narpwatch_sendmail.py\n'
smtp = smtplib.SMTP()
smtp.connect()
smtp.sendmail("arpwatch@crans.org", recipients, texte)
smtp.sendmail("arpwatch@crans.org", recipients, texte.encode('latin1'))
smtp.quit()