Tikhon Uskov , ingénieur de l'équipe d'intégration Zabbix
Zabbix — , . Zabbix Actions . , , , , .
JavaScript Zabbix
2019 Zabbix 4.2 JavaScript. , - , Zabbix , , Zabbix , Zabbix JavaScript. , Zabbix 3.4, .
Zabbix 4.4, JavaScript, — Webhook, Zabbix .
JavaScript Duktape
JavaScript Duktape? :
- Lua – Lua 5.1
- Lua – LuaJIT
- Javascript – Duktape
- Javascript – JerryScript
- Embedded Python
- Embedded Perl
, , , . JavaScript Duktape.
performance testing
Duktape:
— ECMAScript E5/E5.1
— Zabbix Duktape:
- Zabbix.log() — Zabbix Server , , , Webhook .
- CurlHttpRequest() — HTTP- , Webhook.
- atob() btoa() — Base64.
. Duktape ACME. Zabbix 2015 . , .
JavaScript
JavaScript : , .
, .
, -, . — , , , .
. , , , , valueOf toString. valueOf toString. valueOf , .
valueOF. , toString. toString , valueOf , . toString, , . .
, 'obj' toString,
`var obj = { toString() { return "200" }}`
toString , :
`obj + 1 // '2001'`
`obj + 'a' // ‘200a'`
toString, , .
`var obj = { toString() { return 200 }}`
`obj + 1 // '2001'`
, , , .
`obj + 'a' // ‘200a'`
JavaScript.
toString , 1.
, 3, 4.
(==) toString . , . (===).
. .
, , Webhook , , , .
Webhook Media
2019 2020 Zabbix Webhooks « », Zabbix.
- Discord
- Jira
- Jira Service Desk
- Mattermost
- Microsoft Teams
- Opsgenie
- OTRS
- Pagerduty
- Pushover
- Redmine
- ServiceNow
- SINGL4
- Slack
- Telegram
- Zammad
- Zendesk
Preprocessing
- JavaScript , Zabbix .
- Zabbix JavaScript, - , value ( , ).
- , return.
- .
- , . 10 10 .
. - 10 , 1 «» Zabbix. JavaScript (dummy items), .
zabbix_js:
`zabbix_js -s *script-file -p *input-param* [-l log-level] [-t timeout]`
`zabbix_js -s script-file -i input-file [-l log-level] [-t timeout]`
`zabbix_js -h`
`zabbix_js -V`
1
.
: .
, . — (), .
:
- .
- «» , , . , .
, , ( — ).
, , , 30 , 29 Zabbix «», . . , .
— JavaScript, :
`return (value - 32) * 5 / 9;`
, , .
`return (parseInt(value) + parseInt("{$EXAMPLE.MACRO}"));`
, , , - , , , value . , .
`return (value + "{$EXAMPLE.MACRO}");`
, . parseInt(), , parseFloat(), , number, .
2
.
: "Feb 12 12:33:56 2022 GMT".
ECMAScript5 Date.parse() ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ). MMM DD YYYY HH:mm:ss ZZ
: , . Duktape.
:
, ( — , ).
value split. , , , 0, . split(0) — , split(1) — , split(2) — . . .
`var split = value.split(' '),`
- ( ) ( 0 11). , ( 1). , , . slice() — , ( ).
`MONTHS_LIST = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],`
`month_index = ('0' + (MONTHS_LIST.indexOf(split[0]) + 1)).slice(-2),`
- ISO .
`ISOdate = split[3] + '-' + month_index + '-' + split[1] + 'T' + split[2],`
— 1970 - . , Zabbix {Date} {Time}, .
- JavaScript Unix Timestamp , .
`now = Date.now();`
- , Zabbix.
`return parseInt((Date.parse(ISOdate) - now) / 1000);`
'last<' , , , , . , , .
. parseInt() return, , , . parseFloat() .