On ajoute des whos aux mails d'arpwatch.
darcs-hash:20060403021708-68412-466ea7dafa8928bf68c8f44c438b360173657b6e.gz
This commit is contained in:
parent
f7eba944d7
commit
4da729bd16
1 changed files with 37 additions and 0 deletions
37
surveillance/arpwatch_sendmail.py
Executable file
37
surveillance/arpwatch_sendmail.py
Executable file
|
@ -0,0 +1,37 @@
|
|||
#! /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()
|
Loading…
Add table
Add a link
Reference in a new issue