scripts/surveillance/arpwatch_sendmail.py
glondu 4da729bd16 On ajoute des whos aux mails d'arpwatch.
darcs-hash:20060403021708-68412-466ea7dafa8928bf68c8f44c438b360173657b6e.gz
2006-04-03 04:17:08 +02:00

37 lines
1.1 KiB
Python
Executable file

#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Ajout d'un whos aux mails d'arpwatch
# Auteur : Stéphane Glondu
# Licence : GPLv2
import sys, os, sre, smtplib
find_mac = sre.compile(r'[0-9A-Fa-f]{1,2}(?::[0-9A-Fa-f]{1,2}){5}')
def get_machine(mac):
s = os.popen("sudo /usr/scripts/gestion/whos.py mac=%s" % mac).readlines()
if len(s) == 1:
return ""
else:
# On supprime la première ligne et les couleurs
s = "\n" + "".join(s[1:])
s = sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m', '', s)
return s
if __name__ == "__main__":
texte = sys.stdin.read()
try:
macs = find_mac.findall(texte)
for mac in macs:
texte += get_machine(mac)
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))
test += '\n-- \narpwatch_sendmail.py\n'
smtp = smtplib.SMTP()
smtp.connect()
smtp.sendmail("arpwatch@crans.org", "root@crans.org", texte)
smtp.quit()