Wednesday, September 15, 2010

Web Scraping Nagios

I have not been web scape for quite a while. Recently I need to rearrange and summarise Nagios data so as to present the monitoring info into some form of management dashboard.

With Tcl and it's tdom extension, I am able to web scrape with ease. However, one of the challenges is that I need to summarise all the disk partitions utilisation criticality as a single service. My initial XPath is to go through all 26 partitions (Disks A to Z)

$branch selectNodes {td/a[@class='statusCRITICAL'][
    text()='WINDISK-A' or text()='WINDISK-B' or text()='WINDISK-C' or
    text()='WINDISK-D' or text()='WINDISK-E' or text()='WINDISK-F' or
    text()='WINDISK-G' or text()='WINDISK-H' or text()='WINDISK-I' or
    text()='WINDISK-J' or text()='WINDISK-K' or text()='WINDISK-L' or
    text()='WINDISK-M' or text()='WINDISK-N' or text()='WINDISK-O' or
    text()='WINDISK-P' or text()='WINDISK-Q' or text()='WINDISK-R' or
    text()='WINDISK-S' or text()='WINDISK-T' or text()='WINDISK-U' or
    text()='WINDISK-V' or text()='WINDISK-W' or text()='WINDISK-X' or
    text()='WINDISK-Y' or text()='WINDISK-Z'
]}

If you read the XPath specification, you will find the starts-with() function can be used in this scenario. With a single function, I can avoid all the above messy syntax.

$branch selectNodes {td/a[@class='statusCRITICAL'][starts-with(.,'WINDISK-')]}

Labels: , ,

1 Comments:

Blogger Carly Fiorina said...

Web scraping is a computer software technique of extracting information from websites. Web Scraping scripts helps a person to see a web site with a browser. Thanks..........

Extract Data From Web

12:09 PM  

Post a Comment

<< Home