diff --git a/munin/consommables_hp b/munin/consommables_hp new file mode 100755 index 00000000..a6c6470b --- /dev/null +++ b/munin/consommables_hp @@ -0,0 +1,64 @@ +#!/bin/bash /usr/scripts/python.sh +# -*- coding: utf-8 -*- + +from __future__ import print_function +import BeautifulSoup +import re +import requests +import sys + +URL = 'https://imprimante.adm.crans.org/hp/device/DeviceStatus/Index' +CA = '/etc/ssl/certs/cacert.org.pem' + +COLOR_INFOS = { + 'black': ('noir', '000000'), + 'cyan': ('cyan', '00ffff'), + 'magenta': ('magenta', 'ff00ff'), + 'yellow': ('jaune', 'ffff00'), +} + +COLORS = COLOR_INFOS.keys() + +CONS_CLASS_BLOCK = { + color: re.compile(".*consumable-block-"+color.capitalize() +".*") + for color in COLORS +} + +def ffindconsomable(color, raw): + """Retrouve la couleur `color` dans raw""" + couleur=raw.findAll('div', attrs={"class":CONS_CLASS_BLOCK[color]}) + couleur_toner=couleur[0].findAll('p',attrs={"class":'data percentage'})[0].string + couleur_toner=couleur_toner.split('%')[0] + couleur_tambour=couleur[1].findAll('p',attrs={"class":'data percentage'})[0].string + couleur_tambour=couleur_tambour.split('%')[0] + try: + couleur_tambour=re.sub('[^\.0-9]', '', couleur_tambour.decode()) + couleur_toner=re.sub('[^\.0-9]', '', couleur_toner.decode()) + except: + return None, None + return couleur_toner, couleur_tambour + + +if __name__ == '__main__': + if 'config' in sys.argv: + print("host_name laserjet") + print("graph_category consommables") + print("graph_args --lower-limit 0 --upper-limit 100 --rigid") + print("graph_title Etat des consommables (pourcentage)") + print("graph_vlabel Pourcentage restant") + for color, (pr_name, hex) in COLOR_INFOS.iteritems(): + print("%s_toner.label Toner %s" % (color, pr_name)) + print("%s_tambour.label Tambour %s" % (color, pr_name)) + print("%s_toner.draw LINE1" % color) + print("%s_tambour.draw LINE2" % color) + print("%s_toner.colour %s" % (color, hex)) + print("%s_tambour.colour %s" % (color, hex)) + else: + page = requests.get(URL, verify=CA) + raw=BeautifulSoup.BeautifulSoup(page.text) + + for color in COLORS: + toner, tambour = ffindconsomable(color, raw) + print('{}_toner.value {}'.format(color, toner)) + print('{}_tambour.value {}'.format(color, tambour)) + diff --git a/munin/scripts/hosts_plugins.py b/munin/scripts/hosts_plugins.py index 1af6bad6..d1100f2b 100755 --- a/munin/scripts/hosts_plugins.py +++ b/munin/scripts/hosts_plugins.py @@ -127,6 +127,7 @@ hosts_plugins = { "laserjet_stock-papier-p": "laserjet_", "laserjet_tam": "laserjet_", "laserjet_tam-p": "laserjet_", + "laserjet_consommables": "consommables_hp", # La suite plus bas... }, "news": {