From 6ac3eead1b48daf73e2cf47168261dbcfdbac5af Mon Sep 17 00:00:00 2001 From: bernat Date: Tue, 5 Oct 2004 11:02:46 +0200 Subject: [PATCH] Ajout d'un statut des bornes : whos -b permet d'avoir un autostatut darcs-hash:20041005090246-d1718-8bdf41c1444b59615bafedf60c3c5adeebb3f6e5.gz --- gestion/whos.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/gestion/whos.py b/gestion/whos.py index cd4620ce..85b9b700 100755 --- a/gestion/whos.py +++ b/gestion/whos.py @@ -228,12 +228,15 @@ def list_bornes(bornes) : * nom * adresse IP * adresse MAC + * État * puissance * canal * lieu (la première remarque en fait) """ - data = [ ( u'mid' , u'Nom', u'Adresse IP', u'Adresse MAC', u'C' , u'P', u'Lieu') ] + data = [ ( u'mid' , u'Nom', u'Adresse IP', u'Adresse MAC', u'E', u'C' , u'P', u'Lieu') ] + ok = u'\x1b[1;32mu\x1b[1;0m' + nok = u'\x1b[1;31md\x1b[1;0m' for b in bornes : t, bl = __bases_machines(b) if t != 'born' : continue @@ -243,9 +246,13 @@ def list_bornes(bornes) : l = b.info()[0] except : l = u'????' - data.append((b.id() , b.nom().split('.')[0], b.ip(), b.mac(), b.canal(), b.puissance(),l )) + if borne_etat(b.nom()): + etat = ok + else: + etat = nok + data.append((b.id() , b.nom().split('.')[0], b.ip(), b.mac(), etat, b.canal(), b.puissance(),l )) - return u"C=canal, P=puissance\n" + tableau([5, 14, 17, 19, 2, 2, '*'], data) + return u"C=canal, P=puissance, E=état\n" + tableau([5, 14, 17, 17, 1, 2, 2, '*'], data) def adher_details(adher) : """ @@ -408,7 +415,12 @@ def machine_details(machine) : # Borne wifi if machine.puissance() : f += coul(u'Puissance : ','gras') + machine.puissance() - f += coul(u'\tCanal : ', 'gras') + machine.canal() + f += coul(u'\tCanal : ', 'gras') + machine.canal() + f += coul(u'\tÉtat : ', 'gras') + if borne_etat(machine.nom()): + f += coul(u'borne active', 'vert') + else: + f += coul(u'borne éteinte','rouge') f += '\n' if aff_ipsec and machine.ipsec() : @@ -552,6 +564,17 @@ def __bases_machines(m) : return t , bl +def borne_etat(borne) : + """Renvoie vrai si la borne est up, faux sinon""" + # On utilise fping, en cas d'erreur, on considere + # que la borne est down (alors qu'elle peut simplement + # ne pas exister) + try: + retour = os.system("fping -q -c 1 %s > /dev/null 2> /dev/null" % borne) + return (retour == 0) + except: + return False + def prise_etat(chbre) : f = '' try :