
Ignore-this: 9b64aca14cec96439dcc3129e4fdfa67 darcs-hash:20110301153418-ffbb2-7a7885d0bb9d966d359b830cc2b242ff9fcf2d72.gz
162 lines
5.1 KiB
Python
Executable file
162 lines
5.1 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -!- encoding: utf-8 -!-
|
|
# Correspondance hôte <-> plugin munin custom
|
|
#
|
|
# Copyright © 2009 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
|
|
#
|
|
# Licence: MIT
|
|
|
|
import sys as _sys
|
|
_sys.path.append("/usr/scripts/gestion")
|
|
del _sys
|
|
|
|
import annuaires
|
|
import config
|
|
|
|
__all__ = ["hosts_plugins", "munin_fw", "cron_plugins", "hosts_crons"]
|
|
|
|
# Lignes cron correspondant aux plugins customs
|
|
cron_plugins = {
|
|
# plugin: (utilisateur, commande),
|
|
# %s est remplacé par le lien dans /etc/munin/plugins
|
|
"audimat": ("root", "nice -n 14 %s generate 2> /dev/null"),
|
|
"batiments": ("root", "nice -n 14 %s fichier 2> /dev/null"),
|
|
"stats-ip_": ("root", "nice -n 14 %s fichier 2> /dev/null"),
|
|
"stats-ip": ("root", "nice -n 14 %s fichier 2> /dev/null"),
|
|
"wiki_pages": ("www-data", "%s fichier 2> /dev/null"),
|
|
}
|
|
|
|
# Hôtes pour lesquels le firewall est muninisé
|
|
munin_fw = sorted(["zamok", "rouge", "komaz", "sable", "gordon"])
|
|
|
|
hosts_plugins = {
|
|
"zamok": {
|
|
"canon_compteur": "canon_",
|
|
"canon_papier": "canon_",
|
|
"canon_ton-p": "canon_",
|
|
"webalizer_intranet": "webalizer_",
|
|
"webalizer_perso": "webalizer_",
|
|
"who": "who",
|
|
},
|
|
"vert": {
|
|
"slapd_bdb_cache_pages": "slapd_bdb_cache_",
|
|
"slapd_bdb_cache_percent": "slapd_bdb_cache_",
|
|
},
|
|
"rouge": {
|
|
"amavis": "amavis",
|
|
"machines": "machines",
|
|
# "webalizer_dixans": "webalizer_",
|
|
# "webalizer_install-party": "webalizer_",
|
|
# "webalizer_news": "webalizer_",
|
|
# "webalizer_trophee": "webalizer_",
|
|
# "webalizer_webmail": "webalizer_",
|
|
# "webalizer_wiki": "webalizer_",
|
|
# "webalizer_www": "webalizer_",
|
|
},
|
|
"komaz": {
|
|
"machines": "machines",
|
|
"if_sixxs2": "/usr/share/munin/plugins/if_",
|
|
"if_err_sixxs2": "/usr/share/munin/plugins/if_err_",
|
|
},
|
|
"sable": {
|
|
"blacklist": "blacklist",
|
|
"squid_efficiency": "squid_efficiency",
|
|
},
|
|
"gordon": {
|
|
"uptime_bornes": "/usr/scripts/wifi/bornes.py",
|
|
"canal_bornes": "/usr/scripts/wifi/bornes.py",
|
|
"clients_bornes": "/usr/scripts/wifi/bornes.py"
|
|
},
|
|
"xmpp": {
|
|
"jabber": "jabber",
|
|
"ejabberd_connections": "ejabberd_",
|
|
"ejabberd_users": "ejabberd_",
|
|
"ejabberd_registrations": "ejabberd_",
|
|
"ejabberd_statuses": "ejabberd_",
|
|
"ejabberd_memory": "ejabberd_",
|
|
"ejabberd_threads": "ejabberd_",
|
|
"ejabberd_usersindays": "ejabberd_",
|
|
"ejabberd_uptime": "ejabberd_",
|
|
},
|
|
"niomniom": {
|
|
"wiki_pages": "wiki_pages",
|
|
"wiki_themes": "wiki_themes",
|
|
"wiki_users": "wiki_users",
|
|
},
|
|
"munin": {
|
|
"audimat": "audimat",
|
|
"batiments": "batiments",
|
|
"munin": "munin",
|
|
"ping_multiprise_v6.adm": "ping_",
|
|
"stats-ip": "stats-ip",
|
|
# La suite plus bas...
|
|
},
|
|
"news": {
|
|
"innd_total": "innd_total",
|
|
"innd_last": "innd_last",
|
|
"innd_connects": "innd_connects",
|
|
}
|
|
}
|
|
|
|
####
|
|
# Trucs spécifiques à munin.crans.org
|
|
# Onduleur
|
|
for mge_truc in ["batt", "hygro", "intensite", "temp", "temps", "tension"]:
|
|
hosts_plugins["munin"]["mge_%s" % mge_truc] = "mge_%s" % mge_truc
|
|
|
|
# Stats d'utilisation des réseaux
|
|
for net in config.NETs:
|
|
hosts_plugins["munin"]["stats-ip_%s" % net] = "stats-ip_"
|
|
|
|
# Stats de peuplement des bâtiments
|
|
for bat in annuaires.bat_switchs:
|
|
if bat not in ('v',):
|
|
hosts_plugins["munin"]["stats-batiment_%s" % bat] = "stats-batiment_"
|
|
|
|
# Ping de tous les switches de bâtiments
|
|
for switch in annuaires.all_switchs():
|
|
# Suppression du .adm.crans.org
|
|
switch = switch[:switch.index('.')]
|
|
switch = switch.replace('-', '_')
|
|
hosts_plugins["munin"]["ping_%s.adm" % switch] = "ping_bat_"
|
|
|
|
# Et les vigiles...
|
|
for lieu in ["0a", "0b", "2b", "0c", "0g", "2g", "4g", "0h", "-1i", "0j", "4j", "0m"]:
|
|
hosts_plugins["munin"]["vigile_vigile_%s.adm.crans.org" % lieu.replace('-','_')] = "/usr/scripts/surveillance/vigile"
|
|
|
|
# On rajoute les stats de connexion
|
|
for host in hosts_plugins.keys():
|
|
hosts_plugins[host].update({"sockets": "sockets"})
|
|
|
|
#########
|
|
# Muninisation des firewalls
|
|
#
|
|
for host in munin_fw:
|
|
hosts_plugins[host].update({
|
|
"iptables_filter": "iptables_",
|
|
"iptables_mangle": "iptables_",
|
|
"iptables_nat": "iptables_",
|
|
})
|
|
|
|
# format de la ligne cron
|
|
CRON_FORMAT = "%s-%s/%s * * * * %s %s"
|
|
# fréquence
|
|
FREQ = 15
|
|
# lignes cron par hôte
|
|
hosts_crons = {}
|
|
for host, plugins in hosts_plugins.items():
|
|
minute = 1
|
|
hosts_crons[host] = []
|
|
for path, plugin in plugins.items():
|
|
if plugin in cron_plugins:
|
|
path = "/etc/munin/plugins/" + path
|
|
user, line = cron_plugins[plugin]
|
|
hosts_crons[host].append(CRON_FORMAT % (minute,
|
|
60 - FREQ + minute,
|
|
FREQ,
|
|
user,
|
|
line % path))
|
|
minute = (minute + 4) % FREQ
|
|
|
|
if not hosts_crons[host]:
|
|
del hosts_crons[host]
|