You are viewing documentation for the development version, it may be incomplete.
Join our translation project and help translate Zabbix documentation into your native language.

19 Browser items

Overview

Browser items allow monitoring complex websites and web applications using a browser.

The support of Browser items is currently experimental.

Browser items collect data by executing a user-defined JavaScript code and retrieving data over HTTP/HTTPS. This item can simulate such browser-related actions as clicking, entering text, navigating through web pages, and other user interactions with websites or web applications.

In addition to the script, an optional list of parameters (pairs of name and value) and timeout can be specified.

The item partially implements the W3C WebDriver standard with either Selenium Server or a plain WebDriver (for example, ChromeDriver) as a web testing endpoint. For the item to work, set the endpoint in the Zabbix server/proxy configuration file WebDriverURL parameter.

Browser items are executed and processed by Zabbix server or proxy browser pollers. If necessary, you can adjust the number of pre-forked instances of Browser item pollers in the Zabbix server/proxy configuration file StartBrowserPollers parameter.

For monitoring complex websites and web applications, the Website by Browser template is available as an out-of-the-box template.

Configuration

If using ChromeDriver as the web testing endpoint, see Securing Considerations.

In the Type field of item configuration form, select Browser and then fill out the required fields.

All mandatory input fields are marked with a red asterisk.

The fields that require specific information for Browser items are:

Field Description
Key Enter a unique key that will be used to identify the item.
Parameters Specify the variables to be passed to the script as the attribute and value pairs.
User macros are supported. To see which built-in macros are supported, do a search for "Browser-type item" in the supported macro table.
Script Enter JavaScript code in the block that appears when clicking in the parameter field (or on the view/edit button next to it). This code must provide the logic for returning the metric value.
The code has access to all parameters, all additional JavaScript objects and Browser item JavaScript objects added by Zabbix.
See also: JavaScript Guide.
Timeout JavaScript execution timeout (1-600s; exceeding it will return an error).
Note that depending on the script, it might take longer for the timeout to trigger.
For more information on the Timeout parameter, see general item attributes.

Examples

Default script

The following script:

  1. Initiates a browser session.
  2. Navigates to a specified URL.
  3. Collects performance entries and session statistics, and returns them as a JSON string.

In the Script field, enter:

var browser = new Browser(Browser.chromeOptions());
       
       try {
           browser.navigate("http://example.com");
           browser.collectPerfEntries();
       }
       finally {
           return JSON.stringify(browser.getResult());
       }
Check Zabbix login

The following script:

  1. Initiates a browser session.
  2. Navigates to the Zabbix login page.
  3. Enters the username "Admin" and password "zabbix".
  4. Finds and clicks the login button.
  5. Finds and clicks the logout button.
  6. Collects performance data before and after login, as well as after logout.
  7. Handles errors by capturing error messages and a screenshot.
  8. Returns the collected results as a JSON string.

In the Script field, enter:

var browser, result;
       
       browser = new Browser(Browser.chromeOptions());
       
       try {
           browser.navigate("http://example.com/zabbix/index.php");
           browser.collectPerfEntries("open page");
       
           var el = browser.findElement("xpath", "//input[@id='name']");
           if (el === null) {
               throw Error("cannot find name input field");
           }
           el.sendKeys("Admin");
       
           el = browser.findElement("xpath", "//input[@id='password']");
           if (el === null) {
               throw Error("cannot find password input field");
           }
           el.sendKeys("zabbix");
       
           el = browser.findElement("xpath", "//button[@id='enter']");
           if (el === null) {
               throw Error("cannot find login button");
           }
           el.click();
       
           browser.collectPerfEntries("login");
       
           el = browser.findElement("link text", "Sign out");
           if (el === null) {
               throw Error("cannot find logout button");
           }
           el.click();
       
           browser.collectPerfEntries("logout");
       
           result = browser.getResult();
       }
       catch (err) {
           if (!(err instanceof BrowserError)) {
               browser.setError(err.message);
           }
           result = browser.getResult();
           result.error.screenshot = browser.getScreenshot();
       }
       finally {
           return JSON.stringify(result);
       }
Initialize browser

The following script:

  1. Initializes a browser session for the available browser based on the first matching browser in the order specified within the script.
  2. Defines browser capabilities, including page load strategy and options specific to each browser, such as the headless mode for Chrome, Firefox, and Microsoft Edge browsers.

Note that to set up WebDriver instances, you'll need additional test scripts or scenarios to interact with the websites or web application under test.

In the Script field, enter:

var browser = new Browser({
           "capabilities":{
               "firstMatch":[
                   {
                       "browserName":"chrome",
                       "pageLoadStrategy":"normal",
                       "goog:chromeOptions":{
                           "args":[
                               "--headless=new"
                           ]
                       }
                   },
                   {
                       "browserName":"firefox",
                       "pageLoadStrategy":"normal",
                       "moz:firefoxOptions":{
                           "args":[
                               "--headless"
                           ]
                       }
                   },
                   {
                       "browserName":"MicrosoftEdge",
                       "pageLoadStrategy":"normal",
                       "ms:edgeOptions":{
                           "args":[
                               "--headless=new"
                           ]
                       }
                   },
                   {
                       "browserName":"safari",
                       "pageLoadStrategy":"normal"
                   }
               ]
           }
       });