des version avec thread (pour acclerer l'interrogation) se trouvent dans tools
darcs-hash:20050411210850-4ec08-141998e529597711cd1692169bf2d3ee31678a6a.gz
This commit is contained in:
parent
477219f2ed
commit
ec0e96fbfd
2 changed files with 0 additions and 105 deletions
|
@ -1,21 +0,0 @@
|
||||||
#! /usr/bin/env python
|
|
||||||
# -*- coding: iso-8859-15 -*-
|
|
||||||
# Localise une adresse MAC sur les différents switchs
|
|
||||||
|
|
||||||
from annuaires import reverse, all_switchs
|
|
||||||
from hptools import hpswitch
|
|
||||||
from sys import argv
|
|
||||||
from os import system
|
|
||||||
|
|
||||||
mac = ":".join([i.zfill(2) for i in argv[1].split(":")]).lower()
|
|
||||||
|
|
||||||
for switch in ['backbone'] + all_switchs():
|
|
||||||
sw = hpswitch(switch)
|
|
||||||
prise = sw.where_is_mac(mac)
|
|
||||||
if prise != None:
|
|
||||||
print "%-10s: %d (%s)" % (switch, prise, sw.nom(None, prise))
|
|
||||||
else:
|
|
||||||
print "%-10s: non trouvé" % switch
|
|
||||||
|
|
||||||
system("whos mac=%s" % mac)
|
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
#! /usr/bin/env python
|
|
||||||
# -*- coding: iso-8859-15 -*-
|
|
||||||
|
|
||||||
import sys
|
|
||||||
sys.path.append('/usr/scripts/gestion')
|
|
||||||
from whos import borne_clients, borne_etat
|
|
||||||
from ldap_crans import crans_ldap
|
|
||||||
from time import sleep
|
|
||||||
from affich_tools import coul
|
|
||||||
import threading
|
|
||||||
from os import getuid
|
|
||||||
|
|
||||||
# il faut être root
|
|
||||||
if getuid() :
|
|
||||||
print 'Il faut être root !'
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# connexion à la base de données
|
|
||||||
db = crans_ldap()
|
|
||||||
|
|
||||||
# décompostion des arguments
|
|
||||||
try :
|
|
||||||
mac = ":".join([i.zfill(2) for i in sys.argv[1].split(":")]).upper()
|
|
||||||
except :
|
|
||||||
mac = None
|
|
||||||
|
|
||||||
# dit si une mac a déja été traitée
|
|
||||||
mac_done=[]
|
|
||||||
def done (mac) :
|
|
||||||
global mac_done
|
|
||||||
if mac in mac_done :
|
|
||||||
return True
|
|
||||||
else :
|
|
||||||
mac_done.append(mac)
|
|
||||||
return False
|
|
||||||
|
|
||||||
# classe d'interrogation des bornes
|
|
||||||
class interroge_borne (threading.Thread) :
|
|
||||||
def __init__ (self, db, borne, mac = None) :
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
self.borne = borne
|
|
||||||
self.mac = mac
|
|
||||||
self.db = db
|
|
||||||
self.start()
|
|
||||||
|
|
||||||
def aff_client (self, mac, rssi) :
|
|
||||||
if done(mac) :
|
|
||||||
return
|
|
||||||
|
|
||||||
res = db.search("mac=%s" % mac)['machine']
|
|
||||||
if not res:
|
|
||||||
client_nom = '????'
|
|
||||||
coul_rssi = 'rouge'
|
|
||||||
rssi = 0
|
|
||||||
else:
|
|
||||||
# On va choisir la bonne couleur pour le RSSI
|
|
||||||
if rssi > -77:
|
|
||||||
coul_rssi = 'vert'
|
|
||||||
elif rssi > -90:
|
|
||||||
coul_rssi = 'jaune'
|
|
||||||
else:
|
|
||||||
coul_rssi = 'rouge'
|
|
||||||
print '%-10s %-30s (%-15s, RSSI: %s)' % (self.borne.nom().split('.')[0], res[0].proprietaire().Nom(), res[0].nom().split('.')[0],coul("%d" % rssi, coul_rssi))
|
|
||||||
|
|
||||||
def run (self) :
|
|
||||||
nom = self.borne.nom()
|
|
||||||
if not borne_etat(nom) :
|
|
||||||
return
|
|
||||||
clients = borne_clients(nom)
|
|
||||||
for (mac, rssi) in clients :
|
|
||||||
if not self.mac or self.mac == mac.lower() :
|
|
||||||
self.aff_client(mac,rssi)
|
|
||||||
|
|
||||||
# on onterroge trois fois car il donne pas toujours les clients
|
|
||||||
for i in range(0,3) :
|
|
||||||
# on interroge les bornes
|
|
||||||
resultat = {}
|
|
||||||
bornes = db.search('canal=*')['machine']
|
|
||||||
for borne in bornes :
|
|
||||||
interroge_borne(db, borne, mac)
|
|
||||||
|
|
||||||
# on attend la fin de threads
|
|
||||||
while len(threading.enumerate()) > 1 :
|
|
||||||
sleep(1)
|
|
Loading…
Add table
Add a link
Reference in a new issue