manual:config:items:preprocessing:javascript

Differences

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

Link to this comparison view

Next revision
Previous revision
manual:config:items:preprocessing:javascript [2020/06/19 09:36]
marinagen [ZBX-17348] page moved from appendixes
manual:config:items:preprocessing:javascript [2021/03/17 12:37] (current)
martins-v moving global javascript function info (ZBX-18592)
Line 1: Line 1:
-==== 4 Javascript ​preprocessing ====+==== 4 JavaScript ​preprocessing ====
  
 === Overview === === Overview ===
  
-This section provides details of preprocessing by Javascript.+This section provides details of preprocessing by JavaScript.
  
-=== Javascript ​preprocessing ===+=== JavaScript ​preprocessing ===
  
-Javascript ​preprocessing is done by invoking JavaScript function with a single parameter '​value'​ and user provided function body. The preprocessing step result is the value returned from this function, for example, to perform Fahrenheit to Celsius conversion user must enter:+JavaScript ​preprocessing is done by invoking JavaScript function with a single parameter '​value'​ and user provided function body. The preprocessing step result is the value returned from this function, for example, to perform Fahrenheit to Celsius conversion user must enter:
  
   return (value - 32)  * 5 / 9   return (value - 32)  * 5 / 9
Line 35: Line 35:
 </​code>​ </​code>​
  
-Each script has a 10 second execution timeout (depending on the script it might take longer for the timeout to trigger); exceeding it will return error. ​Also a 10 megabyte heap limit is enforced.+Each script has a 10 second execution timeout (depending on the script it might take longer for the timeout to trigger); exceeding it will return error. ​A 64 megabyte heap limit is enforced.
  
 The JavaScript preprocessing step bytecode is cached and reused when the step is applied next time. Any changes to the item's preprocessing steps will cause the cached script to be reset and recompiled later. The JavaScript preprocessing step bytecode is cached and reused when the step is applied next time. Any changes to the item's preprocessing steps will cause the cached script to be reset and recompiled later.
Line 42: Line 42:
  
 JavaScript preprocessing is implemented with Duktape (https://​duktape.org/​) JavaScript engine. JavaScript preprocessing is implemented with Duktape (https://​duktape.org/​) JavaScript engine.
 +
 +See also: [[:​manual/​config/​items/​preprocessing/​javascript/​javascript_objects|Additional JavaScript objects and global functions]]
  
 == Using macros in scripts == == Using macros in scripts ==
Line 54: Line 56:
 return (!isNaN(threshold) && value > threshold) ? threshold : value; return (!isNaN(threshold) && value > threshold) ? threshold : value;
 </​code>​ </​code>​
- 
- 
-=== Global Javascript functions === 
- 
-Additional global Javascript functions have been implemented with Duktape: 
- 
-  * btoa(string) - encodes string to base64 string 
-  * atob(base64_string) - decodes base64 string 
- 
-<code java> 
-try { 
-    b64 = btoa("​utf8 string"​);​ 
-    utf8 = atob(b64); 
- 
-catch (error) { 
-    return {'​error.name'​ : error.name, '​error.message'​ : error.message} 
-} 
-</​code>​ 
- 
-See also: [[:​manual/​config/​items/​preprocessing/​javascript/​javascript_objects|Additional Javascript objects]]