[mac_prises] En place, avec script d'analyse.
Je commence à en avoir marre des gens qui spoofent. J'ai donc pris en charge l'écriture de mac_prises cette nuit. Je le mets en test vers la mailing list test@lists.crans.org, avis aux amateurs.
This commit is contained in:
parent
baf4aa3645
commit
df49d0b6dc
6 changed files with 305 additions and 90 deletions
54
surveillance/mac_prises/mac_prise_holder.py
Executable file
54
surveillance/mac_prises/mac_prise_holder.py
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
import sys
|
||||
import psycopg2
|
||||
import mac_prise
|
||||
from threading import Thread
|
||||
import time
|
||||
|
||||
class ThreadWithReturnValue(Thread):
|
||||
"""
|
||||
Classe de threading qui récupère le "return" d'une fonction, et le renvoie avec
|
||||
output()
|
||||
"""
|
||||
def __init__(self, group=None, target=None, name=None,
|
||||
args=(), kwargs={}, Verbose=None):
|
||||
Thread.__init__(self, group, target, name, args, kwargs, Verbose)
|
||||
self._return = None
|
||||
|
||||
def run(self):
|
||||
if self._Thread__target is not None:
|
||||
self._return = self._Thread__target(*self._Thread__args,
|
||||
**self._Thread__kwargs)
|
||||
def output(self):
|
||||
Thread.join(self)
|
||||
return self._return
|
||||
|
||||
if __name__ == '__main__':
|
||||
"""
|
||||
On envoie sur n threads les n arguments, puis on récupère les sorties
|
||||
et on les enregistre dans une base postgresql
|
||||
"""
|
||||
switches = sys.argv[1:]
|
||||
date = time.strftime('%F %T')
|
||||
threads = {}
|
||||
output = {}
|
||||
for switch in switches:
|
||||
threads[switch] = ThreadWithReturnValue(target=mac_prise.liste_chambres_macs, args=(switch,))
|
||||
threads[switch].start()
|
||||
|
||||
# On change de boucle, car il faut absolument que tous les threads aient démarré, histoire qu'on
|
||||
# parallélise vraiment !
|
||||
for switch in switches:
|
||||
output[switch] = threads[switch].output()
|
||||
connecteur = psycopg2.connect(database="mac_prises", user="crans")
|
||||
connecteur.set_session(autocommit=True)
|
||||
curseur = connecteur.cursor()
|
||||
|
||||
requete = "INSERT INTO correspondance (date, chambre, mac) VALUES (%s, %s, %s);"
|
||||
|
||||
for switch in output:
|
||||
for chambre in output[switch]:
|
||||
for mac in output[switch][chambre]:
|
||||
curseur.execute(requete, (date, chambre, mac))
|
Loading…
Add table
Add a link
Reference in a new issue