remplacement de l'ancien arpwatch_sendmail
darcs-hash:20061005191217-f6463-9c2d7820b16e56b34d6da2a436b9631b8c2bb8bf.gz
This commit is contained in:
parent
b6188a14d0
commit
1d71344ea9
2 changed files with 29 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#execution avec des droits suffisants
|
#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 $*
|
||||||
|
|
|
@ -8,27 +8,35 @@
|
||||||
import sys, os, sre, smtplib
|
import sys, os, sre, smtplib
|
||||||
from commands import getstatusoutput
|
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}')
|
find_mac = sre.compile(r'[0-9A-Fa-f]{1,2}(?::[0-9A-Fa-f]{1,2}){5}')
|
||||||
|
|
||||||
def get_machine(mac):
|
def info_machine(mac):
|
||||||
commande = "/usr/scripts/gestion/whos.py --debug mac=%s" % mac
|
s = u''
|
||||||
r, s = getstatusoutput(commande)
|
db = crans_ldap()
|
||||||
if r == 3:
|
machines = db.search("mac=%s" % mac)['machine']
|
||||||
# Aucun résultat trouvé
|
for m in machines:
|
||||||
return ""
|
adh = m.proprietaire()
|
||||||
else:
|
r = u"""
|
||||||
# On supprime les couleurs
|
Recherche LDAP sur la MAC %(mac)s :
|
||||||
s = sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m', '', s)
|
Nom de machine : %(nomMach)s , IP : %(ip)s, Prise : %(prise)s
|
||||||
# On rajoute éventuellement le code de retour
|
Proprietaire : %(nomAdh)s, chambre %(chbre)s
|
||||||
if r != 0:
|
""" % { "mac":mac, "nomMach":m.nom(), "ip":m.ip(), "prise":m.prise(),"nomAdh":adh.Nom(), "chbre":adh.chbre()}
|
||||||
s = """
|
s += r
|
||||||
Code de retour anormal : %d
|
return s
|
||||||
Commande : %s
|
|
||||||
%s
|
def trace_machine(mac):
|
||||||
""" % (r, commande, s)
|
return locate_mac.get_trace(mac)
|
||||||
else:
|
|
||||||
s = "\n" + s + "\n"
|
def get_machine(unformated_mac):
|
||||||
return s
|
mac = locate_mac.format_mac(unformated_mac)
|
||||||
|
return "\n" + info_machine(mac) + trace_machine(mac) + "\n"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
texte = sys.stdin.read()
|
texte = sys.stdin.read()
|
||||||
|
@ -45,6 +53,7 @@ if __name__ == "__main__":
|
||||||
texte += '\n'
|
texte += '\n'
|
||||||
texte += '\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
texte += '\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
||||||
texte += '\n-- \narpwatch_sendmail.py\n'
|
texte += '\n-- \narpwatch_sendmail.py\n'
|
||||||
|
|
||||||
smtp = smtplib.SMTP()
|
smtp = smtplib.SMTP()
|
||||||
smtp.connect()
|
smtp.connect()
|
||||||
smtp.sendmail("arpwatch@crans.org", recipients, texte)
|
smtp.sendmail("arpwatch@crans.org", recipients, texte)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue