scripts/munin/laserjet_
Antoine Durand-Gasselin 8de055f921 Les accents dans les graphes de munin, c'est trop gay
Et spamassassin dtecte les messages d'erreur comme des spam

darcs-hash:20081005185753-bd074-f0dd4af4dfead90a538f8cfc973e37a6738d398c.gz
2008-10-05 20:57:53 +02:00

154 lines
7.3 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: utf-8 -*
import sys
sys.path.append("/usr/scripts/gestion")
import hptools
dico_courbes_gen = {
'car' : {'titre' : u"Etat des cartouches",
'vlabel' : "nb de pages restantes",
'lower-limit' : 0,
'upper-limit' : 30000,
'warning' : "2000:",
'critical' : "500:",
'dico' : {
'car_bla' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.1.0","Cartouche noir","000000"),
'car_cya' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.2.0","Cartouche cyan","00ffff"),
'car_mag' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.3.0","Cartouche magenta","ff00ff"),
'car_yel' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.4.0","Cartouche jaune","ffff00")
}},
'car-p' : {'titre' : u"Etat des cartouches (pourcentage)",
'vlabel' : "pourcentage restant",
'lower-limit' : 0,
'upper-limit' : 100,
'dico' : {
'car_p_bla' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.18.1.0","Cartouche noir","000000"),
'car_p_cya' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.18.2.0","Cartouche cyan","00ffff"),
'car_p_mag' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.18.3.0","Cartouche magenta","ff00ff"),
'car_p_yel' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.18.4.0","Cartouche jaune","ffff00")
}},
'tam' : {'titre' : u"Etat des tambours",
'vlabel' : "nb de pages restantes",
'lower-limit' : 0,
'upper-limit' : 40000,
'warning' : "2000:",
'critical' : "500:",
'dico' : {
'tam_bla' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.5.0","Tambour d'imagerie noir","000000"),
'tam_cya' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.6.0","Tambour d'imagerie cyan","00ffff"),
'tam_mag' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.7.0","Tambour d'imagerie magenta","ff00ff"),
'tam_yel' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.8.0","Tambour d'imagerie jaune","ffff00"),
}},
'tam-p' : {'titre' : u"Etat des tambours (pourcentage)",
'vlabel' : "Pourcentage restant",
'lower-limit' : 0,
'upper-limit' : 100,
'dico' : {
'tam_p_bla' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.37.5.0","Tambour d'imagerie noir","000000"),
'tam_p_cya' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.37.6.0","Tambour d'imagerie cyan","00ffff"),
'tam_p_mag' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.37.7.0","Tambour d'imagerie magenta","ff00ff"),
'tam_p_yel' : ("enterprises.11.2.3.9.4.2.1.4.1.10.1.1.37.8.0","Tambour d'imagerie jaune","ffff00"),
}},
'stock-papier' : {'titre' : "Stock papier",
'vlabel' : "nb de pages restantes",
'lower-limit' : 0,
'upper-limit' : 2000,
'dico' : {
'tray6' : ("1.3.6.1.2.1.43.8.2.1.10.1.6","Feuilles A4","3333ff"),
'tray6_max' : ("1.3.6.1.2.1.43.8.2.1.9.1.6","Feuilles A4 (max)","0000cc"),
'tray3' : ("1.3.6.1.2.1.43.8.2.1.10.1.3","Feuilles A3","33ff33"),
'tray3_max' : ("1.3.6.1.2.1.43.8.2.1.9.1.3","Feuilles A3 (max)","00cc00"),
'tray2' : ("1.3.6.1.2.1.43.8.2.1.10.1.2","Cartons","ff3333"),
'tray2_max' : ("1.3.6.1.2.1.43.8.2.1.9.1.2","Cartons (max)","cc0000"),
'tray1' : ("1.3.6.1.2.1.43.8.2.1.10.1.1","Transparents","ffff33"),
'tray1_max' : ("1.3.6.1.2.1.43.8.2.1.9.1.1","Transparents (max)","cccc00"),
}},
'stock-papier-p' : {'titre' : "Stock papier (pourcentage)",
'vlabel' : "Pourcentage restant",
'lower-limit' : 0,
'upper-limit' : 100,
'dico' : {
'tray6' : ("1.3.6.1.2.1.43.8.2.1.10.1.6","Feuilles A4","3333ff"),
'tray3' : ("1.3.6.1.2.1.43.8.2.1.10.1.3","Feuilles A3","33ff33"),
'tray2' : ("1.3.6.1.2.1.43.8.2.1.10.1.2","Cartons","ff3333"),
'tray1' : ("1.3.6.1.2.1.43.8.2.1.10.1.1","Transparents","ffff33"),
},
'max' : {
'tray6' : "1.3.6.1.2.1.43.8.2.1.9.1.6",
'tray3' : "1.3.6.1.2.1.43.8.2.1.9.1.3",
'tray2' : "1.3.6.1.2.1.43.8.2.1.9.1.2",
'tray1' : "1.3.6.1.2.1.43.8.2.1.9.1.1",
}},
'kit' : {'titre' : u"Etat des kits images",
'vlabel' : "nb de pages restantes",
'lower-limit' : 0,
'upper-limit' : 150000,
'warning' : "2000:",
'critical' : "500:",
'dico' : {
'kit_tra' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.9.0","Kit de transfert image"),
'kit_net' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.10.0","Kit de nettoyage image"),
'kit_fus' : ("enterprises.11.2.3.9.4.2.1.4.1.10.5.1.1.11.0","Kit de fusion image")
}}
}
#Initialisation du dictionnaire des courbes
arg = sys.argv[0].split('_')[1]
dico_courbes = dico_courbes_gen[arg]['dico']
titre = dico_courbes_gen[arg]['titre']
vlabel = dico_courbes_gen[arg]['vlabel']
lower_limit = dico_courbes_gen[arg]['lower-limit']
upper_limit = dico_courbes_gen[arg]['upper-limit']
warning = dico_courbes_gen[arg].get("warning")
critical = dico_courbes_gen[arg].get("critical")
#########
try :
max_courbes = dico_courbes_gen[arg]['max']
except :
max_courbes = []
try :
arg = sys.argv[1]
except :
arg = ''
#Ecrit sur la sortie standard la configuration
if arg == "config" :
print 'host_name laserjet'
print 'graph_category consommables'
print "graph_args --lower-limit %i --upper-limit %i --rigid" % (lower_limit,upper_limit)
print 'graph_title %s' % titre
print "graph_vlabel %s" % vlabel
keys = dico_courbes.keys()
keys.sort()
for fieldname in keys:
print "%s.label %s" % (fieldname,dico_courbes[fieldname][1])
if warning:
print "%s.warning %s" % (fieldname, warning)
if critical:
print "%s.critical %s" % (fieldname, critical)
if len(dico_courbes[fieldname]) == 3 :
print "%s.colour %s" % (fieldname,dico_courbes[fieldname][2])
if len(dico_courbes[fieldname]) == 4 :
print "%s.draw %s" % (fieldname,dico_courbes[fieldname][3])
else:
#Ecrit les valeurs actuelles sur la sortie standard
try:
comm = hptools.snmp(host="laserjet.adm.crans.org",version="1",community="public")
except Exception,err:
exit
for fieldname in dico_courbes.keys():
try:
if max_courbes :
max_val = int(comm.get(max_courbes[fieldname]))
value = 100*int(comm.get(dico_courbes[fieldname][0]))/max_val
else :
value = int(comm.get(dico_courbes[fieldname][0]))
except Exception,err:
value = 0
if value < 0 : value = 0
print "%s.value %s" % (fieldname,value)