Support des fonctions de who2b dans whosthere avec comme arg 2b
This commit is contained in:
parent
686bc45ed5
commit
39409ec894
1 changed files with 37 additions and 6 deletions
|
@ -8,6 +8,8 @@ import sys
|
|||
import collections
|
||||
import os
|
||||
import xml.dom.minidom
|
||||
import subprocess
|
||||
from socket import gethostname
|
||||
|
||||
from lc_ldap import shortcuts
|
||||
|
||||
|
@ -44,6 +46,8 @@ def pretty_name(item):
|
|||
except KeyError:
|
||||
nom = unicode(item['host'][0])
|
||||
v = nom
|
||||
except TypeError:
|
||||
v = item
|
||||
v = v.replace('.wifi.crans.org', ' (WiFi)')
|
||||
v = v.replace('.adm.crans.org', '')
|
||||
v = v.replace('.crans.org', '')
|
||||
|
@ -97,8 +101,6 @@ class WhosThere(object):
|
|||
"""Rempli à partir de la mac"""
|
||||
fm = self.db.search(u"macAddress=%s" % mac)
|
||||
res = self._res
|
||||
if mac in self.expected:
|
||||
return
|
||||
if fm:
|
||||
m = fm[0]
|
||||
proprio = m.proprio()
|
||||
|
@ -122,6 +124,16 @@ class WhosThere(object):
|
|||
else:
|
||||
res['unknown_macs'].append(mac)
|
||||
|
||||
def expected_machine(self):
|
||||
"""Remplie la liste des machines qui devraient etre dans le local"""
|
||||
current = self.query()
|
||||
mach_manq = []
|
||||
detected_mach = [machine['host'][0] for machine in current['crans'] + current['bde']]
|
||||
for mach in self.expected:
|
||||
if mach not in detected_mach:
|
||||
mach_manq.append(mach)
|
||||
return mach_manq
|
||||
|
||||
def populate_from_switch(self, host, port):
|
||||
"""Rempli les macs à partir de la prise d'un switch"""
|
||||
sw = hpswitch(host)
|
||||
|
@ -142,6 +154,13 @@ class WhosThere(object):
|
|||
for mac in doc.getElementsByTagName('mac'):
|
||||
self.populate_from_mac(mac.firstChild.nodeValue)
|
||||
|
||||
def populate_from_tty(self):
|
||||
res = self._res
|
||||
p = subprocess.check_output(["/usr/bin/w"])
|
||||
for line in p.split("\n"):
|
||||
if "gdm-session" in line:
|
||||
res['ttyfound'].append(line)
|
||||
|
||||
def do_scan(self):
|
||||
"""Fonction à surcharger pour remplir la liste de personnes présentes.
|
||||
La fonction pourra faire appel à populate_from_*"""
|
||||
|
@ -157,7 +176,7 @@ class WhosThere(object):
|
|||
'adh': [],
|
||||
'bde': [],
|
||||
'unknown_macs': [],
|
||||
'ttyfound': 0,
|
||||
'ttyfound': [],
|
||||
}
|
||||
self.db = shortcuts.lc_ldap_readonly()
|
||||
self.do_scan()
|
||||
|
@ -169,11 +188,18 @@ class WhosThere(object):
|
|||
if current['ma']:
|
||||
cprint('---=== Machines des membres actifs ===---', 'bleu')
|
||||
show_liste_by_prop(current['ma'])
|
||||
if hasattr(self, "tty_server"):
|
||||
if gethostname()!=self.tty_server:
|
||||
cprint(u'---=== Il faut executer ce script sur %s pour avoir les users logués ! ===---' % self.tty_server, 'rouge')
|
||||
else:
|
||||
if current['ttyfound']:
|
||||
cprint('---=== W(ho) sur %s ===---' % self.tty_server, 'bleu')
|
||||
for user in current["ttyfound"]:
|
||||
cprint(user, 'jaune')
|
||||
if current['ma'] or current['ttyfound']:
|
||||
cprint("---=== Il y a du monde ===---", 'vert')
|
||||
else:
|
||||
cprint("---=== Il semble n'y avoir personne ... ===---", 'rouge')
|
||||
for mac in current['unknown_macs']:
|
||||
cprint("Machine inconnue: %s" % mac, 'rouge')
|
||||
if current['crans']:
|
||||
cprint("---=== Machines Cr@ns ===---", 'bleu')
|
||||
show_liste(current['crans'])
|
||||
|
@ -183,6 +209,10 @@ class WhosThere(object):
|
|||
if current['adh']:
|
||||
cprint("---=== Machines d'adhérents ===---", 'bleu')
|
||||
show_liste_by_prop(current['adh'])
|
||||
for mac in current['unknown_macs']:
|
||||
cprint("Machine inconnue: %s" % mac, 'rouge')
|
||||
for machine_manquante in self.expected_machine():
|
||||
cprint("Machine %s manquante !" % pretty_name(machine_manquante), 'rouge')
|
||||
|
||||
def munin_config(self):
|
||||
"""Donne la configuration du graphe munin"""
|
||||
|
@ -230,7 +260,6 @@ class Who2B(WhosThere):
|
|||
name = u"2B"
|
||||
|
||||
expected = [
|
||||
'00:07:cb:b1:99:4e', # Freebox
|
||||
'terminal.crans.org',
|
||||
'minigiga.adm.crans.org',
|
||||
'belides.wifi.crans.org',
|
||||
|
@ -243,6 +272,8 @@ class Who2B(WhosThere):
|
|||
# mais on cache quand-même les personnes connectées en WiFi
|
||||
self.set_ignore_inactive(True, wifi_only=True)
|
||||
self.populate_from_switch('backbone.adm.crans.org', 33)
|
||||
self.tty_server=u"vo"
|
||||
self.populate_from_tty()
|
||||
|
||||
class WhoDAlembert(WhosThere):
|
||||
name = u"D'Alembert (PR)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue