remplacement de l'ancien arpwatch_sendmail

darcs-hash:20061005191217-f6463-9c2d7820b16e56b34d6da2a436b9631b8c2bb8bf.gz
This commit is contained in:
cohen 2006-10-05 21:12:17 +02:00
parent b6188a14d0
commit 1d71344ea9
2 changed files with 29 additions and 20 deletions

View file

@ -1,4 +1,4 @@
#!/bin/sh
#execution avec des droits suffisants
LANG=fr_FR@euro sudo -u '#120' /usr/scripts/surveillance/arpwatch_sendmail2.py $*
LANG=fr_FR@euro sudo -u '#120' /usr/scripts/surveillance/arpwatch_sendmail.py $*

View file

@ -8,27 +8,35 @@
import sys, os, sre, smtplib
from commands import getstatusoutput
sys.path.append('/usr/scripts/gestion')
from ldap_crans import crans_ldap
import whos
sys.path.append('/usr/scripts/gestion/tools')
import locate_mac
find_mac = sre.compile(r'[0-9A-Fa-f]{1,2}(?::[0-9A-Fa-f]{1,2}){5}')
def get_machine(mac):
commande = "/usr/scripts/gestion/whos.py --debug mac=%s" % mac
r, s = getstatusoutput(commande)
if r == 3:
# Aucun résultat trouvé
return ""
else:
# On supprime les couleurs
s = sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m', '', s)
# On rajoute éventuellement le code de retour
if r != 0:
s = """
Code de retour anormal : %d
Commande : %s
%s
""" % (r, commande, s)
else:
s = "\n" + s + "\n"
return s
def info_machine(mac):
s = u''
db = crans_ldap()
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
return s
def trace_machine(mac):
return locate_mac.get_trace(mac)
def get_machine(unformated_mac):
mac = locate_mac.format_mac(unformated_mac)
return "\n" + info_machine(mac) + trace_machine(mac) + "\n"
if __name__ == "__main__":
texte = sys.stdin.read()
@ -45,6 +53,7 @@ if __name__ == "__main__":
texte += '\n'
texte += '\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
texte += '\n-- \narpwatch_sendmail.py\n'
smtp = smtplib.SMTP()
smtp.connect()
smtp.sendmail("arpwatch@crans.org", recipients, texte)