How to monitor a Konica-Minolta printer’s settings using Nagios

For some reason, some users seem not to be able to keep their hands off the settings of my KonicaMinolta Bizhub 283. They keep changing the paper format for tray 2 to PlainPaper, causing all kinds of problems. Since there is no way to lock the settings, I started to monitor them and report them.

This is my Nagios script:

#!/usr/bin/python
 
import os
import pycurl
import cStringIO
import re
import random
import time
import tempfile
import sys
 
from lxml import etree
 
newcookiefile = tempfile.NamedTemporaryFile()
 
if len(sys.argv)!=2:
        print "Usage: "+sys.argv[0]+" [printer ip or hostname]"
        sys.exit(1)
 
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://"+sys.argv[1]+"/wcd/index.html")
c.setopt(pycurl.COOKIEFILE, newcookiefile.name)
c.setopt(pycurl.COOKIEJAR, newcookiefile.name)
c.setopt(pycurl.WRITEFUNCTION, buf.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.ENCODING, "")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.USERAGENT, "Something")
c.perform()
curlData = buf.getvalue()
buf.close()
 
buf = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://"+sys.argv[1]+"/wcd/system.xml")
c.setopt(pycurl.COOKIEFILE, newcookiefile.name)
c.setopt(pycurl.COOKIEJAR, newcookiefile.name)
c.setopt(pycurl.WRITEFUNCTION, buf.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.ENCODING, "")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.USERAGENT, "Something")
c.perform()
curlData = buf.getvalue()
buf.close()
 
#print curlData
 
tree = etree.fromstring(curlData)
root = etree.Element("root")
paperformat=tree.xpath('/MFP/DeviceInfo/Input/TrayList/Tray/TrayID[text()="Tray2"]/../CurrentPaper/MediaType')[0].text
 
if "PlainPaper" == paperformat:
        print "Someone touched the settings - again!"
        sys.exit(2)
 
print "OK"
sys.exit(0)
© GeekLabInfo How to monitor a Konica-Minolta printer's settings using Nagios is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Leave a Reply