Extended Monitoring Guide

  • Docs Home
  • Community Home

10. ZenWebTx Extensions to twill

ZenWebTx adds several commands to the standard twill vocabulary.

10.1. twilltiming

twilltiming sets timers in a set of twill commands. If you then define a data point for this timer, you can graph and set thresholds on this timer value.

Use the following command to start a new timer:

startTimer myTimerName

and then, to output the value:

printTimer myTimerName

Timer values should be output only once. So, to output the time from the start of the script to more than one point in the script, you must use more than one timer. For example:

startTimer wwwZenossCom
startTimer bothPages
go http://www.zenoss.com
printTimer wwwZenossCom
startTimer communityPage
follow "Community"
printTimer communityPage
printTimer bothPages

To use these timers in Zenoss, create data points with the same name as the timers. In this example you could create data points named wwwZenossCom, communityPage, and bothPages. You can then use these data points in Zenoss thresholds and graph definitions.

10.2. twillextract

twillextract extracts numeric values from Web pages during the transaction. To use twillextract, use the following command to match the given regular expression to the current page:

extract <dataName> <regularExpression>

The value 1 or 0 is assigned to dataName depending on whether the regular expression matched or not.

Additionally, you can use Python's regular expression substring-matching syntax to extract substrings of the matched text. For example, http://www.zenoss.com contains a copyright notice near the bottom that looks like "Copyright (c) 2005-2009 Zenoss, Inc." The following twill commands use a regular expression to grab the second year from that notice:

go http://www.zenoss.com
extract copyright "(?P<firstYear>[0-9]*)-(?P<secondYear>[0-9]*) Zenoss, Inc."

(?P<name>.....) is Python syntax for naming that particular part of the regular expression. The value extracted from that part of the matching text is given the name from the extract command, then a dash, then the name from the sub-pattern. In this example, copyright gets a value of 1 or 0 depending on whether the pattern was found on the page or not, and copyright-firstYear and copyright-secondYear get the values extracted from the matched text. To use these values in Zenoss you must create data points in the WebTx data source with the same name as those you used in the extract command. In this case you would create data points named copyright, copyright-firstYear and copyright-secondYear. You can then create graph definitions and thresholds for these data points.

10.3. twillxpathextract

Zenoss uses the twillxpathextract command to extract numeric values from XML documents. To use twillxpathextract, add the following command to match and extract data using the given XPath expression:

xpathextract <dataName> <xpath>

where xpathextract is the command name, <dataName> is the name of the data point to which the value will map, and <xpath> is the xpath used to retrieve the data.

When applied to an XML document, the XPath expression must return a numeric value. This value is then assigned to the dataName data point.

10.4. ignorescripts

ignorescripts strips javascript from visited pages before they are processed by twill. Although twill ignores script tags, it is possible for scripts to include strings that twill will interpret as HTML tags. Including the command extend_with ignorescripts near the top of your twill commands will cause all script tags to be stripped, thereby avoiding this issue.