scripts/munin/stats-ip
Nicolas Dandrimont cceeea27bb Tweaking des plugins munin
darcs-hash:20080914174748-ffbb2-f90ffd8cb29070a3d0ed1c63d3b7302e07815ae4.gz
2008-09-14 19:47:48 +02:00

51 lines
1.4 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Plugin pour visualiser l'utilisation des plages ip
import sys
sys.path.append('/usr/scripts/gestion')
from config import NETs
fichier = "/var/lib/munin/tmp/stats-ip"
try :
arg = sys.argv[1]
except :
arg = ''
if arg == "config" :
print 'host_name adresses-ip'
print 'graph_title Statistiques adresses IP'
print 'graph_args --base 1000 --lower-limit 0 --upper-limit 100'
print 'graph_category network'
print "graph_vlabel % d'utilisation"
for subnet in NETs.keys():
nom = subnet.replace('-', '')
print "%s.label %s" % (nom, subnet)
print "%s.warning 92" % nom
print "%s.critical 98" % nom
elif arg == "fichier" :
from ldap_crans import crans_ldap
from iptools import AddrInNet
ips = [ x.ip() for x in crans_ldap().search('ip=*')['machine'] ]
out = file(fichier, "w")
for subnet in NETs :
total = 0
for net in NETs[subnet]:
total += 2 ** ( 32 - int( net.split('/')[1] ) )
# on ne prend pas en compte les adresse .0 et .255
total = total - int(total/128)
utilisees = len( [ ip for ip in ips if AddrInNet( ip, NETs[subnet] ) ] )
pourcentage = int((utilisees*100)/total)
nom = subnet.replace('-', '')
out.write("%s.value %d\n" % (nom, pourcentage))
else:
print file(fichier).read()