+ Post New Thread
Results 1 to 9 of 9
Web Development Thread, [Python] Printer/MFD Monitor in Coding and Web Development; Hi, Thought I would share and ask for opinions. This is a printer monitor I created which we are finding ...
  1. #1

    Join Date
    Nov 2012
    Posts
    34
    Thank Post
    1
    Thanked 5 Times in 4 Posts
    Rep Power
    4

    Lightbulb [Python] Printer/MFD Monitor

    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.



    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?

  2. 2 Thanks to m1k3r:

    fiza (22nd May 2014), victory2012 (22nd May 2014)

  3. #2

    Join Date
    Nov 2010
    Posts
    452
    Thank Post
    59
    Thanked 69 Times in 59 Posts
    Rep Power
    34
    I'd like to see that code. Is it on github?

  4. #3

    Join Date
    May 2012
    Posts
    160
    Thank Post
    20
    Thanked 26 Times in 17 Posts
    Rep Power
    9
    oooooo i like that please share :-)

  5. #4

    Join Date
    Nov 2012
    Posts
    34
    Thank Post
    1
    Thanked 5 Times in 4 Posts
    Rep Power
    4
    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 <div>


    Code:
    #!/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 '<div class = "printerBlock">'
        print "<h2 class = '" + headerClass + "'><a href='http://" + Printer + "' target='_blank'>" + prnName + " : " + Printer + "</a></h2>"
        
        print "<p><b>Toner Levels</b></p>"
        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 '<div class="tonerPlace"><div class = "tonerBlock" id = ' + TonerColour[i] + ' style="width: ' + tonerlevelStr + ';"></div></div>'
        
        
        print "<p><b>Errors: " + str(len(prnErrors)) + "</b></p>"
        print "<ul>"
        for Error in prnErrors:
            print "<li>" + Error + "</li>"
        print "</ul>"
        print "<p>Page Count " + pageCount + "</p>"
        print "</div>"    
        x = x + 1
        if x == 4:
            print "<div style='clear:both'></div>"
            x = 0

  6. #5

    Join Date
    May 2012
    Posts
    160
    Thank Post
    20
    Thanked 26 Times in 17 Posts
    Rep Power
    9
    im sorry can you help me how do i get this running? and showing like the first pic?

  7. #6

    Join Date
    May 2012
    Posts
    160
    Thank Post
    20
    Thanked 26 Times in 17 Posts
    Rep Power
    9
    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

  8. #7

    Join Date
    Nov 2012
    Posts
    34
    Thank Post
    1
    Thanked 5 Times in 4 Posts
    Rep Power
    4
    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.

    Code:
    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.

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

  9. Thanks to m1k3r from:

    victory2012 (22nd May 2014)

  10. #8

    Join Date
    May 2012
    Posts
    160
    Thank Post
    20
    Thanked 26 Times in 17 Posts
    Rep Power
    9
    thats brilliant thanks so much i shall try this, are u able post the html file for me as i am at a loss of how to do that.

  11. #9

    Join Date
    Nov 2012
    Posts
    34
    Thank Post
    1
    Thanked 5 Times in 4 Posts
    Rep Power
    4
    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.

    Code:
    <html>
    <head>
        <title>MFD Status Page</title>
        <link rel = "stylesheet" type = "text/css" href = "style.css">
        <script src="jquery.js" type="text/javascript"></script>
        <script>
            $().ready( function() {
                $("#content").load("http://your-address.co.uk/cgi-bin/mfdStatus2.cgi", function() {
                    $("#content").trigger('create');
                });
    
                var currentTime = new Date();
                var day = currentTime.getDay();
                var month = currentTime.getMonth();
                var year = currentTime.getYear();
                var hours = currentTime.getHours();
                var minutes = currentTime.getMinutes();
                var seconds = currentTime.getSeconds();
                var timestamp = "Last Update: " + hours + ":" + minutes + ":" + seconds
                $("#TimeStamp").text(timestamp);
                
                setTimeout(arguments.callee, 10000);
            });
        </script>
    </head>
    <body>
    
        <div id = "container">
            <div id = "header">
                <h1>MFD Status Page</h1>
            </div>
            <div id = "content">
                
            </div>
            <div style="clear:both;"></div>
            <div id = "footer">
                <p id="TimeStamp"></p>
            </div>
        </div>
    
    </body>
    </html>

SHARE:
+ Post New Thread

Similar Threads

  1. Printer Status Monitoring
    By Quackers in forum Windows
    Replies: 4
    Last Post: 15th September 2011, 01:11 PM
  2. Free printer quota / monitoring software
    By Bruce123 in forum Network and Classroom Management
    Replies: 6
    Last Post: 19th January 2009, 04:36 PM
  3. Monitoring Printers with Nagios
    By Lee_K_81 in forum Wireless Networks
    Replies: 25
    Last Post: 14th May 2008, 02:52 PM
  4. Printer monitoring
    By timbo343 in forum Windows
    Replies: 20
    Last Post: 19th October 2006, 09:55 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •