Jump to content

Recommended Posts

Posted

Hi,

 

Thought I would share and ask for opinions. This is a printer monitor I created which we are finding extremely useful for resolving any printer queries.

 

It uses Python to fetch the data from each SNMP capable printer and returns any errors/warnings (including jams), toner levels, name, IP address (which links to the printers own page) and page count and as you can see changes colour depending on the status. It is a live feed and updates every 5 seconds. The screenshot is just a section from the page.

 

printer-mon.png

 

If any one is interested I will happily post the Python code. The python script is called from jQuery and returns formatted HTML which is added straight onto the page.

 

Any suggestions?

  • Thanks 2
Posted

No unfortunately it was cobbled together and is not on github - the only interesting part is the Python script, the HTML page is nothing more than a jQuery AJAX request on a timer and a

 

 

#!/usr/bin/env python

import netsnmp
import os

Printers = ["10.0.0.1", "10.0.0.2", "10.0.0.3"]     #IPs changed for security

isoName = "iso.3.6.1.2.1.1.6.0"
isoMessage = "iso.3.6.1.2.1.43.16.5.1.2.1.1"
isoErrors = "iso.3.6.1.2.1.43.18.1.1.8"
isoTonerMax = "iso.3.6.1.2.1.43.11.1.1.8.1"
isoTonerLevel = "iso.3.6.1.2.1.43.11.1.1.9.1"
isoTonerColour = "iso.3.6.1.2.1.43.12.1.1.4.1"
isoPageCount = "iso.3.6.1.2.1.43.10.2.1.4.1.1"

MFDWarning = ["Tray 1 Low", "Tray 2 Low", "Tray 3 Low", "Black cartridge low", "Cyan cartridge low", "Magenta cartridge low", "Yellow cartridge low"]


print "Content-type: text/html"
print ""
print ""
x = 0
for Printer in Printers:

   command = "snmpget -v 1 -c public " + Printer + " " + isoName
   prnName = os.popen(command).read()
   prnName = prnName[prnName.find(":")+1:]
   prnName = prnName.replace('"', "")

   command = "snmpwalk -v 1 -c public " + Printer + " " + isoTonerMax
   TonerMax = os.popen(command).read()
   TonerMax = TonerMax.split("\n")
   TonerMax = TonerMax[:4]
   for i, s in enumerate(TonerMax):
       TonerMax[i] = s[s.find(":")+1:]

   command = "snmpwalk -v 1 -c public " + Printer + " " + isoTonerLevel
   TonerLevel = os.popen(command).read()
   TonerLevel = TonerLevel.split("\n")
   TonerLevel = TonerLevel[:4]
   for i, s in enumerate(TonerLevel):
       TonerLevel[i] = s[s.find(":")+1:]

   command = "snmpwalk -v 1 -c public " + Printer + " " + isoTonerColour
   TonerColour = os.popen(command).read()
   TonerColour = TonerColour.split("\n")
   for i, s in enumerate(TonerColour):
       TonerColour[i] = s[s.find(":")+1:]

   command = "snmpget -v 1 -c public " + Printer + " " + isoPageCount
   pageCount = os.popen(command).read()
   pageCount = pageCount[pageCount.find(":")+1:]
   
   command = "snmpwalk -v 1 -c public " + Printer + " " + isoErrors
   prnErrors = os.popen(command).read()
   prnErrors = prnErrors.split("\n")
   for i, s in enumerate(prnErrors):
       prnErrors[i] = s[s.find(":")+1:]
       prnErrors[i] = prnErrors[i].strip()
       prnErrors[i] = prnErrors[i].replace('"', "")
       if prnErrors[i] == "":
           del prnErrors[i]
   
   errorCount = 0
   warningCount = 0
   if len(prnErrors) > 0:
       for e in prnErrors:
           if e in MFDWarning:
               headerClass = "headerWarning"
           else:
               errorCount += 1
       if errorCount > 0:
           headerClass = "headerError"
   else:
       headerClass = "headerOk"

   

   print ''
   print "" + prnName + " : " + Printer + ""
   
   print "
Toner Levels"
   for i, s in enumerate(TonerColour[:4]):
       tLevel = TonerLevel[i]
       tLevel = tLevel[tLevel.find(":")+1:].strip()
       tMax = TonerMax[i]
       tMax = tMax[tMax.find(":")+1:].strip()
       
       tonerlevel = 100 * int(tLevel) / int(tMax)
       tonerlevelStr = str(tonerlevel) + "%"
       if tonerlevel <= 0:
           tonerlevelStr = "1%"
       print ''
   
   
   print "
Errors: " + str(len(prnErrors)) + ""
   print ""
   for Error in prnErrors:
       print "" + Error + ""
   print ""
   print "
Page Count " + pageCount + ""
   print ""    
   x = x + 1
   if x == 4:
       print ""
       x = 0

Posted

Hi sorry just wondering if u can help me implement this , ive downloaded the code above but i am getting the following error trying run it , i would be most appreciated if you could help

 

Untitled.png

Posted

It sounds like it's not reading the variables from the printer correctly.

 

The following variables are unique to our Lexmark MFD's you will need to find the appropriate values for your own devices.

 

isoName = "iso.3.6.1.2.1.1.6.0"
isoMessage = "iso.3.6.1.2.1.43.16.5.1.2.1.1"
isoErrors = "iso.3.6.1.2.1.43.18.1.1.8"
isoTonerMax = "iso.3.6.1.2.1.43.11.1.1.8.1"
isoTonerLevel = "iso.3.6.1.2.1.43.11.1.1.9.1"
isoTonerColour = "iso.3.6.1.2.1.43.12.1.1.4.1"
isoPageCount = "iso.3.6.1.2.1.43.10.2.1.4.1.1"

 

If you run the following command from a Linux machine you will get a list of all available SNMP details. This will write all the details to 'printer.txt' it's then a case of finding the correct values and matching them to the ISO address.

 

snmpwalk -v -1 -c public 10.242.229.160 > printer.txt

  • Thanks 1
Posted

HTML file calls the python script. The apache server is configured to use Python as CGI. It uses the jQuery load function to fetch the html output from the Python script and adds it onto the #content div.

 


   MFD Status Page
   
   
   <br />
        $().ready( function() {<br />
            $("#content").load("http://your-address.co.uk/cgi-bin/mfdStatus2.cgi", function() {<br />
                $("#content").trigger('create');<br />
            });<br />
<br />
            var currentTime = new Date();<br />
            var day = currentTime.getDay();<br />
            var month = currentTime.getMonth();<br />
            var year = currentTime.getYear();<br />
            var hours = currentTime.getHours();<br />
            var minutes = currentTime.getMinutes();<br />
            var seconds = currentTime.getSeconds();<br />
            var timestamp = "Last Update: " + hours + ":" + minutes + ":" + seconds<br />
            $("#TimeStamp").text(timestamp);<br />
            <br />
            setTimeout(arguments.callee, 10000);<br />
        });<br />
    



   
       
           MFD Status Page
       
       
           
       
       
       
           

       
   


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...