plexer (17th October 2008)

I'm trying to create a plugin for nagios to get the consumables status for our Konica K5440dl printers.
I tried a snmpwalk on one and it only goes so far so I was hoping to try and copy the HP 2600 one which uses wget to download the supplies status webpage to a temporary file and then extracts the details from that.
Thats what the downloaded page looks like.Code:<html lang="en-US"> <head> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <meta http-equiv="content-style-type" content="text/css"> <style type="text/css"> <!-- a { color: #000000; text-decoration:none} body { background-color: #FFFFFF } .menu { background-color: #6666FF; color: #FFFFFF } .menu2 { background-color: #9999FF; color: #FFFFFF } .menu3 { background-color: #CCCCFF; color: #000000 } .bar { background-color: #6666FF } --> </style> <title>System - Detail - Consumable</title> </head> <body> <table width="760" cellpadding="0" cellspacing="2"> <tr> <td class="bar" colspan="3"><img src="space.gif" width="756" height="13" ></td> </tr> <tr> <td align="center" valign="top" width="236"> <table width="100" cellpadding="0" cellspacing="0"> <tr><td><img src="space.gif" height="3" ></td></tr> </table> <table width="236" cellspacing="6" cellpadding="4"> <tr> <td class="menu3"> <img src="head_s2.gif" width="8" height="9"> <a href="m_s_smm.htm"><strong>Summary</strong></a> </td> </tr> <tr> <td class="menu"> <img src="head_a1.gif" width="9" height="8"> <strong>Detail</strong> </td> </tr> <tr> <td class="menu3"> <img src="./space.gif" width="15" height="1" ><img src="head_s2.gif" width="8" height="9"> <a href="m_s_dtl1.htm"><strong>Input Tray</strong></a> </td> </tr> <tr> <td class="menu3"> <img src="./space.gif" width="15" height="1" ><img src="head_s2.gif" width="8" height="9"> <a href="m_s_dtl2.htm"><strong>Network</strong></a> </td> </tr> <tr> <td class="menu2"> <img src="./space.gif" width="15" height="1" ><img src="head_a2.gif" width="9" height="10"> <a href="m_s_dtl3.htm"><strong><font color="#FFFFFF">Consumables</font></strong></a> </td> </tr> <tr> <td class="menu3"> <img src="head_s2.gif" width="8" height="9"> <a href="m_s_cnt.htm"><strong>Counter</strong></a> </td> </tr> <tr> <td class="menu3"> <img src="head_s2.gif" width="8" height="9"> <a href="m_s_onl.htm"><strong>Online Assistance</strong></a> </td> </tr> </table> <table cellpadding="0" cellspacing="0" class="bar" width="220"> <tr> <td><img src="space.gif" width="220" height="2" ></td> </tr> </table> </td> <td class="bar" width="2"><img src="space.gif" width="2" height="1" ></td> <td align="center" valign="top" width="516" height="5"> <table border="0" width="520" cellspacing="0" cellpadding="0"> <tr> <td width="7"></td> <td width="510"> <table border="0" cellpadding="5" cellspacing="1" width="510" > <tr> <td height="40" width="197" valign="top"><u><b>Consumables</b></u></td> <td height="40" valign="top"> <p align="center"><u><b>Status</b></u></p></td> <td height="40" valign="top"> </td> <td width="75" height="40" valign="top"><p align="center"><u><b>Max Life</b></u></p></td> </tr> <tr> <td width="197" height="30">Black Toner Cartridge</td> <td width="150" > <table border="1" cellpadding="0" cellspacing="0" width="150" > <tr> <td width="100" height="8"> <table border="0" cellpadding="0" cellspacing="0" width="79" height="8"> <tr> <td width="100" bgcolor="#000000"></td> </tr> </table> </td> </tr> </table> </td> <td valign="bottom" align="left" width="33"><font size="2">53%</font></td> <td width="75" align="center" height="33"> 12000 </td> </tr> <tr> <td width="197" height="30">Cyan Toner Cartridge</td> <td width="150" > <table border="1" cellpadding="0" cellspacing="0" width="150" > <tr> <td width="100" height="8"> <table border="0" cellpadding="0" cellspacing="0" width="1" height="8"> <tr> <td width="100" bgcolor="#00FFFFF"></td> </tr> </table> </td> </tr> </table> </td> <td valign="bottom" align="left" width="33"><font size="2">1%</font></td> <td width="75" align="center" >12000</td> </tr> <tr> <td width="197" height="30">Magenta Toner Cartridge</td> <td width="150"> <table border="1" cellpadding="0" cellspacing="0" width="150"> <tr> <td width="100" height="8"> <table border="0" cellpadding="0" cellspacing="0" width="150" height="8"> <tr> <td width="100" bgcolor="#FF00FF"></td> </tr> </table> </td> </tr> </table> </td> <td valign="bottom" align="left" width="33"><font size="2">100%</font></td> <td width="75" align="center" >12000</td> </tr> <tr> <td width="197" height="30">Yellow Toner Cartridge</td> <td width="150"> <table border="1" cellpadding="0" cellspacing="0" width="150" height="8"> <tr> <td width="100" height="8"> <table border="0" cellpadding="0" cellspacing="0" width="150" height="8"> <tr> <td width="100" bgcolor="#FFFF00"></td> </tr> </table> </td> </tr> </table> </td> <td valign="bottom" align="left" width="33"><font size="2">100%</font></td> <td width="75" align="center" >12000</td> </tr> <tr> <td width="197" height="30">Transfer Roller Unit</td> <td width="150" align="left" >Ready</td> <td valign="bottom" align="left" width="33"></td> <td width="75" align="center" > -</td> </tr> <tr> <td width="197" height="30">Transfer Belt Unit</td> <td width="150" align="left">Ready</td> <td valign="bottom" align="left" width="33"></td> <td width="75" align="center">-</td> </tr> <tr> <td width="197" height="30">Waste Toner Bottle</td> <td width="150" align="left" >Ready</td> <td valign="bottom" align="left" width="33"></td> <td width="75" align="center" >-</td> </tr> </table> <BR> </td> </tr> </table> </td> </tr> <tr> <td class="bar" colspan="3" width="100" height="2"><img src="space.gif" width="1" height="1" ></td> </tr> </table> </body> </html>
If anyone could come up with an idea to split that into values for each toner that would be cool.
Ben

wget http://blah.html && cat blah.html | grep % > output.txt
will put the following into an output.txt file.
Not sure how to strip the html out though, will have a playCode:<td valign="bottom" align="left" width="33"><font size="2">53</font></td> <td valign="bottom" align="left" width="33"><font size="2">1%</font></td> <td valign="bottom" align="left" width="33"><font size="2">100%</font></td> <td valign="bottom" align="left" width="33"><font size="2">100%</font></td>

I then need to do a split on those lines then I suppose?
Ben

pipe the output to awk, then $1, $2, $3 etc to get each column
soCode:awk '{ print $1, $2 }'
Code:wget http://blah.html && cat blah.html | grep % | awk '{ print $1, $2 }'


strips out the first bit of the html, but I cant get sed to remove the latter part. Not sure if its to do with the \ in the html tagCode:wget http://temp.html && cat temp.html | grep % | awk '{ print $5 }' > test.txt && sed -e 's/size="2">/ /' test.txt > test2.txt
Code:53%</font></td> 1%</font></td> 100%</font></td> 100%</font></td>


Thanks for all the suggestions guys looking good.
I just want to end up with some variables that contain the cartridge colour and the corresponding % or just % as long as I know variable1 is black, 2 is cyan I suppose.
Ben


I would suggest learning a bit of perl.. much easier.. then use a few match lines.. but...
try:
wget <whatever> | grep % | cut -d\> -f3 | cut -d\< -f1
If you really want it doing nicely I will perl it for you and post here as an example?

Yes please Tom then once I can get the check working I'll add that.
Ben

Cracked it.
Probably not the cleverest or neatest way, but it works.
add > filename.txt to output to a file.Code:wget http://temp.html && cat temp.html | grep % | awk -F\> '{print $3}' | awk -F\< '{print $1}'
Will list 1 per line, black, cyan, magenta, yellow.
Code:Saving to: `temp.html' 100%[============================================>] 6,315 in 0.04s 2008-10-16 18:26:37 (167 KB/s) - `temp.html' saved [6315/6315] 53% 1% 100% 100%

plexer (17th October 2008)
plexer (17th October 2008)


tom@white-elephant:/tmp$ cat plex.txt | ./plex.pl
Black: 53
Cyan: 1
Magenta: 100
Yellow: 100
where "plex.txt" is your HTML.
Could be done on the commandline but this is neater IMO.
Next step: remove wget, and go with LWP::Simple
plexer (17th October 2008)

Thanks Tom.
I can't seem to open that it just comes out gobbledegook when I un compress it.
Ben
There are currently 1 users browsing this thread. (0 members and 1 guests)