[whokfet] ajout d'un plugin munin
This commit is contained in:
parent
75a4d6b8f2
commit
c3e28ac9c1
4 changed files with 52 additions and 11 deletions
0
gestion/tools/__init__.py
Normal file
0
gestion/tools/__init__.py
Normal file
|
@ -27,12 +27,19 @@ def get_wifi_connected_client(host):
|
|||
f.close()
|
||||
return [ mac.firstChild.nodeValue for mac in doc.getElementsByTagName('mac') ]
|
||||
|
||||
STATE_DESCR = {
|
||||
'ma': ('machines de membres actifs', 0x00ff00),
|
||||
'crans': ('machines du crans', 0x0000ff),
|
||||
'adh': ('autres machines appartenant aux autres adhérents', 0xe5ff00),
|
||||
'unknown_macs': ('machines inconnues de la base', 0xff0000),
|
||||
}
|
||||
def get_state():
|
||||
sw = hpswitch('backbone.adm.crans.org')
|
||||
db = crans_ldap()
|
||||
res = {'machines': [],
|
||||
'machines_crans': [],
|
||||
'unknown': [],
|
||||
res = {'ma': [],
|
||||
'crans': [],
|
||||
'adh': [],
|
||||
'unknown_macs': [],
|
||||
'ttyfound': 0,
|
||||
}
|
||||
try:
|
||||
|
@ -45,27 +52,44 @@ def get_state():
|
|||
fm = db.search("mac=%s" % mac)
|
||||
if fm['machine']:
|
||||
m = fm['machine'][0]
|
||||
if not fm['machineCrans'] and hasattr(m.proprietaire(),'droits') and m.proprietaire().droits():
|
||||
# On filtre ceux qui ont des droits et qui sont pas des machines crans
|
||||
res['machines'].append(m)
|
||||
if fm['machineCrans']:
|
||||
key = 'crans'
|
||||
elif hasattr(m.proprietaire(),'droits') and m.proprietaire().droits():
|
||||
key = 'ma'
|
||||
else:
|
||||
res['unknown'].append(mac)
|
||||
key = 'adh'
|
||||
res[key].append(m)
|
||||
else:
|
||||
res['unknown_macs'].append(mac)
|
||||
return res
|
||||
|
||||
def summary(current):
|
||||
u"""Réalise un joli aperçu de l'état donné en paramètre."""
|
||||
if current['machines']:
|
||||
if current['ma']:
|
||||
cprint('---=== Machines des membres actifs ===---', 'bleu')
|
||||
aff(current['machines'])
|
||||
aff(current['ma'])
|
||||
cprint("---=== Il y a du monde à la Kfet ! ===---", 'vert')
|
||||
else:
|
||||
cprint("---=== Il semble n'y avoir personne à la Kfet ... ===---", 'rouge')
|
||||
for mac in current['unknown']:
|
||||
for mac in current['unknown_macs']:
|
||||
cprint("Machine inconnue: %s" % mac, 'rouge')
|
||||
|
||||
def munin_config():
|
||||
"""Donne la configuration du graphe munin"""
|
||||
print """graph_title Membres actifs à la kfet
|
||||
graph_vlabel N
|
||||
graph_category environnement"""
|
||||
for (name,(descr,color)) in STATE_DESCR.iteritems():
|
||||
print """%(name)s.label %(descr)s
|
||||
%(name)s AREASTACK
|
||||
%(name)s.colour %(color)06X""" % {'name': name, 'descr': descr, 'color': color}
|
||||
# Dans le doute, n'affichons pas les adhérents
|
||||
print "adh.graph no"
|
||||
|
||||
def munin(current):
|
||||
"""S'occupe de l'affichage pour munin. TODO: l'écrire."""
|
||||
pass
|
||||
for name in STATE_DESCR.iterkeys():
|
||||
print """%(name)s.value %(value)s""" % {'name': name, 'value': len(current[name])}
|
||||
|
||||
if __name__ == '__main__':
|
||||
state = get_state()
|
||||
|
|
|
@ -37,6 +37,7 @@ hosts_plugins = {
|
|||
"webalizer_intranet": "webalizer_",
|
||||
"webalizer_perso": "webalizer_",
|
||||
"who": "who",
|
||||
"whokfet": "whokfet",
|
||||
},
|
||||
"vert": {
|
||||
"slapd_bdb_cache_pages": "slapd_bdb_cache_",
|
||||
|
|
16
munin/whokfet
Executable file
16
munin/whokfet
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Graphe des membres actifs présents à la Kfet"""
|
||||
|
||||
import sys
|
||||
sys.path.append('/usr/scripts')
|
||||
from gestion.tools import whokfet
|
||||
|
||||
action = ''.join(sys.argv[1:2])
|
||||
if action == 'autoconfig':
|
||||
print "yes"
|
||||
elif action == 'config':
|
||||
whokfet.munin_config()
|
||||
else:
|
||||
whokfet.munin(whokfet.get_state())
|
Loading…
Add table
Add a link
Reference in a new issue