In several previous articles in the Zabbix 2.2 series we already discussed several improvements for web monitoring – the ability to template it, customise the amount of retries and the ability to specify an HTTP proxy on the scenario level. There’s more – in 2.2 it will also be possible to parse content from a page and reuse it in further scenario steps.
Articles in 2.2 feature series:
- Part 1 – Automatic database upgrading
- Part 2 – Templated web monitoring
- Part 3 – Web scenario retries
- Part 4 – HTTP proxy for web monitoring
- Part 5 – Better value mapping
- Part 6 – Returning values from webpages
- Part 7 – Value extracting from logfiles and more
- Part 8 – Reusing content in web monitoring
- Part 9 – No more full page reload in latest data
- Part 10 – Support of loadable modules
- Part 11 – SNMP monitoring improvements
EDIT: specification was changed, prefix will be case sensitive after all
While the built-in Zabbix web monitoring allows to create scenarios with steps, can be used over Zabbix proxies and has been extended quite a lot for 2.2, there’s one more case where it was not that easy to use – if for some reason there was a need to reuse part of the page in subsequent scenario steps. A common need being session ID that has to be passed in all further operations. There probably are other cases, too.
Current web monitoring variables
It is already possible to use variables in the built-in web monitoring – for example, on the scenario level one might have a variable:
{hostid}=131313
This variable could be used in all the steps for GET or POST parameters. See the web monitoring section in the Zabbix manual for more detail.
Retrieving data from a webpage
Zabbix 2.2 will extend this feature by allowing to parse a webpage by a regular expression and store the result in a variable. For this the syntax has been slightly extended – if the variable contents start with a regex: string, the part after the colon will be treated as a regular expression, and the result will be stored in the specified variable. For example:
{hostid}=regex:hostid is ([0-9]+)
Such an expression would match a “hostid is ” string (without quotes), then grab all numbers from it and put them in the {hostid} variable. Important to note:
- the expression must have at least one subgroup
- if there are multiple subgroups, the match from the first one will be used
- same as with other regular expressions, POSIX Extended ones will be used, but here multiline matching is enabled (first in Zabbix)
- regex string is case
insensitivesensitive
The step will fail if:
- there are no subgroups
- there is no match
Specifying variables in steps
Of course, configuring something like that only once per scenario might not be enough, thus it is now possible to specify variables per step, too. In the frontend, a new Variables field has been added to step properties.
- If a variable is configured on the scenario level, it will be used for all steps…
- …but variables in steps will override scenario and previous step variables
This functionality should benefit the monitoring of various pages – even the Zabbix frontend itself, as it uses a session ID, which is required for several operations. Looking at the Zabbix pages, we would observe content like this:
input type="hidden" id="sid" name="sid" value="d48525fb6a01c0c2"
If we would need the ID, the variable and regular expression definition would look like this:
{zabbixsession}=regex:name="sid" value="([0-9a-z])"
And again, if you plan to use this feature – do test it as soon as possible 🙂