Zabbix: running POST tests with web scenarios

2016 note: Zabbix 3 has just been released. I haven't looked at it yet so this information may not be applicable to it.

Zabbix, the swiss army knife of monitoring tools, has some pretty nifty web scenario testing to help you with monitoring your precious web application.

So you've got a web application up and running and it's working well. A number of factors can conspire to cause issues with parts of your web application -  third party services going down or getting slow, network issues or system issues. If you use Zabbix for keeping an eye on things you may be interested to know that its Web Scenario configuration is very, very powerful and can perform HTTP POST while retaining sessions.

With the correct scenarios in place, you'll get notifications of issues before they become issues for lots of people visiting your website.

The key elements here are an understanding of the Web Scenario 'Post' and 'Variable' fields:

Post: HTTP POST variables in a query string format for use on a Scenario step. Importantly variables are not URL encoded before sending, so you'll need to URL encode them yourselves. You can also send query strings containing indexes such as foo[bar]. In Zabbix 2.4, this field supports {macros} and you can reuse variables from previous steps in following steps OR the variables set at the base Scenario configuration level.

Example field value:  search[foo]=Bar&search[go]=1&page=next

Variables: This field allows you to check a response document for and pass values found via  a regex into a {macro} variable. For instance, if your response document is JSON encoded  text such as "foo":"898743"  you can use the following regex to grab the value 898743 for use in later steps:
Example field value: {foo}=regex:"foo":"([0-9]+)"

Concrete Example

Let's look at a concrete example such as a POST to your site returning a JSON encoded response which the application reacts to and produces a page accessible via a URL. We'll use the response from the POST to bring up a following page and check for a value.

  1. Set up your Scenario in the Zabbix dashboard Configuration > Host

  2. You should see a list of hosts, in the host of choice, click  the 'Web' link in the Web column.

  3. Hit 'Create Scenario' button over on the far right (why are Zabbix buttons always out of context ?)

  4. Enter a Name, Application, User Agent and any variables you'd like available for all steps in the format {macro}=value or {macro}=regex:pattern. Worth noting that wariables in steps overwrite variables of the same name from previous steps and global variables,

  5. On the Steps tab, create a step with 'Add' and enter the Name and URL (e.g In the Post field enter the values you would like to POST in a query string format.

  6. Our example response document will be JSON encoded and on success will return the following text containing an integer id e.g {"document":"9137917213"} so in the Variables field enter {document}=regex:"document":"([0-9]+)". Add a 200 in the Response Code field.

  7. Save the step and add a new one. For the URL in this step, use your {document} value to check for a 200 OK from a followup page: e.g{document}/

  8. In this step, add 200 for a Response Code. In this example the document URL will contain a string in the footer of the page showing the document ID so in the Required string  field add Document #{document}

  9. Click Save and the click Update, if all goes well you should see a graph with timing of your two steps or if not an error message saying what went wrong. Zabbix will alert when one of the steps fails and if Step 1 fails then Step 2 will not proceed.

This is fairly powerful stuff and you can use it to test for all kinds of responses after a post such as a 301 Redirect to another page containing a required string. You can use it for testing site authentication and logging out or even shopping cart processing

If you get stuck or the response values are not as expected, check the following:

  1. Check your regex patterns - are they correct? Zabbix regexes are POSIX extended. Maybe you are missing a ) or ] ?

  2. Tail your access logs and filter the output (using | grep) by your Zabbix server IP address if you have access to them - you may see where the request is going wrong or a funky URL that is unexpected.

  3. Point the scenario at your dev platform and turn debugging of POST variables on, logging them to a file for instance.

  4. Use curl --data and wget to run requests on the shell and see if you get expected results.

  5. Do you need to use basic auth or work around a self signed certificate ? If so, check the Authentication tab for the Scenario for relevant cURL options you can complete.

Useful resources:

Post your comment


No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments