Script items can be used to collect data by executing a user-defined JavaScript code with the ability to retrieve data over HTTP/HTTPS. In addition to the script, an optional list of parameters (pairs of name and value) and timeout can be specified.
This item type may be useful in data collection scenarios that require multiple steps or complex logic. As an example, a Script item can be configured to make an HTTP call, then process the data received in the first step in some way, and pass transformed value to the second HTTP call.
Script items are processed by Zabbix server or proxy pollers.
In the Type field of item configuration form select Script then fill out required fields.
All mandatory input fields are marked with a red asterisk.
The fields that require specific information for Script 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. Built-in macros {HOST.CONN}, {HOST.DNS}, {HOST.HOST}, {HOST.IP}, {HOST.NAME}, {ITEM.ID}, {ITEM.KEY}, {ITEM.KEY.ORIG} and user macros are supported. |
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, it may perform HTTP GET, POST, PUT and DELETE requests and has control over HTTP headers and request body. See also: Additional JavaScript objects, JavaScript Guide. |
Timeout | JavaScript execution timeout (1-60s, default 3s). Time suffixes are supported, e.g. 30s, 1m. |
Collect the content of https://www.zabbix.com/release_notes:
Use the {HOST.CONN} macro as parameter value and get a response with expanded macro:
var request = new CurlHttpRequest();
return request.Post("https://postman-echo.com/post", JSON.parse(value));
Collect the content of both https://www.zabbix.com and https://www.zabbix.com/release_notes:
var request = new CurlHttpRequest();
return request.Get("https://www.zabbix.com") + request.Get("https://www.zabbix.com/release_notes");
Add the "Log test" entry to the Zabbix server log and receive the item value "1" in return: