
Cela devrait rduire le temps de mise jour de munin. Il faudrait surement utiliser un fichier commun (objet dump via cPickle) pour ne pas remployer cet appel pour chacun des rseaux. darcs-hash:20070919135737-72cb0-84eb4724932256c3b98706ec67b6c452d951a954.gz
57 lines
1.5 KiB
Python
Executable file
57 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
# Plugin pour visualiser l'utilisation des plages ip
|
|
|
|
fichier = '/var/lib/munin/tmp/stats-ip_'
|
|
|
|
import sys, os, string
|
|
sys.path.append('/usr/scripts/gestion')
|
|
|
|
from ldap_crans import crans_ldap
|
|
from config import NETs
|
|
from iptools import AddrInNet
|
|
|
|
# On prend l'argument pour définir la plage d'ip à analyser
|
|
SUBNET = sys.argv[0].split('_')[1]
|
|
|
|
try :
|
|
arg = sys.argv[1]
|
|
except :
|
|
arg = ''
|
|
|
|
if arg == "config" :
|
|
if len(SUBNET) == 1 : NOM = "Bâtiment %s" % string.upper(SUBNET)
|
|
else: NOM = SUBNET
|
|
|
|
print 'host_name adresses-ip'
|
|
print 'graph_title Statistiques adresses IP - %s' % NOM
|
|
print 'graph_args --base 1000 --lower-limit 0'
|
|
print 'graph_category network'
|
|
print "graph_vlabel nb d'ips"
|
|
print "utilisees.label IP utilisées"
|
|
print "utilisees.draw AREA"
|
|
print "total.label Total disponibles"
|
|
|
|
elif arg == "fichier" :
|
|
|
|
ips = [ x.ip() for x in crans_ldap().search('ip=*')['machine'] ]
|
|
|
|
file = open('%s%s.next' % (fichier, SUBNET), 'w')
|
|
|
|
total = 0
|
|
for net in NETs[SUBNET]:
|
|
total += 2 ** ( 32 - int( net.split('/')[1] ) )
|
|
# on ne prend pas en compte les adresses .0 et .255
|
|
total = total - int(total/128)
|
|
|
|
utilisees = len( [ ip for ip in ips if AddrInNet( ip, NETs[SUBNET] ) ] )
|
|
|
|
file.write("utilisees.value %d\n" % utilisees)
|
|
file.write("total.value %s\n" % total)
|
|
file.close()
|
|
|
|
os.system('mv %s%s.next %s%s' % (fichier, SUBNET, fichier, SUBNET))
|
|
|
|
else :
|
|
os.system('cat %s%s' % (fichier, SUBNET))
|