Web Scraping Nagios
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: Tcl, tDOM, Web Scraping