[munin/scripts] Améliorations diverses
Ignore-this: caad836e0dfeafe6da1f30b6cf74ec63 darcs-hash:20090328152022-ffbb2-79e3736d738365780ba14d263f2cf83016164234.gz
This commit is contained in:
parent
371e293d9d
commit
67edc088e7
2 changed files with 69 additions and 32 deletions
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
# Copyright © 2009 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
|
# Copyright © 2009 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
|
||||||
#
|
#
|
||||||
# Licence: Domaine public (qui voudrait de ça de toute façon...)
|
# Licence: MIT
|
||||||
|
|
||||||
import sys as _sys
|
import sys as _sys
|
||||||
_sys.path.append("/usr/scripts/gestion")
|
_sys.path.append("/usr/scripts/gestion")
|
||||||
|
@ -43,16 +43,13 @@ hosts_plugins = {
|
||||||
"iptables_mangle": "iptables_",
|
"iptables_mangle": "iptables_",
|
||||||
"iptables_nat": "iptables_",
|
"iptables_nat": "iptables_",
|
||||||
"machines": "machines",
|
"machines": "machines",
|
||||||
"webalizer_dixans": "webalizer_",
|
# "webalizer_dixans": "webalizer_",
|
||||||
"webalizer_install-party": "webalizer_",
|
# "webalizer_install-party": "webalizer_",
|
||||||
"webalizer_news": "webalizer_",
|
# "webalizer_news": "webalizer_",
|
||||||
"webalizer_trophee": "webalizer_",
|
# "webalizer_trophee": "webalizer_",
|
||||||
"webalizer_webmail": "webalizer_",
|
# "webalizer_webmail": "webalizer_",
|
||||||
"webalizer_wiki": "webalizer_",
|
# "webalizer_wiki": "webalizer_",
|
||||||
"webalizer_www": "webalizer_",
|
# "webalizer_www": "webalizer_",
|
||||||
"wiki_pages": "wiki_pages",
|
|
||||||
"wiki_themes": "wiki_themes",
|
|
||||||
"wiki_users": "wiki_users",
|
|
||||||
},
|
},
|
||||||
"komaz": {
|
"komaz": {
|
||||||
"iptables_filter": "iptables_",
|
"iptables_filter": "iptables_",
|
||||||
|
@ -66,6 +63,14 @@ hosts_plugins = {
|
||||||
"iptables_mangle": "iptables_",
|
"iptables_mangle": "iptables_",
|
||||||
"iptables_nat": "iptales_",
|
"iptables_nat": "iptales_",
|
||||||
},
|
},
|
||||||
|
"xmpp": {
|
||||||
|
"jabber": "jabeer",
|
||||||
|
},
|
||||||
|
"niomniom": {
|
||||||
|
"wiki_pages": "wiki_pages",
|
||||||
|
"wiki_themes": "wiki_themes",
|
||||||
|
"wiki_users": "wiki_users",
|
||||||
|
},
|
||||||
"munin": {
|
"munin": {
|
||||||
"audimat": "audimat",
|
"audimat": "audimat",
|
||||||
"batiments": "batiments",
|
"batiments": "batiments",
|
||||||
|
|
|
@ -12,7 +12,9 @@
|
||||||
# Licence: MIT
|
# Licence: MIT
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import optparse
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -37,6 +39,9 @@ if sys.version_info < (2, 5):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def register_quirk(f):
|
||||||
|
QUIRKS.append(f)
|
||||||
|
|
||||||
def get_munin_plugins():
|
def get_munin_plugins():
|
||||||
"""Liste les plugins munin créés par le système
|
"""Liste les plugins munin créés par le système
|
||||||
|
|
||||||
|
@ -102,10 +107,16 @@ def get_all_plugins():
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def link_all_plugins(directory, plugins):
|
def list_plugins(plugins, directory):
|
||||||
"""Lie tous les plugins du dictionnaire plugins dans le répertoire
|
"""Liste les plugins comme s'ils allaient être liés dans
|
||||||
directory"""
|
directory"""
|
||||||
|
|
||||||
|
for name, path in sorted(plugins.items()):
|
||||||
|
print os.path.join(directory, name), '->', path
|
||||||
|
|
||||||
|
def link_plugins(plugins, directory):
|
||||||
|
"""Lie les plugins dans le répertoire directory"""
|
||||||
|
|
||||||
for name, path in plugins.iteritems():
|
for name, path in plugins.iteritems():
|
||||||
os.symlink(path, os.path.join(directory, name))
|
os.symlink(path, os.path.join(directory, name))
|
||||||
|
|
||||||
|
@ -117,14 +128,14 @@ def add_plugin(plugin):
|
||||||
plugins[plugin] = os.path.join(MUNIN_PATH, plugin)
|
plugins[plugin] = os.path.join(MUNIN_PATH, plugin)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
register_quirk(add_plugin("uptime")) # Coucou MoSaN
|
||||||
QUIRKS.append(add_plugin("uptime")) # Coucou MoSaN
|
register_quirk(add_plugin("netstat"))
|
||||||
QUIRKS.append(add_plugin("netstat"))
|
|
||||||
|
|
||||||
# Hacks sales
|
# Hacks sales
|
||||||
def add_wicked_ifaces_if_no_ifaces(plugins):
|
@register_quirk
|
||||||
"""Ajoute les interfaces moisies (p.ex. `crans') aux plugins si
|
def add_ifaces(plugins):
|
||||||
munin n'a pas trouvé d'interface"""
|
"""Ajoute les interfaces à la liste des plugins si munin n'a pas
|
||||||
|
trouvé d'interface (ou si elles ont été filtrées)"""
|
||||||
|
|
||||||
if not any(plugin.startswith('if_') for plugin in plugins):
|
if not any(plugin.startswith('if_') for plugin in plugins):
|
||||||
# Liste les interfaces configurées sur le système
|
# Liste les interfaces configurées sur le système
|
||||||
|
@ -133,25 +144,46 @@ def add_wicked_ifaces_if_no_ifaces(plugins):
|
||||||
try:
|
try:
|
||||||
interfaces_file = file('/etc/network/interfaces', 'r')
|
interfaces_file = file('/etc/network/interfaces', 'r')
|
||||||
for line in interfaces_file:
|
for line in interfaces_file:
|
||||||
line = line.strip()
|
line = line.split()
|
||||||
# Recherche d'une ligne type "iface eth0 inet static"
|
# Recherche d'une ligne type "iface eth0 inet static"
|
||||||
if line.startswith('iface'):
|
if line and line[0] == 'iface' and line[-1] == 'static':
|
||||||
if line.endswith("static"):
|
interface_name = line[1]
|
||||||
interface_name = line.split()[1]
|
# on dégage les interfaces sur vlan spéciaux et
|
||||||
# on dégage les interfaces sur vlan spéciaux et aliasées
|
# aliasées (leur nom contient ':' ou '.')
|
||||||
if not set('.:') & set(interface_name):
|
if not set('.:') & set(interface_name):
|
||||||
interfaces.append(interface_name)
|
interfaces.append(interface_name)
|
||||||
finally:
|
finally:
|
||||||
if interfaces_file is not None:
|
if interfaces_file is not None:
|
||||||
interfaces_file.close()
|
interfaces_file.close()
|
||||||
|
|
||||||
for interface in interfaces:
|
for interface in interfaces:
|
||||||
plugins['if_%s' % interface] = os.path.join(MUNIN_PATH, 'if_')
|
plugins['if_%s' % interface] = os.path.join(MUNIN_PATH,'if_')
|
||||||
plugins['if_err_%s' % interface] = os.path.join(MUNIN_PATH, 'if_err_')
|
plugins['if_err_%s' % interface] = os.path.join(MUNIN_PATH, 'if_err_')
|
||||||
|
|
||||||
QUIRKS.append(add_wicked_ifaces_if_no_ifaces)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
tmpdir = tempfile.mkdtemp()
|
parser = optparse.OptionParser()
|
||||||
print tmpdir
|
parser.add_option('-d', '--directory',
|
||||||
link_all_plugins(tmpdir, get_all_plugins())
|
help = 'Write plugin symlinks to DIR',
|
||||||
|
metavar = 'DIR',
|
||||||
|
default = '/etc/munin/plugins'
|
||||||
|
)
|
||||||
|
parser.add_option('-f', '--force',
|
||||||
|
action = 'store_true',
|
||||||
|
help = 'Remove destination directory'
|
||||||
|
)
|
||||||
|
parser.add_option('-p', '--pretend',
|
||||||
|
action = 'store_true',
|
||||||
|
help = 'Do not actually make links'
|
||||||
|
)
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
plugins = get_all_plugins()
|
||||||
|
|
||||||
|
if options.pretend:
|
||||||
|
list_plugins(plugins, options.directory)
|
||||||
|
else:
|
||||||
|
if options.force:
|
||||||
|
shutil.rmtree(options.directory)
|
||||||
|
os.mkdir(options.directory)
|
||||||
|
link_plugins(plugins, options.directory)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue