[munin/iptables_] remise au goût du jour du plugin

This commit is contained in:
Daniel STAN 2013-05-11 16:18:07 +02:00
parent d059fb154b
commit ec08d96426

View file

@ -20,46 +20,32 @@ except :
CHAINS = commands.getoutput('%s | grep Chain | awk \'{print $2}\'' % IPTABLES).split('\n') CHAINS = commands.getoutput('%s | grep Chain | awk \'{print $2}\'' % IPTABLES).split('\n')
def name_of_chain(chain):
"""Identifiant munin de la chaine"""
return string.lower(chain.replace('_', '').replace('-', '').replace('.','').replace('/', ''))
def label_of_chain(chain):
"""Label affiché sur le graphe"""
return chain.replace('_', '-').replace('.','-').replace('/','-')
if arg == "config" : if arg == "config" :
print 'graph_title Firewall %s' % string.lower(TABLE) print 'graph_title Firewall %s' % string.lower(TABLE)
print 'graph_args --base 1000 --lower-limit 0' print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category network' print 'graph_category network'
print "graph_vlabel nb de regles" print "graph_vlabel nb de regles"
for chain in CHAINS : for chain in CHAINS :
nom = string.lower(chain.replace('_', '').replace('-', '').replace('.','').replace('/', '')) nom = name_of_chain(chain)
label = chain.replace('_', '-').replace('.','-').replace('/','-') label = label_of_chain(chain)
if label != "TEST-MAC-IP" : print "%s.label %s" % (nom, label)
print "%s.label %s" % (nom, label) print "%s.draw AREASTACK" % nom
if CHAINS.index(chain) == 0 : if (label,TABLE) == ("TEST-MAC-IP",'filter'):
print "%s.draw AREA" % nom print "%s.warning 8:12" % nom
else : print "%s.critical 1:20" % nom
print "%s.draw STACK" % nom
else :
print "%sadm.label %s-adm" % (nom, label)
print "%sadm.draw STACK" % nom
print "%sadm.warning 2:2" % nom
print "%sadm.critical 2:10" % nom
print "%s.label %s" % (nom, label)
print "%s.warning 2:2" % nom
print "%s.critical 2:10" % nom
else : else :
for chain in CHAINS : for chain in CHAINS :
nom = string.lower(chain.replace('_', '').replace('-', '').replace('.','').replace('/', '')) nom = name_of_chain(chain)
label = chain.replace('_', '-').replace('.','-').replace('/','-') label = label_of_chain(chain)
if label == "TEST-MAC-IP" : # On retire 2 pour les entêtes
data = commands.getoutput("%s %s | uniq | awk '{print $4}' | grep 231 | awk -F '.' '{print $1$2$3}' | sort | uniq -c | grep 231" % (IPTABLES, chain)).split('\n') value = int(commands.getoutput('%s %s | wc -l' % (IPTABLES, chain))) - 2
total = 0 print "%s.value %d" % (nom, value)
for line in data :
try: value, subnet = line.split()
except ValueError: continue
total += int(value)
if subnet[:8] == "10231136":
print "%sadm.value %s" % (nom, value)
for x in range(136,152):
if subnet[:9] == ("138231%d" % x):
print "%s%d.value %s" % (nom, x, value)
print "%s.value %d" % (nom, total)
else :
value = int(commands.getoutput('%s %s | uniq | wc -l' % (IPTABLES, chain))) - 2
print "%s.value %d" % (nom, value)