diff --git a/surveillance/arpwatch_sendmail b/surveillance/arpwatch_sendmail index 9d0570b0..3274c14e 100755 --- a/surveillance/arpwatch_sendmail +++ b/surveillance/arpwatch_sendmail @@ -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 $* diff --git a/surveillance/arpwatch_sendmail.py b/surveillance/arpwatch_sendmail.py index 092c4f4a..d2f6b07f 100755 --- a/surveillance/arpwatch_sendmail.py +++ b/surveillance/arpwatch_sendmail.py @@ -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)