manual:appendix:preprocessing:javascript:javascript_objects

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
manual:appendix:preprocessing:javascript:javascript_objects [2020/06/19 10:31]
marinagen removed
— (current)
Line 1: Line 1:
-==== Additional Javascript objects ==== 
  
-=== Overview === 
- 
-This section describes Zabbix additions to the Javascript language implemented with Duktape. 
- 
-=== Built-in objects === 
- 
-**Zabbix** 
- 
-The Zabbix object provides interaction with the internal Zabbix functionality. 
- 
-^Method^Description^ 
-|''​Log(loglevel,​ message)'' ​ |Writes <​message>​ into Zabbix log using <​loglevel>​ log level (see configuration file DebugLevel parameter). ​ | 
- 
-Example: 
- 
-  Zabbix.Log(3,​ "this is a log entry written with '​Warning'​ log level"​) 
- 
-**CurlHttpRequest** 
- 
-This object encapsulates cURL handle allowing to make simple HTTP requests. Errors are thrown as exceptions. 
- 
-^Method^Description^ 
-|''​AddHeader(name,​ value)'' ​ |Adds HTTP header field. This field is used for all following requests until cleared with the ClearHeader() method. ​ | 
-|''​ClearHeader()'' ​          ​|Clears HTTP header. If no header fields are set CurlHttpRequest will set Content-Type to application/​json if the data being posted is json formatted and text/plain otherwise. ​ | 
-|''​Get(url,​ data)'' ​         |Sends HTTP GET request to the URL with optional //data// payload and returns the response. ​ | 
-|''​Put(url,​ data)'' ​         |Sends HTTP PUT request to the URL with optional //data// payload and returns the response. ​ | 
-|''​Post(url,​ data)'' ​        ​|Sends HTTP POST request to the URL with optional //data// payload and returns the response. ​ | 
-|''​Delete(url,​ data)'' ​      ​|Sends HTTP DELETE request to the URL with optional //data// payload and returns the response. ​ | 
-|''​Status()'' ​               |Returns the status code of the last HTTP request. ​ | 
-|''​SetProxy(proxy)'' ​        |Sets HTTP proxy to %%"​%%proxy%%"​%% value. If this parameter is empty then no proxy is used.  | 
- 
- 
-Example: 
- 
-<code java> 
-try { 
-    Zabbix.Log(4,​ 'jira webhook script value='​+value);​ 
-  ​ 
-    var result = { 
-        '​tags':​ { 
-            '​endpoint':​ '​jira'​ 
-        } 
-    }, 
-    params = JSON.parse(value),​ 
-    req = new CurlHttpRequest(),​ 
-    fields = {}, 
-    resp; 
-  ​ 
-    req.AddHeader('​Content-Type:​ application/​json'​);​ 
-    req.AddHeader('​Authorization:​ Basic '​+params.authentication);​ 
-  ​ 
-    fields.summary = params.summary;​ 
-    fields.description = params.description;​ 
-    fields.project = {"​key":​ params.project_key};​ 
-    fields.issuetype = {"​id":​ params.issue_id};​ 
-    resp = req.Post('​https://​tsupport.zabbix.lan/​rest/​api/​2/​issue/',​ 
-        JSON.stringify({"​fields":​ fields}) 
-    ); 
-  ​ 
-    if (req.Status() != 201) { 
-        throw '​Response code: '​+req.Status();​ 
-    } 
-  ​ 
-    resp = JSON.parse(resp);​ 
-    result.tags.issue_id = resp.id; 
-    result.tags.issue_key = resp.key; 
-} catch (error) { 
-    Zabbix.Log(4,​ 'jira issue creation failed json : '​+JSON.stringify({"​fields":​ fields})); 
-    Zabbix.Log(4,​ 'jira issue creation failed : '​+error);​ 
-  ​ 
-    result = {}; 
-} 
-  ​ 
-return JSON.stringify(result);​ 
-</​code>​