[munin/canon_] plugin munin pour la nouvelle imprimante
darcs-hash:20090519021801-bd074-ea78d049a30a8ac0409c33d78f28b390494095f4.gz
This commit is contained in:
parent
d7d9f9e3d5
commit
e9a1d3033d
1 changed files with 58 additions and 35 deletions
63
munin/canon_
63
munin/canon_
|
@ -4,14 +4,32 @@
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
sys.path.append('/usr/scripts/impression')
|
sys.path.append('/usr/scripts/impression')
|
||||||
|
from commands import getstatusoutput
|
||||||
|
|
||||||
|
class ConversationError(Exception): pass
|
||||||
|
|
||||||
|
class snmp:
|
||||||
|
def __init__(self, host, version="1", community="public"):
|
||||||
|
self.cmd = 'snmpget -O v -v%s -c %s %s ' % (version, community, host)
|
||||||
|
|
||||||
|
def get(self, mib):
|
||||||
|
s, r = getstatusoutput(self.cmd + mib)
|
||||||
|
if s:
|
||||||
|
r = r.replace('snmpget: ', '')
|
||||||
|
raise ConversationError(r, self.cmd)
|
||||||
|
return r.split(' ', 1)[1]
|
||||||
|
|
||||||
|
comm = snmp(host="imprimante.adm.crans.org",version="1",community="public")
|
||||||
|
|
||||||
|
from impression_canon import SNMP_CAPA_B, SNMP_CAPA_C, SNMP_CAPA_M, \
|
||||||
|
SNMP_CAPA_Y, SNMP_TON_B, SNMP_TON_C, \
|
||||||
|
SNMP_TON_M, SNMP_TON_Y,SNMP_BAC1, SNMP_BAC2, \
|
||||||
|
SNMP_BAC3, SNMP_BAC4, SNMP_COUNT_A4, \
|
||||||
|
SNMP_COUNT_A3, SNMP_COUNT_A4c, \
|
||||||
|
SNMP_COUNT_A3c, SNMP_COUNT_TOT
|
||||||
|
|
||||||
from impression_canon import SNMP_CAPA_B, SNMP_CAPA_C, SNMP_CAPA_M, SNMP_CAPA_Y,
|
|
||||||
SNMP_TON_B, SNMP_TON_C, SNMP_TON_M, SNMP_TON_Y,
|
|
||||||
SNMP_BAC1, SNMP_BAC2, SNMP_BAC3, SNMP_BAC4
|
|
||||||
SNMP_COUNT_A4, SNMP_COUNT_A3, SNMP_COUNT_A4c,
|
|
||||||
SNMP_COUNT_A3c, SNMP_COUNT_TOT, COMM, LOG
|
|
||||||
dico_courbes_gen = {
|
dico_courbes_gen = {
|
||||||
'ton' : { 'titre' : u"État des toner",
|
'ton-p' : { 'titre' : u"État des toner",
|
||||||
'vlabel': u"Pourcentage restant",
|
'vlabel': u"Pourcentage restant",
|
||||||
'lower-limit' : 0,
|
'lower-limit' : 0,
|
||||||
'upper-limit' : 6000,
|
'upper-limit' : 6000,
|
||||||
|
@ -25,7 +43,7 @@ dico_courbes_gen = {
|
||||||
'ton_m' : SNMP_CAPA_M,
|
'ton_m' : SNMP_CAPA_M,
|
||||||
'ton_y' : SNMP_CAPA_Y }
|
'ton_y' : SNMP_CAPA_Y }
|
||||||
},
|
},
|
||||||
'ton-p' : { 'titre' : u"État des toner",
|
'ton' : { 'titre' : u"État des toner",
|
||||||
'vlabel': u"pages restantes",
|
'vlabel': u"pages restantes",
|
||||||
'lower-limit' : 0,
|
'lower-limit' : 0,
|
||||||
'upper-limit' : 100,
|
'upper-limit' : 100,
|
||||||
|
@ -35,21 +53,21 @@ dico_courbes_gen = {
|
||||||
'ton_y' : (SNMP_TON_Y, "Toner jaune", "ffff00") }
|
'ton_y' : (SNMP_TON_Y, "Toner jaune", "ffff00") }
|
||||||
},
|
},
|
||||||
'papier' : { 'titre' : 'Stock papier',
|
'papier' : { 'titre' : 'Stock papier',
|
||||||
'vlablel' : 'Feuilles restantes',
|
'vlabel' : 'Feuilles restantes',
|
||||||
'lower-limit' : 0,
|
'lower-limit' : 0,
|
||||||
'upper-limit' : 550,
|
'upper-limit' : 550,
|
||||||
'dico' : { 'Bac1' : (SNMP_BAC1, "Feuilles A4 (Bac 1)", '3333ff'),
|
'dico' : { 'Bac1' : (SNMP_BAC1, "Feuilles A4 (Bac 1)", '3333ff'),
|
||||||
'Bac2' : (SNMP_BAC2, "Feuilles A4 (Bac 2)", '4444cc'),
|
'Bac2' : (SNMP_BAC2, "Feuilles A4 (Bac 2)", '4444cc'),
|
||||||
'Bac3' : (SNMP_BAC3, "Feuilles A4R (Bac 3)", "33ff33"),
|
'Bac3' : (SNMP_BAC3, "Feuilles A4R (Bac 3)", "33ff33"),
|
||||||
'Bac3' : (SNMP_BAC4, "Feuilles A4R (Bac 3)", "ff3333") }
|
'Bac4' : (SNMP_BAC4, "Feuilles A4R (Bac 4)", "ff3333") }
|
||||||
},
|
},
|
||||||
'compteur' : { 'titre' : 'Pages imprimées',
|
'compteur' : { 'titre' : 'Pages imprimées',
|
||||||
'vlabel' : 'Pages',
|
'vlabel' : 'Pages',
|
||||||
'dico' : { 'nb_A4' : (SNMP_COUNT_A4, "Feuilles A4 n/b", '000000'),
|
'dico' : { 'nb_A4' : (SNMP_COUNT_A4, "Feuilles A4 n/b", '000000'),
|
||||||
(SNMP_COUNT_A3, "Feuilles A3 n/b", '333333'),
|
'nb_A3' : (SNMP_COUNT_A3, "Feuilles A3 n/b", '333333'),
|
||||||
(SNMP_COUNT_A4c, "Feuilles A4 coul", '00ffff'),
|
'nb_A4c': (SNMP_COUNT_A4c, "Feuilles A4 coul", '00ffff'),
|
||||||
(SNMP_COUNT_A3c, "Feuilles A3 coul", 'ff00ff'),
|
'nb_A3c': (SNMP_COUNT_A3c, "Feuilles A3 coul", 'ff00ff'),
|
||||||
(SNMP_COUNT_TOT, "Total", 'ffff00') }
|
'total' : (SNMP_COUNT_TOT, "Total", 'ffff00') }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +80,7 @@ lower_limit = dico_courbes_gen[arg].get('lower-limit', None)
|
||||||
upper_limit = dico_courbes_gen[arg].get('upper-limit', None)
|
upper_limit = dico_courbes_gen[arg].get('upper-limit', None)
|
||||||
max_courbes = dico_courbes_gen[arg].get('max', [])
|
max_courbes = dico_courbes_gen[arg].get('max', [])
|
||||||
|
|
||||||
|
|
||||||
try :
|
try :
|
||||||
arg = sys.argv[1]
|
arg = sys.argv[1]
|
||||||
except :
|
except :
|
||||||
|
@ -72,16 +91,18 @@ if arg == "config" :
|
||||||
print 'graph_category consommables'
|
print 'graph_category consommables'
|
||||||
if lower_limit and upper_limit:
|
if lower_limit and upper_limit:
|
||||||
print "graph_args --lower-limit %i --upper-limit %i --rigid" % (lower_limit,upper_limit)
|
print "graph_args --lower-limit %i --upper-limit %i --rigid" % (lower_limit,upper_limit)
|
||||||
|
else:
|
||||||
|
print "graph_args --lower-limit 0"
|
||||||
print 'graph_title %s' % titre
|
print 'graph_title %s' % titre
|
||||||
print "graph_vlabel %s" % vlabel
|
print "graph_vlabel %s" % vlabel
|
||||||
keys = dico_courbes.keys()
|
keys = dico_courbes.keys()
|
||||||
keys.sort()
|
keys.sort()
|
||||||
for fieldname in keys:
|
for fieldname in keys:
|
||||||
print "%s.label %s" % (fieldname,dico_courbes[fieldname][1])
|
print "%s.label %s" % (fieldname,dico_courbes[fieldname][1])
|
||||||
if warning:
|
# if warning:
|
||||||
print "%s.warning %s" % (fieldname, warning)
|
# print "%s.warning %s" % (fieldname, warning)
|
||||||
if critical:
|
# if critical:
|
||||||
print "%s.critical %s" % (fieldname, critical)
|
# print "%s.critical %s" % (fieldname, critical)
|
||||||
if len(dico_courbes[fieldname]) == 3 :
|
if len(dico_courbes[fieldname]) == 3 :
|
||||||
print "%s.colour %s" % (fieldname,dico_courbes[fieldname][2])
|
print "%s.colour %s" % (fieldname,dico_courbes[fieldname][2])
|
||||||
if len(dico_courbes[fieldname]) == 4 :
|
if len(dico_courbes[fieldname]) == 4 :
|
||||||
|
@ -89,14 +110,16 @@ if arg == "config" :
|
||||||
else:
|
else:
|
||||||
#Ecrit les valeurs actuelles sur la sortie standard
|
#Ecrit les valeurs actuelles sur la sortie standard
|
||||||
for fieldname in dico_courbes.keys():
|
for fieldname in dico_courbes.keys():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if max_courbes :
|
if max_courbes :
|
||||||
max_val = int(COMM.get(max_courbes[fieldname]))
|
max_val = int(comm.get(max_courbes[fieldname]))
|
||||||
value = 100*int(COMM.get(dico_courbes[fieldname][0]))/max_val
|
value = 100*int(comm.get(dico_courbes[fieldname][0]))/max_val
|
||||||
else :
|
else :
|
||||||
value = int(COMM.get(dico_courbes[fieldname][0]))
|
value = int(comm.get(dico_courbes[fieldname][0]))
|
||||||
except Exception,err:
|
except Exception,err:
|
||||||
value = 0
|
value = 0
|
||||||
|
print err
|
||||||
if value < 0 : value = 0
|
if value < 0 : value = 0
|
||||||
|
|
||||||
print "%s.value %s" % (fieldname,value)
|
print "%s.value %s" % (fieldname,value)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue