├── .editorconfig ├── .gitignore ├── docs ├── fonts │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.woff │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ └── OpenSans-LightItalic-webfont.woff ├── scripts │ ├── linenumber.js │ └── prettify │ │ ├── lang-css.js │ │ ├── Apache-License-2.0.txt │ │ └── prettify.js ├── styles │ ├── prettify-jsdoc.css │ ├── prettify-tomorrow.css │ └── jsdoc-default.css ├── index.html ├── wrapper.js.html ├── api.js.html ├── utils.js.html ├── Zabbix.html └── Client.html ├── index.js ├── examples ├── zabbixSender.js ├── getHost.js └── createHost.js ├── .travis.yml ├── docker-compose.yml ├── LICENSE ├── tasks └── test.sh ├── package.json ├── README.md ├── lib ├── wrapper.js ├── api.js └── utils.js └── test └── acceptance.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | package-lock.json 4 | node_modules 5 | coverage 6 | .nyc_output 7 | out 8 | -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StarryShark/zabbix-promise/HEAD/docs/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @overview Interact with the Zabbix API using `zabbix-promise` and ES2015 3 | * native promises. 4 | * @license MIT 5 | * @author Sumit Goel 6 | */ 7 | module.exports = require('./lib/utils') 8 | -------------------------------------------------------------------------------- /examples/zabbixSender.js: -------------------------------------------------------------------------------- 1 | /** 2 | * In this example, we will send values to Zabbix trapper item type. There is 3 | * no need for Zabbix Sender binary as zabbix-promise package implements the 4 | * sender protocol in native JavaScript/Node.js. 5 | */ 6 | 7 | const zabbix = require('../index') 8 | 9 | const main = async () => { 10 | try { 11 | const result = await zabbix.sender({ 12 | server: '127.0.0.1', 13 | host: 'zabbix-promise-host', 14 | key: 'zabbix.promise.key', 15 | value: Math.random() 16 | }) 17 | console.log(result) 18 | } catch (error) { 19 | console.error(error) 20 | } 21 | } 22 | main() 23 | -------------------------------------------------------------------------------- /examples/getHost.js: -------------------------------------------------------------------------------- 1 | /** 2 | * In this example, we will query Zabbix hosts and apply a filter for host 3 | * "zabbix-promise-host" and include the interfaces as well. 4 | */ 5 | 6 | const Zabbix = require('../index') 7 | 8 | const zabbix = new Zabbix({ 9 | url: 'http://127.0.0.1:8080/api_jsonrpc.php', 10 | user: 'Admin', 11 | password: 'zabbix' 12 | }) 13 | 14 | const main = async () => { 15 | try { 16 | await zabbix.login() 17 | const hosts = await zabbix.request('host.get', { 18 | selectInterfaces: 'extend', 19 | filter: { 20 | host: 'zabbix-promise-host' 21 | } 22 | }) 23 | console.log(JSON.stringify(hosts, null, 2)) 24 | zabbix.logout() 25 | } catch (error) { 26 | console.error(error) 27 | } 28 | } 29 | main() 30 | -------------------------------------------------------------------------------- /docs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (() => { 3 | const source = document.getElementsByClassName('prettyprint source linenums'); 4 | let i = 0; 5 | let lineNumber = 0; 6 | let lineId; 7 | let lines; 8 | let totalLines; 9 | let anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = `line${lineNumber}`; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | group: edge 2 | sudo: required 3 | 4 | language: node_js 5 | node_js: 6 | - '8' 7 | - '10' 8 | - '12' 9 | services: 10 | - docker 11 | addons: 12 | apt: 13 | packages: 14 | - shellcheck 15 | - devscripts 16 | - jq 17 | 18 | install: 19 | - npm install 20 | 21 | script: 22 | - npm test 23 | 24 | branches: 25 | only: 26 | - master 27 | - v1.x.x 28 | 29 | matrix: 30 | fast_finish: true 31 | 32 | before_deploy: 33 | - | 34 | if ! [ "$TRAVIS_TAG" ]; then 35 | git config --local user.name "${github_username:?}" 36 | git config --local user.email "${github_email:?}" 37 | export TRAVIS_TAG=$(jq .version package.json | tr -d '"') 38 | git tag "v$TRAVIS_TAG" 39 | fi 40 | 41 | deploy: 42 | - provider: releases 43 | api_key: 44 | secure: "$github_token" 45 | on: 46 | repo: sumitgoelpw/zabbix-promise 47 | branch: master 48 | node: '8' 49 | - provider: npm 50 | email: "$npm_email" 51 | api_key: 52 | secure: "$npm_token" 53 | on: 54 | repo: sumitgoelpw/zabbix-promise 55 | branch: master 56 | node: '8' 57 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | zabbix-database: 4 | hostname: zabbix-database.local 5 | image: postgres:alpine 6 | environment: 7 | POSTGRES_USER: ${DBUSER} 8 | POSTGRES_PASSWORD: ${DBPASS} 9 | zabbix-server: 10 | hostname: zabbix-server.local 11 | image: zabbix/zabbix-server-pgsql:${ZABTAG} 12 | ports: 13 | - 0.0.0.0:10051:10051/tcp 14 | environment: 15 | DB_SERVER_HOST: zabbix-database 16 | POSTGRES_USER: ${DBUSER} 17 | POSTGRES_PASSWORD: ${DBPASS} 18 | POSTGRES_DB: ${DBUSER} 19 | depends_on: 20 | - zabbix-database 21 | zabbix-web: 22 | hostname: zabbix-web.local 23 | image: zabbix/zabbix-web-nginx-pgsql:${ZABTAG} 24 | ports: 25 | - 0.0.0.0:8080:80/tcp 26 | - 0.0.0.0:8443:443/tcp 27 | environment: 28 | ZBX_SERVER_HOST: zabbix-server 29 | DB_SERVER_HOST: zabbix-database 30 | POSTGRES_USER: ${DBUSER} 31 | POSTGRES_PASSWORD: ${DBPASS} 32 | POSTGRES_DB: ${DBUSER} 33 | TZ: GMT 34 | depends_on: 35 | - zabbix-server 36 | - zabbix-database 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2019 Sumit Goel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/createHost.js: -------------------------------------------------------------------------------- 1 | /** 2 | * In this example, we will create a Zabbix host "yet-another-host". 3 | * We need at least one host group and interface details as this information 4 | * is required to create a new host. We will query the host groups and get the 5 | * last group id from the return values. 6 | */ 7 | 8 | const Zabbix = require('../index') 9 | 10 | const zabbix = new Zabbix({ 11 | url: 'http://127.0.0.1:8080/api_jsonrpc.php', 12 | user: 'Admin', 13 | password: 'zabbix' 14 | }) 15 | 16 | const main = async () => { 17 | try { 18 | await zabbix.login() 19 | const groups = await zabbix.request('hostgroup.get', {}) 20 | const groupId = groups[groups.length - 1].groupid 21 | const host = await zabbix.request('host.create', { 22 | host: 'yet-another-host', 23 | groups: [{ groupid: groupId }], 24 | interfaces: [{ 25 | type: 1, 26 | main: 1, 27 | useip: 1, 28 | ip: '127.0.0.1', 29 | dns: '', 30 | port: '10050' 31 | }] 32 | }) 33 | console.log(host) 34 | zabbix.logout() 35 | } catch (error) { 36 | console.error(error) 37 | } 38 | } 39 | main() 40 | -------------------------------------------------------------------------------- /tasks/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ev 4 | 5 | export PATH="./node_modules/.bin:$PATH" 6 | 7 | export DBUSER='postgres' 8 | export DBPASS='postgres' 9 | 10 | # linting check 11 | standard 12 | 13 | # Ensure to bump up the version in package.json 14 | PKGVERSION=$(jq .version package.json | tr -d '"') 15 | PKGNPMVERSION=$(npm show zabbix-promise version) 16 | echo "$PKGVERSION" 17 | echo "$PKGNPMVERSION" 18 | if [ "$PKGVERSION" = "$PKGNPMVERSION" ]; then 19 | printf '\n>>>You need to bump up the version in package.json\n\n' 20 | exit 1 21 | fi 22 | 23 | # run tests for zabbix 24 | for VAR in 'alpine-3.0-latest' 'alpine-4.0-latest' 'alpine-4.2-latest' 25 | do 26 | export ZABTAG="$VAR" 27 | 28 | printf '\n>>> Building Zabbix %s conatiners.\n\n' "$VAR" 29 | docker-compose -p "$VAR" up -d 30 | printf '\n' && sleep 2 31 | docker-compose -p "$VAR" ps 32 | 33 | printf '\n>>> Please allow 10 seconds for the application to start entirely.\n' 34 | sleep 10 35 | 36 | printf '\n>>> Running the test cases.\n\n' 37 | node test/acceptance.test.js 38 | 39 | # exit 0 40 | printf '\n>>> Tests passed, deleting the containers.\n\n' 41 | docker-compose -p "$VAR" down 42 | done 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zabbix-promise", 3 | "version": "2.0.2", 4 | "description": "Simplified Zabbix API Client", 5 | "main": "index.js", 6 | "scripts": { 7 | "cb": "checkbashisms ./tasks/*.sh; exit 0", 8 | "sc": "shellcheck -s bash -Calways ./tasks/*.sh", 9 | "pretest": "npm run cb && npm run sc", 10 | "test": "bash ./tasks/test.sh", 11 | "jsdoc": "jsdoc -d docs -R README.md lib && open docs/index.html", 12 | "up": "rm -rf ./node_modules package-lock.json && npm i" 13 | }, 14 | "files": [ 15 | "index.js", 16 | "lib" 17 | ], 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/sumitgoelpw/zabbix-promise.git" 21 | }, 22 | "keywords": [ 23 | "Zabbix", 24 | "API" 25 | ], 26 | "author": { 27 | "name": "Sumit Goel" 28 | }, 29 | "license": "MIT", 30 | "bugs": { 31 | "url": "https://github.com/sumitgoelpw/zabbix-promise/issues" 32 | }, 33 | "homepage": "https://github.com/sumitgoelpw/zabbix-promise#readme", 34 | "devDependencies": { 35 | "jsdoc": "*", 36 | "nock": "*", 37 | "standard": "*", 38 | "tap": "*" 39 | }, 40 | "standard": { 41 | "ignore": [ 42 | "docs" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /docs/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zabbix API Client 2 | 3 | Zabbix is an open source monitoring software that can monitor pretty much everything like networks, servers, applications, etc. You may learn more about Zabbix at [www.zabbix.com](https://www.zabbix.com/). 4 | 5 | **Zabbix-promise** is a JavaScript package for Node.js runtime environment to interact with Zabbix APIs. The package is written to support JavaScript Promise and Async/await interfaces. Zabbix-promise implements Zabbix sender protocol in pure JavaScript code, and there are no other package dependencies, just the Node.js runtime. 6 | 7 | The latest version of zabbix-promise supports all currently maintained Node versions, see [Node Release Schedule](https://github.com/nodejs/Release#release-schedule) and all currently supported Zabbix releases, see [Zabbix Life Cycle & Release Policy](https://www.zabbix.com/life_cycle_and_release_policy). 8 | 9 | **Table of Contents** 10 | 11 | 12 | 13 | - [Install](#install) 14 | - [Usage](#usage) 15 | - [Examples](#examples) 16 | - [getHost](examples/getHost.js) 17 | - [createHost](examples/createHost.js) 18 | - [zabbixSender](examples/zabbixSender.js) 19 | - [Debugging](#debugging) 20 | - [Contributing](#contributing) 21 | - [License](#license) 22 | 23 | 24 | 25 | ## Install 26 | 27 | ```js 28 | $ npm install zabbix-promise --save 29 | ``` 30 | 31 | ## Usage 32 | 33 | ```js 34 | const Zabbix = require('zabbix-promise') 35 | 36 | const zabbix = new Zabbix({ 37 | url: 'http://127.0.0.1:8080/api_jsonrpc.php', 38 | user: 'Admin', 39 | password: 'zabbix' 40 | }) 41 | 42 | const main = async () => { 43 | try { 44 | await zabbix.login() 45 | const host = await zabbix.request('host.get', { 46 | selectInterfaces: 'extend', 47 | limit: 1 48 | }) 49 | console.log(JSON.stringify(host, null, 2)) 50 | zabbix.logout() 51 | } catch (error) { 52 | console.error(error) 53 | } 54 | } 55 | main() 56 | ``` 57 | 58 | ### Examples 59 | 60 | Please check the examples below to get started. 61 | 62 | - [getHost](examples/getHost.js) 63 | - [createHost](examples/createHost.js) 64 | - [zabbixSender](examples/zabbixSender.js) 65 | 66 | ## Debugging 67 | 68 | Zabbix-promsie uses [`debuglog`](https://nodejs.org/dist/latest/docs/api/util.html#util_util_debuglog_section), so just run with environmental variable `NODE_DEBUG` set to `zp*`. 69 | 70 | ```js 71 | $ NODE_DEBUG=zp* node getHost.js 72 | ``` 73 | 74 | ## Contributing 75 | 76 | 👋Thanks for thinking about contributing to zabbix-promise! There are a few ways you may contribute to the project. 77 | 78 | 1. Use the package in your projects and report any bugs you may find by filing issues. 79 | 2. Submit examples to cover the Zabbix APIs that are not in examples already by sending pull request. 80 | 3. Submit test cases to cover all or most of the Zabbix APIs by sending pull request. 81 | 82 | ## License 83 | 84 | [MIT](LICENSE) 85 | 86 | Copyright (c) 2016-2019 Sumit Goel. 87 | -------------------------------------------------------------------------------- /lib/wrapper.js: -------------------------------------------------------------------------------- 1 | const http = require('http') 2 | const https = require('https') 3 | const { URL } = require('url') 4 | const util = require('util') 5 | 6 | const debug = util.debuglog('zp:wrapper') 7 | 8 | module.exports = { 9 | /** 10 | * @param {object} opts 11 | * @property {string} url 12 | * @property {string} auth 13 | * @property {string} method 14 | * @property {(object|Array)} params 15 | * @property {object} options 16 | */ 17 | post: async (opts) => { 18 | try { 19 | // Creates a new URL object by parsing the input 20 | const url = new URL(opts.url) 21 | debug('Request URL: %o', url) 22 | 23 | // Use http or https module based on the input URL 24 | let client = http 25 | if (url.protocol === 'https:') { 26 | client = https 27 | } 28 | 29 | // Include or overwrite the user supplied HTTP request options. 30 | const options = Object.assign({ 31 | hostname: url.hostname, 32 | port: url.port, 33 | path: url.pathname, 34 | method: 'POST', 35 | headers: { 36 | 'Content-Type': 'application/json' 37 | } 38 | }, opts.options) 39 | debug('Request options: %o', options) 40 | 41 | // Stringify the JSON body to write to HTTP POST request. 42 | const body = JSON.stringify({ 43 | jsonrpc: '2.0', 44 | id: String(Math.random()), 45 | auth: opts.auth, 46 | method: opts.method, 47 | params: opts.params 48 | }) 49 | debug('Request body: %o', body) 50 | 51 | return new Promise((resolve, reject) => { 52 | const req = client.request(options, (res) => { 53 | const { statusCode } = res 54 | const contentType = res.headers['content-type'] 55 | 56 | debug('Response status code: %i', statusCode) 57 | debug('Response status message: %s', res.statusMessage) 58 | debug('Response headers: %o', res.headers) 59 | 60 | /** 61 | * Check the response headers for status code and content type. 62 | * If it's not 200 and application/json respectively then reject the 63 | * promise and that will return the error message. 64 | */ 65 | let error = '' 66 | if (statusCode !== 200) { 67 | error = new Error('Request Failed.\n' + `Status Code: ${statusCode}`) 68 | } else if (!/^application\/json/.test(contentType)) { 69 | error = new Error('Invalid content-type.\n' + 70 | `Expected application/json but received ${contentType}`) 71 | } 72 | 73 | if (error) { 74 | /** 75 | * We are calling .resume() to consume the data from response. 76 | * Because until the data is read it will consume memory that can 77 | * eventually lead to a 'process out of memory' error. Read more at: 78 | * https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_class_http_clientrequest 79 | */ 80 | res.resume() 81 | reject(error) 82 | } 83 | 84 | res.setEncoding('utf8') 85 | let rawData = '' 86 | res.on('data', (chunk) => { rawData = rawData + chunk }) 87 | res.on('end', () => { 88 | debug('Response body: %o', rawData) 89 | resolve(JSON.parse(rawData)) 90 | }) 91 | }) 92 | 93 | req.on('error', (error) => { 94 | reject(error) 95 | }) 96 | 97 | req.write(body) 98 | req.end() 99 | }) 100 | } catch (error) { 101 | throw error 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /lib/api.js: -------------------------------------------------------------------------------- 1 | const req = require('./wrapper') 2 | const util = require('util') 3 | 4 | const debug = util.debuglog('zp:api') 5 | 6 | /** 7 | * Zabbix class represents the Zabbix API Client to make JSON-RPC 2.0 protocol 8 | * compliant HTTP POST requests. You instantiate a class with an object that 9 | * includes the required properties listed below, and then you should call the 10 | * login method first to get the valid authentication token. Now you are ready 11 | * to make other Zabbix API calls and don't forget to call the logout method 12 | * when you are done. 13 | */ 14 | class Zabbix { 15 | /** 16 | * The constructor creates an instance of Zabbix class. 17 | * 18 | * @param {object} opts - An object contains the details about Zabbix API 19 | * server like url, username, password and an optional object for any other 20 | * Node.js HTTP options the user may want to send with the request. 21 | * @property {string} url - The URL of the Zabbix API endpoint. 22 | * @property {string} user - The login name for authentication. 23 | * @property {string} password - The password for authentication. 24 | * @property {object} [options] - Any Nodejs HTTP request supported options. 25 | * 26 | * @example 27 | * new Zabbix({ 28 | * url: 'https://127.0.0.1:8443/api_jsonrpc.php', 29 | * user: 'Admin', 30 | * password: 'zabbix', 31 | * options: { 32 | * rejectUnauthorized: false 33 | * } 34 | * }) 35 | */ 36 | constructor (opts) { 37 | this.url = opts.url 38 | this.user = opts.user 39 | this.password = opts.password 40 | this.options = opts.options || {} 41 | this.auth = null 42 | 43 | debug('Constructor options: %o', opts) 44 | } 45 | 46 | /** 47 | * A request method to make Zabbix API calls. 48 | * 49 | * @param {string} method - the Zabbix API method being called. 50 | * @param {object|array} params - The parameters that will be passed to the 51 | * Zabbix API method. 52 | * 53 | * @returns {Promise} - a promise which resolves to the http response from the 54 | * Zabbix server of string, object or array type. 55 | * 56 | * @example 57 | * Zabbix.request('host.get', { limit: 1 }) 58 | */ 59 | async request (method, params) { 60 | try { 61 | const res = await req.post({ 62 | url: this.url, 63 | auth: this.auth, 64 | options: this.options, 65 | method, 66 | params 67 | }) 68 | debug('API Request response: %o', res) 69 | if (res.result) { 70 | return res.result 71 | } else { 72 | throw JSON.stringify(res) 73 | } 74 | } catch (error) { 75 | throw error 76 | } 77 | } 78 | 79 | /** 80 | * A login method to authenticate with Zabbix. 81 | * 82 | * @returns {Promise} - a promise which resolves to the http response from the 83 | * Zabbix server of string type authentication token. 84 | * 85 | * @example 86 | * Zabbix.login() 87 | */ 88 | async login () { 89 | try { 90 | const result = await this.request('user.login', { 91 | user: this.user, 92 | password: this.password 93 | }) 94 | this.auth = result 95 | return result 96 | } catch (error) { 97 | throw error 98 | } 99 | } 100 | 101 | /** 102 | * A logout method to close the Zabbix server session. 103 | * 104 | * @returns {Promise} - a promise which resolves to the http response from the 105 | * Zabbix server of boolean truthy value. 106 | * 107 | * @example 108 | * Zabbix.logout() 109 | */ 110 | async logout () { 111 | try { 112 | const result = await this.request('user.logout', []) 113 | this.auth = null 114 | return result 115 | } catch (error) { 116 | throw error 117 | } finally { 118 | this.auth = null 119 | } 120 | } 121 | } 122 | 123 | module.exports = Zabbix 124 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Home 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Home

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |

Zabbix API Client

47 |

Zabbix is an open source monitoring software that can monitor pretty much everything like networks, servers, applications, etc. You may learn more about Zabbix at www.zabbix.com.

48 |

Zabbix-promise is a JavaScript package for Node.js runtime environment to interact with Zabbix APIs. The package is written to support JavaScript Promise and Async/await interfaces. Zabbix-promise implements Zabbix sender protocol in pure JavaScript code, and there are no other package dependencies, just the Node.js runtime.

49 |

The latest version of zabbix-promise supports all currently maintained Node versions, see Node Release Schedule and all currently supported Zabbix releases, see Zabbix Life Cycle & Release Policy.

50 |

Table of Contents

51 | 52 | 69 | 70 |

Install

71 |
$ npm install zabbix-promise --save
 72 | 
73 |

Usage

74 |
const Zabbix = require('zabbix-promise')
 75 | 
 76 | const zabbix = new Zabbix({
 77 |   url: 'http://127.0.0.1:8080/api_jsonrpc.php',
 78 |   user: 'Admin',
 79 |   password: 'zabbix'
 80 | })
 81 | 
 82 | const main = async () => {
 83 |   try {
 84 |     await zabbix.login()
 85 |     const host = await zabbix.request('host.get', {
 86 |       selectInterfaces: 'extend',
 87 |       limit: 1
 88 |     })
 89 |     console.log(JSON.stringify(host, null, 2))
 90 |     zabbix.logout()
 91 |   } catch (error) {
 92 |     console.error(error)
 93 |   }
 94 | }
 95 | main()
 96 | 
97 |

Examples

98 |

Please check the examples below to get started.

99 | 104 |

Debugging

105 |

Zabbix-promsie uses debuglog, so just run with environmental variable NODE_DEBUG set to zp*.

106 |
$ NODE_DEBUG=zp* node getHost.js
107 | 
108 |

Contributing

109 |

👋Thanks for thinking about contributing to zabbix-promise! There are a few ways you may contribute to the project.

110 |
    111 |
  1. Use the package in your projects and report any bugs you may find by filing issues.
  2. 112 |
  3. Submit examples to cover the Zabbix APIs that are not in examples already by sending pull request.
  4. 113 |
  5. Submit test cases to cover all or most of the Zabbix APIs by sending pull request.
  6. 114 |
115 |

License

116 |

MIT

117 |

Copyright (c) 2016-2019 Sumit Goel.

118 |
119 | 120 | 121 | 122 | 123 | 124 | 125 |
126 | 127 | 130 | 131 |
132 | 133 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /docs/wrapper.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: wrapper.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: wrapper.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
const http = require('http')
 30 | const https = require('https')
 31 | const { URL } = require('url')
 32 | const util = require('util')
 33 | 
 34 | const debug = util.debuglog('zp:wrapper')
 35 | 
 36 | module.exports = {
 37 |   /**
 38 |    * @param {object} opts
 39 |    * @property {string} url
 40 |    * @property {string} auth
 41 |    * @property {string} method
 42 |    * @property {(object|Array)} params
 43 |    * @property {object} options
 44 |    */
 45 |   post: async (opts) => {
 46 |     try {
 47 |       // Creates a new URL object by parsing the input
 48 |       const url = new URL(opts.url)
 49 |       debug('Request URL: %o', url)
 50 | 
 51 |       // Use http or https module based on the input URL
 52 |       let client = http
 53 |       if (url.protocol === 'https:') {
 54 |         client = https
 55 |       }
 56 | 
 57 |       // Include or overwrite the user supplied HTTP request options.
 58 |       const options = Object.assign({
 59 |         hostname: url.hostname,
 60 |         port: url.port,
 61 |         path: url.pathname,
 62 |         method: 'POST',
 63 |         headers: {
 64 |           'Content-Type': 'application/json'
 65 |         }
 66 |       }, opts.options)
 67 |       debug('Request options: %o', options)
 68 | 
 69 |       // Stringify the JSON body to write to HTTP POST request.
 70 |       const body = JSON.stringify({
 71 |         jsonrpc: '2.0',
 72 |         id: String(Math.random()),
 73 |         auth: opts.auth,
 74 |         method: opts.method,
 75 |         params: opts.params
 76 |       })
 77 |       debug('Request body: %o', body)
 78 | 
 79 |       return new Promise((resolve, reject) => {
 80 |         const req = client.request(options, (res) => {
 81 |           const { statusCode } = res
 82 |           const contentType = res.headers['content-type']
 83 | 
 84 |           debug('Response status code: %i', statusCode)
 85 |           debug('Response status message: %s', res.statusMessage)
 86 |           debug('Response headers: %o', res.headers)
 87 | 
 88 |           /**
 89 |            * Check the response headers for status code and content type.
 90 |            * If it's not 200 and application/json respectively then reject the
 91 |            * promise and that will return the error message.
 92 |            */
 93 |           let error = ''
 94 |           if (statusCode !== 200) {
 95 |             error = new Error('Request Failed.\n' + `Status Code: ${statusCode}`)
 96 |           } else if (!/^application\/json/.test(contentType)) {
 97 |             error = new Error('Invalid content-type.\n' +
 98 |                               `Expected application/json but received ${contentType}`)
 99 |           }
100 | 
101 |           if (error) {
102 |             /**
103 |              * We are calling .resume() to consume the data from response.
104 |              * Because until the data is read it will consume memory that can
105 |              * eventually lead to a 'process out of memory' error. Read more at:
106 |              * https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_class_http_clientrequest
107 |              */
108 |             res.resume()
109 |             reject(error)
110 |           }
111 | 
112 |           res.setEncoding('utf8')
113 |           let rawData = ''
114 |           res.on('data', (chunk) => { rawData = rawData + chunk })
115 |           res.on('end', () => {
116 |             debug('Response body: %o', rawData)
117 |             resolve(JSON.parse(rawData))
118 |           })
119 |         })
120 | 
121 |         req.on('error', (error) => {
122 |           reject(error)
123 |         })
124 | 
125 |         req.write(body)
126 |         req.end()
127 |       })
128 |     } catch (error) {
129 |       throw error
130 |     }
131 |   }
132 | }
133 | 
134 |
135 |
136 | 137 | 138 | 139 | 140 |
141 | 142 | 145 | 146 |
147 | 148 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/api.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: api.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: api.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
const req = require('./wrapper')
 30 | const util = require('util')
 31 | 
 32 | const debug = util.debuglog('zp:api')
 33 | 
 34 | /**
 35 |  * Zabbix class represents the Zabbix API Client to make JSON-RPC 2.0 protocol
 36 |  * compliant HTTP POST requests. You instantiate a class with an object that
 37 |  * includes the required properties listed below, and then you should call the
 38 |  * login method first to get the valid authentication token. Now you are ready
 39 |  * to make other Zabbix API calls and don't forget to call the logout method
 40 |  * when you are done.
 41 |  */
 42 | class Zabbix {
 43 |   /**
 44 |    * The constructor creates an instance of Zabbix class.
 45 |    *
 46 |    * @param {object} opts - An object contains the details about Zabbix API
 47 |    *  server like url, username, password and an optional object for any other
 48 |    *  Node.js HTTP options the user may want to send with the request.
 49 |    * @property {string} url - The URL of the Zabbix API endpoint.
 50 |    * @property {string} user - The login name for authentication.
 51 |    * @property {string} password - The password for authentication.
 52 |    * @property {object} [options] - Any Nodejs HTTP request supported options.
 53 |    *
 54 |    * @example
 55 |    * new Zabbix({
 56 |    *   url: 'https://127.0.0.1:8443/api_jsonrpc.php',
 57 |    *   user: 'Admin',
 58 |    *   password: 'zabbix',
 59 |    *   options: {
 60 |    *     rejectUnauthorized: false
 61 |    *   }
 62 |    * })
 63 |    */
 64 |   constructor (opts) {
 65 |     this.url = opts.url
 66 |     this.user = opts.user
 67 |     this.password = opts.password
 68 |     this.options = opts.options || {}
 69 |     this.auth = null
 70 | 
 71 |     debug('Constructor options: %o', opts)
 72 |   }
 73 | 
 74 |   /**
 75 |    * A request method to make Zabbix API calls.
 76 |    *
 77 |    * @param {string} method - the Zabbix API method being called.
 78 |    * @param {object|array} params - The parameters that will be passed to the
 79 |    *  Zabbix API method.
 80 |    *
 81 |    * @returns {Promise} - a promise which resolves to the http response from the
 82 |    *  Zabbix server of string, object or array type.
 83 |    *
 84 |    * @example
 85 |    * Zabbix.request('host.get', { limit: 1 })
 86 |    */
 87 |   async request (method, params) {
 88 |     try {
 89 |       const res = await req.post({
 90 |         url: this.url,
 91 |         auth: this.auth,
 92 |         options: this.options,
 93 |         method,
 94 |         params
 95 |       })
 96 |       debug('API Request response: %o', res)
 97 |       if (res.result) {
 98 |         return res.result
 99 |       } else {
100 |         throw JSON.stringify(res)
101 |       }
102 |     } catch (error) {
103 |       throw error
104 |     }
105 |   }
106 | 
107 |   /**
108 |    * A login method to authenticate with Zabbix.
109 |    *
110 |    * @returns {Promise} - a promise which resolves to the http response from the
111 |    *  Zabbix server of string type authentication token.
112 |    *
113 |    * @example
114 |    * Zabbix.login()
115 |    */
116 |   async login () {
117 |     try {
118 |       const result = await this.request('user.login', {
119 |         user: this.user,
120 |         password: this.password
121 |       })
122 |       this.auth = result
123 |       return result
124 |     } catch (error) {
125 |       throw error
126 |     }
127 |   }
128 | 
129 |   /**
130 |    * A logout method to close the Zabbix server session.
131 |    *
132 |    * @returns {Promise} - a promise which resolves to the http response from the
133 |    *  Zabbix server of boolean truthy value.
134 |    *
135 |    * @example
136 |    * Zabbix.logout()
137 |    */
138 |   async logout () {
139 |     try {
140 |       const result = await this.request('user.logout', [])
141 |       this.auth = null
142 |       return result
143 |     } catch (error) {
144 |       throw error
145 |     } finally {
146 |       this.auth = null
147 |     }
148 |   }
149 | }
150 | 
151 | module.exports = Zabbix
152 | 
153 |
154 |
155 | 156 | 157 | 158 | 159 |
160 | 161 | 164 | 165 |
166 | 167 | 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | const net = require('net') 2 | const util = require('util') 3 | const Zabbix = require('./api') 4 | 5 | const debug = util.debuglog('zp:utils') 6 | 7 | /** 8 | * Class extending Zabbix APIs to useful utility methods. 9 | * @extends Zabbix 10 | */ 11 | class Client extends Zabbix { 12 | /** 13 | * The sender method implements the Zabbix Sender protocol natively in 14 | * JavaScript. There is no need to authenticate with Zabbix to use sender 15 | * method. Just pass an object with server, host, key and value properties. 16 | * 17 | * @param {object} options - An object contains the payload to send to Zabbix 18 | * sender. 19 | * @property {integer} [port] - Zabbix server port to receive sender traffic. 20 | * Defaults to 10051. 21 | * @property {string} server - Zabbix server name or IP address 22 | * @property {string} host - Zabbix host as configured in frontend 23 | * @property {string} key - Zabbix host item key 24 | * @property {(string|number)} value - The value to send 25 | * 26 | * @example 27 | * Client.sender({ 28 | * server: '127.0.0.1', 29 | * host: 'zabbix.host', 30 | * key: 'item.test.key', 31 | * value: 'Hey there!' 32 | * }) 33 | */ 34 | static async sender (options) { 35 | try { 36 | if (!options.server) throw new Error('"server" is missing') 37 | if (!options.host) throw new Error('"host" is missing') 38 | if (!options.key) throw new Error('"key" is missing') 39 | if (!options.value) throw new Error('"value" is missing') 40 | 41 | debug('Options received: %o', options) 42 | 43 | /** 44 | * Zabbix sender request message. 45 | * https://www.zabbix.com/documentation/4.0/manual/appendix/items/trapper 46 | */ 47 | const payload = { 48 | request: 'sender data', 49 | data: [ 50 | { 51 | host: options.host, 52 | key: options.key, 53 | value: options.value 54 | } 55 | ] 56 | } 57 | 58 | // Creates a new Buffer containing payload string. 59 | const payloadBuffer = Buffer.from(JSON.stringify(payload)) 60 | 61 | /** 62 | * Returns the actual byte length of a string. This is not the same as 63 | * String.prototype.length since that returns the number of characters in 64 | * A string. When string is a Buffer, the actual byte length is returned. 65 | */ 66 | const payloadByteLength = Buffer.byteLength(payloadBuffer) 67 | 68 | /* 69 | * Zabbix sender request and response messages must begin with header 70 | * And data length. Here is the link describing all the headers, 71 | * https://www.zabbix.com/documentation/4.0/manual/appendix/protocols/header_datalen 72 | * 73 | * The code below allocates a new Buffer of size 13 bytes and write the 74 | * header information. 75 | */ 76 | const headerBuffer = Buffer.alloc(4 + 1 + 4 + 4) 77 | headerBuffer.write('ZBXD\x01') 78 | headerBuffer.writeUInt32LE(payloadByteLength, 5) 79 | headerBuffer.write('\x00\x00\x00\x00', 9) 80 | 81 | /* 82 | * Returns a new Buffer which is the result of concatenating the header and 83 | * Payload buffers. 84 | */ 85 | const packet = Buffer.concat([headerBuffer, payloadBuffer]) 86 | 87 | const serverResponse = await new Promise((resolve, reject) => { 88 | /** 89 | * Initiates connection to Zabbix server or proxy and sends the packet. 90 | */ 91 | const client = net.connect({ 92 | port: options.port || 10051, 93 | host: options.server 94 | }, () => { 95 | debug('Connected to server: %s', options.server) 96 | client.write(packet) 97 | }) 98 | 99 | /** 100 | * Emitted when data is received. The argument data will be a Buffer or 101 | * String. By default, no encoding is assigned and stream data will be 102 | * returned as Buffer objects. Note that the data will be lost if there 103 | * is no listener when a Socket emits a 'data' event. 104 | */ 105 | client.on('data', (data) => { 106 | debug('Server response raw: %s', data.toString()) 107 | const jsonData = JSON.parse(data.slice(13).toString()) 108 | debug('Server response parsed JSON: %j', jsonData) 109 | client.end() 110 | 111 | // Read the Zabbix server response and reject the promise with the 112 | // error message. 113 | const errorMessage = `${data.toString()}\n` + 'A few things to check,\n' + 114 | '- Double check the host and item key name in Zabbix\n' + 115 | '- Double check the item configuration e.g. item type, data type and etc.\n' + 116 | '- If using Zabbix proxy then ensure cache is updated.' 117 | const failed = jsonData.info.split(';')[1].slice(-1) 118 | if (failed !== '0') { 119 | reject(new Error(errorMessage)) 120 | } 121 | resolve(jsonData) 122 | }) 123 | 124 | /** 125 | * Emitted when an error occurs. The 'close' event will be called 126 | * directly following this event. 127 | */ 128 | client.on('error', (error) => { 129 | debug('Server response: %o', error) 130 | reject(error) 131 | }) 132 | 133 | /** 134 | * Emitted when the other end of the socket sends a FIN packet, thus 135 | * ending the readable side of the socket. 136 | */ 137 | client.on('end', () => { 138 | debug('Connection closed.') 139 | }) 140 | }) 141 | 142 | return serverResponse 143 | } catch (error) { 144 | throw error 145 | } 146 | } 147 | } 148 | 149 | module.exports = Client 150 | -------------------------------------------------------------------------------- /test/acceptance.test.js: -------------------------------------------------------------------------------- 1 | const Zabbix = require('../index') 2 | const t = require('tap') 3 | const test = t.test 4 | 5 | const zabbix = new Zabbix({ 6 | url: 'http://127.0.0.1:8080/api_jsonrpc.php', 7 | user: 'Admin', 8 | password: 'zabbix' 9 | }) 10 | 11 | // We need host group name to create a new host group and it will return the 12 | // group id that we will store in hostGroupId. We need host group id to create 13 | // a new host later. 14 | const hostGroupName = 'zabbix-promise-group' 15 | let hostGroupId = null 16 | 17 | // We need host name to create a new host and it will return the host id that we 18 | // will store in hostId. We need host id to create a new item later. 19 | const hostName = 'zabbix-promise-host' 20 | let hostId = null 21 | 22 | // We need item name and key to create Zabbix trapper item. 23 | const itemName = 'zabbix-promise-item' 24 | const itemKey = 'zabbix.promise.key' 25 | 26 | const main = async () => { 27 | await test('User login', async t => { 28 | await t.resolves(zabbix.login()) 29 | 30 | t.type(await new Zabbix({ 31 | url: 'http://127.0.0.1:8080/api_jsonrpc.php', 32 | user: 'Admin', 33 | password: 'zabbix' 34 | }).login(), 'string', 'return value type is string') 35 | 36 | // Wrong username 37 | t.rejects(new Zabbix({ 38 | url: 'http://127.0.0.1:8080/api_jsonrpc.php', 39 | user: 'Admin1', 40 | password: 'zabbix' 41 | }).login(), 'expect rejected Promise for wrong username') 42 | 43 | // Wrong password 44 | t.rejects(new Zabbix({ 45 | url: 'http://127.0.0.1:8080/api_jsonrpc.php', 46 | user: 'Admin', 47 | password: 'zabbix1' 48 | }).login(), 'expect rejected Promise for wrong password') 49 | 50 | // Wrong port 51 | t.rejects(new Zabbix({ 52 | url: 'http://127.0.0.1:80801/api_jsonrpc.php', 53 | user: 'Admin', 54 | password: 'zabbix' 55 | }).login(), 'expect rejected Promise for wrong URL') 56 | 57 | // HTTPS URL 58 | t.rejects(new Zabbix({ 59 | url: 'https://localhost:8080/api_jsonrpc.php', 60 | user: 'Admin', 61 | password: 'zabbix' 62 | }).login(), 'expect rejected Promise for HTTPS') 63 | }) 64 | 65 | await test('Create hostgroup', async t => { 66 | const result = await zabbix.request('hostgroup.get', { 67 | filter: { name: hostGroupName } 68 | }) 69 | if (result.length === 0) { 70 | const value = await zabbix.request('hostgroup.create', { name: hostGroupName }) 71 | hostGroupId = value.groupids[0] 72 | t.match(hostGroupId, /[0-9]+/g, `${hostGroupName} created`) 73 | } else { 74 | hostGroupId = result[0].groupid 75 | t.match(hostGroupId, /[0-9]+/g, `${hostGroupName} already exists`) 76 | } 77 | }) 78 | 79 | await test('Create host', async t => { 80 | const result = await zabbix.request('host.get', { 81 | filter: { host: hostName } 82 | }) 83 | if (result.length === 0) { 84 | const value = await zabbix.request('host.create', { 85 | host: hostName, 86 | groups: [{ groupid: hostGroupId }], 87 | interfaces: [{ 88 | type: 1, 89 | main: 1, 90 | useip: 1, 91 | ip: '127.0.0.1', 92 | dns: '', 93 | port: '10050' 94 | }] 95 | }) 96 | hostId = value.hostids[0] 97 | t.match(hostId, /[0-9]+/g, `${hostName} created`) 98 | } else { 99 | hostId = result[0].hostid 100 | t.match(hostId, /[0-9]+/g, `${hostName} already exists`) 101 | } 102 | }) 103 | 104 | await test('Create item', async t => { 105 | const result = await zabbix.request('item.get', { 106 | hostids: hostId, 107 | search: { key_: itemKey } 108 | }) 109 | if (result.length === 0) { 110 | const value = await zabbix.request('item.create', { 111 | hostid: hostId, 112 | key_: itemKey, 113 | name: itemName, 114 | type: 2, // 2 - Zabbix trapper 115 | value_type: 0 // 0 - numeric float 116 | }) 117 | t.match(value.itemids[0], /[0-9]+/g, `${itemName} created, please wait for 60 seconds.`) 118 | await new Promise(resolve => setTimeout(resolve, 60000)) 119 | } else { 120 | t.match(result[0].itemid, /[0-9]+/g, `${itemName} already exists`) 121 | } 122 | }) 123 | 124 | await test('Zabbix sender', async t => { 125 | t.resolves(Zabbix.sender({ 126 | server: '127.0.0.1', 127 | host: hostName, 128 | key: itemKey, 129 | value: Math.random() 130 | })) 131 | 132 | // Wrong host name 133 | t.rejects(Zabbix.sender({ 134 | server: '127.0.0.1', 135 | host: hostName + 'zabbix', 136 | key: itemKey, 137 | value: Math.random() 138 | }), 'expect rejected Promise for wrong host name') 139 | 140 | // Wrong port 141 | t.rejects(Zabbix.sender({ 142 | server: '127.0.0.1', 143 | port: 1234, 144 | host: hostName, 145 | key: itemKey, 146 | value: Math.random() 147 | }), 'expect rejected Promise for wrong server port') 148 | 149 | // Missing server 150 | t.rejects(Zabbix.sender({ 151 | host: hostName, 152 | key: itemKey, 153 | value: Math.random() 154 | }), 'expect rejected Promise for missing server') 155 | 156 | // Missing host 157 | t.rejects(Zabbix.sender({ 158 | server: '127.0.0.1', 159 | key: itemKey, 160 | value: Math.random() 161 | }), 'expect rejected Promise for missing host') 162 | 163 | // Missing key 164 | t.rejects(Zabbix.sender({ 165 | server: '127.0.0.1', 166 | host: hostName, 167 | value: Math.random() 168 | }), 'expect rejected Promise for missing key') 169 | 170 | // Missing value 171 | t.rejects(Zabbix.sender({ 172 | server: '127.0.0.1', 173 | host: hostName, 174 | key: itemKey 175 | }), 'expect rejected Promise for missing value') 176 | }) 177 | 178 | await test('User logout', async t => { 179 | await t.resolveMatch(zabbix.logout(), /true/g) 180 | t.rejects(zabbix.logout()) 181 | }) 182 | } 183 | main() 184 | -------------------------------------------------------------------------------- /docs/utils.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Source: utils.js 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Source: utils.js

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
const net = require('net')
 30 | const util = require('util')
 31 | const Zabbix = require('./api')
 32 | 
 33 | const debug = util.debuglog('zp:utils')
 34 | 
 35 | /**
 36 |  * Class extending Zabbix APIs to useful utility methods.
 37 |  * @extends Zabbix
 38 |  */
 39 | class Client extends Zabbix {
 40 |   /**
 41 |    * The sender method implements the Zabbix Sender protocol natively in
 42 |    * JavaScript. There is no need to authenticate with Zabbix to use sender
 43 |    * method. Just pass an object with server, host, key and value properties.
 44 |    *
 45 |    * @param {object} options - An object contains the payload to send to Zabbix
 46 |    *  sender.
 47 |    * @property {integer} [port] - Zabbix server port to receive sender traffic.
 48 |    *  Defaults to 10051.
 49 |    * @property {string} server - Zabbix server name or IP address
 50 |    * @property {string} host - Zabbix host as configured in frontend
 51 |    * @property {string} key - Zabbix host item key
 52 |    * @property {(string|number)} value - The value to send
 53 |    *
 54 |    * @example
 55 |    * Client.sender({
 56 |    *   server: '127.0.0.1',
 57 |    *   host: 'zabbix.host',
 58 |    *   key: 'item.test.key',
 59 |    *   value: 'Hey there!'
 60 |    * })
 61 |    */
 62 |   static async sender (options) {
 63 |     try {
 64 |       if (!options.server) throw new Error('"server" is missing')
 65 |       if (!options.host) throw new Error('"host" is missing')
 66 |       if (!options.key) throw new Error('"key" is missing')
 67 |       if (!options.value) throw new Error('"value" is missing')
 68 | 
 69 |       debug('Options received: %o', options)
 70 | 
 71 |       /**
 72 |        * Zabbix sender request message.
 73 |        * https://www.zabbix.com/documentation/4.0/manual/appendix/items/trapper
 74 |        */
 75 |       const payload = {
 76 |         request: 'sender data',
 77 |         data: [
 78 |           {
 79 |             host: options.host,
 80 |             key: options.key,
 81 |             value: options.value
 82 |           }
 83 |         ]
 84 |       }
 85 | 
 86 |       // Creates a new Buffer containing payload string.
 87 |       const payloadBuffer = Buffer.from(JSON.stringify(payload))
 88 | 
 89 |       /**
 90 |        * Returns the actual byte length of a string. This is not the same as
 91 |        * String.prototype.length since that returns the number of characters in
 92 |        * A string. When string is a Buffer, the actual byte length is returned.
 93 |        */
 94 |       const payloadByteLength = Buffer.byteLength(payloadBuffer)
 95 | 
 96 |       /*
 97 |       * Zabbix sender request and response messages must begin with header
 98 |       * And data length. Here is the link describing all the headers,
 99 |       * https://www.zabbix.com/documentation/4.0/manual/appendix/protocols/header_datalen
100 |       *
101 |       * The code below allocates a new Buffer of size 13 bytes and write the
102 |       * header information.
103 |       */
104 |       const headerBuffer = Buffer.alloc(4 + 1 + 4 + 4)
105 |       headerBuffer.write('ZBXD\x01')
106 |       headerBuffer.writeUInt32LE(payloadByteLength, 5)
107 |       headerBuffer.write('\x00\x00\x00\x00', 9)
108 | 
109 |       /*
110 |       * Returns a new Buffer which is the result of concatenating the header and
111 |       * Payload buffers.
112 |       */
113 |       const packet = Buffer.concat([headerBuffer, payloadBuffer])
114 | 
115 |       const serverResponse = await new Promise((resolve, reject) => {
116 |         /**
117 |          * Initiates connection to Zabbix server or proxy and sends the packet.
118 |          */
119 |         const client = net.connect({
120 |           port: options.port || 10051,
121 |           host: options.server
122 |         }, () => {
123 |           debug('Connected to server: %s', options.server)
124 |           client.write(packet)
125 |         })
126 | 
127 |         /**
128 |          * Emitted when data is received. The argument data will be a Buffer or
129 |          * String. By default, no encoding is assigned and stream data will be
130 |          * returned as Buffer objects. Note that the data will be lost if there
131 |          * is no listener when a Socket emits a 'data' event.
132 |          */
133 |         client.on('data', (data) => {
134 |           debug('Server response raw: %s', data.toString())
135 |           const jsonData = JSON.parse(data.slice(13).toString())
136 |           debug('Server response parsed JSON: %j', jsonData)
137 |           client.end()
138 | 
139 |           // Read the Zabbix server response and reject the promise with the
140 |           // error message.
141 |           const errorMessage = `${data.toString()}\n` + 'A few things to check,\n' +
142 |             '- Double check the host and item key name in Zabbix\n' +
143 |             '- Double check the item configuration e.g. item type, data type and etc.\n' +
144 |             '- If using Zabbix proxy then ensure cache is updated.'
145 |           const failed = jsonData.info.split(';')[1].slice(-1)
146 |           if (failed !== '0') {
147 |             reject(new Error(errorMessage))
148 |           }
149 |           resolve(jsonData)
150 |         })
151 | 
152 |         /**
153 |          * Emitted when an error occurs. The 'close' event will be called
154 |          * directly following this event.
155 |          */
156 |         client.on('error', (error) => {
157 |           debug('Server response: %o', error)
158 |           reject(error)
159 |         })
160 | 
161 |         /**
162 |          * Emitted when the other end of the socket sends a FIN packet, thus
163 |          * ending the readable side of the socket.
164 |          */
165 |         client.on('end', () => {
166 |           debug('Connection closed.')
167 |         })
168 |       })
169 | 
170 |       return serverResponse
171 |     } catch (error) {
172 |       throw error
173 |     }
174 |   }
175 | }
176 | 
177 | module.exports = Client
178 | 
179 |
180 |
181 | 182 | 183 | 184 | 185 |
186 | 187 | 190 | 191 |
192 | 193 | 196 | 197 | 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /docs/styles/jsdoc-default.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Open Sans'; 3 | font-weight: normal; 4 | font-style: normal; 5 | src: url('../fonts/OpenSans-Regular-webfont.eot'); 6 | src: 7 | local('Open Sans'), 8 | local('OpenSans'), 9 | url('../fonts/OpenSans-Regular-webfont.eot?#iefix') format('embedded-opentype'), 10 | url('../fonts/OpenSans-Regular-webfont.woff') format('woff'), 11 | url('../fonts/OpenSans-Regular-webfont.svg#open_sansregular') format('svg'); 12 | } 13 | 14 | @font-face { 15 | font-family: 'Open Sans Light'; 16 | font-weight: normal; 17 | font-style: normal; 18 | src: url('../fonts/OpenSans-Light-webfont.eot'); 19 | src: 20 | local('Open Sans Light'), 21 | local('OpenSans Light'), 22 | url('../fonts/OpenSans-Light-webfont.eot?#iefix') format('embedded-opentype'), 23 | url('../fonts/OpenSans-Light-webfont.woff') format('woff'), 24 | url('../fonts/OpenSans-Light-webfont.svg#open_sanslight') format('svg'); 25 | } 26 | 27 | html 28 | { 29 | overflow: auto; 30 | background-color: #fff; 31 | font-size: 14px; 32 | } 33 | 34 | body 35 | { 36 | font-family: 'Open Sans', sans-serif; 37 | line-height: 1.5; 38 | color: #4d4e53; 39 | background-color: white; 40 | } 41 | 42 | a, a:visited, a:active { 43 | color: #0095dd; 44 | text-decoration: none; 45 | } 46 | 47 | a:hover { 48 | text-decoration: underline; 49 | } 50 | 51 | header 52 | { 53 | display: block; 54 | padding: 0px 4px; 55 | } 56 | 57 | tt, code, kbd, samp { 58 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 59 | } 60 | 61 | .class-description { 62 | font-size: 130%; 63 | line-height: 140%; 64 | margin-bottom: 1em; 65 | margin-top: 1em; 66 | } 67 | 68 | .class-description:empty { 69 | margin: 0; 70 | } 71 | 72 | #main { 73 | float: left; 74 | width: 70%; 75 | } 76 | 77 | article dl { 78 | margin-bottom: 40px; 79 | } 80 | 81 | article img { 82 | max-width: 100%; 83 | } 84 | 85 | section 86 | { 87 | display: block; 88 | background-color: #fff; 89 | padding: 12px 24px; 90 | border-bottom: 1px solid #ccc; 91 | margin-right: 30px; 92 | } 93 | 94 | .variation { 95 | display: none; 96 | } 97 | 98 | .signature-attributes { 99 | font-size: 60%; 100 | color: #aaa; 101 | font-style: italic; 102 | font-weight: lighter; 103 | } 104 | 105 | nav 106 | { 107 | display: block; 108 | float: right; 109 | margin-top: 28px; 110 | width: 30%; 111 | box-sizing: border-box; 112 | border-left: 1px solid #ccc; 113 | padding-left: 16px; 114 | } 115 | 116 | nav ul { 117 | font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif; 118 | font-size: 100%; 119 | line-height: 17px; 120 | padding: 0; 121 | margin: 0; 122 | list-style-type: none; 123 | } 124 | 125 | nav ul a, nav ul a:visited, nav ul a:active { 126 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 127 | line-height: 18px; 128 | color: #4D4E53; 129 | } 130 | 131 | nav h3 { 132 | margin-top: 12px; 133 | } 134 | 135 | nav li { 136 | margin-top: 6px; 137 | } 138 | 139 | footer { 140 | display: block; 141 | padding: 6px; 142 | margin-top: 12px; 143 | font-style: italic; 144 | font-size: 90%; 145 | } 146 | 147 | h1, h2, h3, h4 { 148 | font-weight: 200; 149 | margin: 0; 150 | } 151 | 152 | h1 153 | { 154 | font-family: 'Open Sans Light', sans-serif; 155 | font-size: 48px; 156 | letter-spacing: -2px; 157 | margin: 12px 24px 20px; 158 | } 159 | 160 | h2, h3.subsection-title 161 | { 162 | font-size: 30px; 163 | font-weight: 700; 164 | letter-spacing: -1px; 165 | margin-bottom: 12px; 166 | } 167 | 168 | h3 169 | { 170 | font-size: 24px; 171 | letter-spacing: -0.5px; 172 | margin-bottom: 12px; 173 | } 174 | 175 | h4 176 | { 177 | font-size: 18px; 178 | letter-spacing: -0.33px; 179 | margin-bottom: 12px; 180 | color: #4d4e53; 181 | } 182 | 183 | h5, .container-overview .subsection-title 184 | { 185 | font-size: 120%; 186 | font-weight: bold; 187 | letter-spacing: -0.01em; 188 | margin: 8px 0 3px 0; 189 | } 190 | 191 | h6 192 | { 193 | font-size: 100%; 194 | letter-spacing: -0.01em; 195 | margin: 6px 0 3px 0; 196 | font-style: italic; 197 | } 198 | 199 | table 200 | { 201 | border-spacing: 0; 202 | border: 0; 203 | border-collapse: collapse; 204 | } 205 | 206 | td, th 207 | { 208 | border: 1px solid #ddd; 209 | margin: 0px; 210 | text-align: left; 211 | vertical-align: top; 212 | padding: 4px 6px; 213 | display: table-cell; 214 | } 215 | 216 | thead tr 217 | { 218 | background-color: #ddd; 219 | font-weight: bold; 220 | } 221 | 222 | th { border-right: 1px solid #aaa; } 223 | tr > th:last-child { border-right: 1px solid #ddd; } 224 | 225 | .ancestors, .attribs { color: #999; } 226 | .ancestors a, .attribs a 227 | { 228 | color: #999 !important; 229 | text-decoration: none; 230 | } 231 | 232 | .clear 233 | { 234 | clear: both; 235 | } 236 | 237 | .important 238 | { 239 | font-weight: bold; 240 | color: #950B02; 241 | } 242 | 243 | .yes-def { 244 | text-indent: -1000px; 245 | } 246 | 247 | .type-signature { 248 | color: #aaa; 249 | } 250 | 251 | .name, .signature { 252 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 253 | } 254 | 255 | .details { margin-top: 14px; border-left: 2px solid #DDD; } 256 | .details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } 257 | .details dd { margin-left: 70px; } 258 | .details ul { margin: 0; } 259 | .details ul { list-style-type: none; } 260 | .details li { margin-left: 30px; padding-top: 6px; } 261 | .details pre.prettyprint { margin: 0 } 262 | .details .object-value { padding-top: 0; } 263 | 264 | .description { 265 | margin-bottom: 1em; 266 | margin-top: 1em; 267 | } 268 | 269 | .code-caption 270 | { 271 | font-style: italic; 272 | font-size: 107%; 273 | margin: 0; 274 | } 275 | 276 | .source 277 | { 278 | border: 1px solid #ddd; 279 | width: 80%; 280 | overflow: auto; 281 | } 282 | 283 | .prettyprint.source { 284 | width: inherit; 285 | } 286 | 287 | .source code 288 | { 289 | font-size: 100%; 290 | line-height: 18px; 291 | display: block; 292 | padding: 4px 12px; 293 | margin: 0; 294 | background-color: #fff; 295 | color: #4D4E53; 296 | } 297 | 298 | .prettyprint code span.line 299 | { 300 | display: inline-block; 301 | } 302 | 303 | .prettyprint.linenums 304 | { 305 | padding-left: 70px; 306 | -webkit-user-select: none; 307 | -moz-user-select: none; 308 | -ms-user-select: none; 309 | user-select: none; 310 | } 311 | 312 | .prettyprint.linenums ol 313 | { 314 | padding-left: 0; 315 | } 316 | 317 | .prettyprint.linenums li 318 | { 319 | border-left: 3px #ddd solid; 320 | } 321 | 322 | .prettyprint.linenums li.selected, 323 | .prettyprint.linenums li.selected * 324 | { 325 | background-color: lightyellow; 326 | } 327 | 328 | .prettyprint.linenums li * 329 | { 330 | -webkit-user-select: text; 331 | -moz-user-select: text; 332 | -ms-user-select: text; 333 | user-select: text; 334 | } 335 | 336 | .params .name, .props .name, .name code { 337 | color: #4D4E53; 338 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 339 | font-size: 100%; 340 | } 341 | 342 | .params td.description > p:first-child, 343 | .props td.description > p:first-child 344 | { 345 | margin-top: 0; 346 | padding-top: 0; 347 | } 348 | 349 | .params td.description > p:last-child, 350 | .props td.description > p:last-child 351 | { 352 | margin-bottom: 0; 353 | padding-bottom: 0; 354 | } 355 | 356 | .disabled { 357 | color: #454545; 358 | } 359 | -------------------------------------------------------------------------------- /docs/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p 2 | 3 | 4 | 5 | JSDoc: Class: Zabbix 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Zabbix

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Zabbix(opts)

32 | 33 |
Zabbix class represents the Zabbix API Client to make JSON-RPC 2.0 protocol 34 | compliant HTTP POST requests. You instantiate a class with an object that 35 | includes the required properties listed below, and then you should call the 36 | login method first to get the valid authentication token. Now you are ready 37 | to make other Zabbix API calls and don't forget to call the logout method 38 | when you are done.
39 | 40 | 41 |
42 | 43 |
44 |
45 | 46 | 47 | 48 | 49 |

Constructor

50 | 51 | 52 | 53 |

new Zabbix(opts)

54 | 55 | 56 | 57 | 58 | 59 | 60 |
61 | The constructor creates an instance of Zabbix class. 62 |
63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
Parameters:
73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 108 | 109 | 110 | 111 | 112 | 113 | 116 | 117 | 118 | 119 | 120 |
NameTypeDescription
opts 101 | 102 | 103 | object 104 | 105 | 106 | 107 | An object contains the details about Zabbix API 114 | server like url, username, password and an optional object for any other 115 | Node.js HTTP options the user may want to send with the request.
121 | 122 | 123 | 124 | 125 | 126 | 127 |
Properties:
128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 166 | 167 | 168 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 195 | 196 | 197 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 224 | 225 | 226 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 253 | 254 | 255 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 |
NameTypeAttributesDescription
url 159 | 160 | 161 | string 162 | 163 | 164 | 165 | 169 | 170 | 171 | 172 | The URL of the Zabbix API endpoint.
user 188 | 189 | 190 | string 191 | 192 | 193 | 194 | 198 | 199 | 200 | 201 | The login name for authentication.
password 217 | 218 | 219 | string 220 | 221 | 222 | 223 | 227 | 228 | 229 | 230 | The password for authentication.
options 246 | 247 | 248 | object 249 | 250 | 251 | 252 | 256 | 257 | <optional>
258 | 259 | 260 | 261 |
Any Nodejs HTTP request supported options.
272 | 273 | 274 | 275 | 276 |
277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 |
Source:
304 |
307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |
315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 |
Example
335 | 336 |
new Zabbix({
337 |   url: 'https://127.0.0.1:8443/api_jsonrpc.php',
338 |   user: 'Admin',
339 |   password: 'zabbix',
340 |   options: {
341 |     rejectUnauthorized: false
342 |   }
343 | })
344 | 345 | 346 | 347 | 348 |
349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 |

Methods

366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 |

(async) login() → {Promise}

374 | 375 | 376 | 377 | 378 | 379 | 380 |
381 | A login method to authenticate with Zabbix. 382 |
383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 |
397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 |
Source:
424 |
427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 |
435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 |
Returns:
451 | 452 | 453 |
454 | - a promise which resolves to the http response from the 455 | Zabbix server of string type authentication token. 456 |
457 | 458 | 459 | 460 |
461 |
462 | Type 463 |
464 |
465 | 466 | Promise 467 | 468 | 469 |
470 |
471 | 472 | 473 | 474 | 475 | 476 | 477 |
Example
478 | 479 |
Zabbix.login()
480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 |

(async) logout() → {Promise}

490 | 491 | 492 | 493 | 494 | 495 | 496 |
497 | A logout method to close the Zabbix server session. 498 |
499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 |
513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 |
Source:
540 |
543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 |
551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 |
Returns:
567 | 568 | 569 |
570 | - a promise which resolves to the http response from the 571 | Zabbix server of boolean truthy value. 572 |
573 | 574 | 575 | 576 |
577 |
578 | Type 579 |
580 |
581 | 582 | Promise 583 | 584 | 585 |
586 |
587 | 588 | 589 | 590 | 591 | 592 | 593 |
Example
594 | 595 |
Zabbix.logout()
596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 |

(async) request(method, params) → {Promise}

606 | 607 | 608 | 609 | 610 | 611 | 612 |
613 | A request method to make Zabbix API calls. 614 |
615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 |
Parameters:
625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 686 | 687 | 688 | 689 | 690 | 691 | 693 | 694 | 695 | 696 | 697 |
NameTypeDescription
method 653 | 654 | 655 | string 656 | 657 | 658 | 659 | the Zabbix API method being called.
params 676 | 677 | 678 | object 679 | | 680 | 681 | array 682 | 683 | 684 | 685 | The parameters that will be passed to the 692 | Zabbix API method.
698 | 699 | 700 | 701 | 702 | 703 | 704 |
705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 |
Source:
732 |
735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 |
743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 |
Returns:
759 | 760 | 761 |
762 | - a promise which resolves to the http response from the 763 | Zabbix server of string, object or array type. 764 |
765 | 766 | 767 | 768 |
769 |
770 | Type 771 |
772 |
773 | 774 | Promise 775 | 776 | 777 |
778 |
779 | 780 | 781 | 782 | 783 | 784 | 785 |
Example
786 | 787 |
Zabbix.request('host.get', { limit: 1 })
788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 |
798 | 799 |
800 | 801 | 802 | 803 | 804 |
805 | 806 | 809 | 810 |
811 | 812 |
813 | Documentation generated by JSDoc 3.6.2 on Fri May 24 2019 19:18:00 GMT-0700 (Pacific Daylight Time) 814 |
815 | 816 | 817 | 818 | 819 | -------------------------------------------------------------------------------- /docs/Client.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Class: Client 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Class: Client

21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |

Client()

32 | 33 |
Class extending Zabbix APIs to useful utility methods.
34 | 35 | 36 |
37 | 38 |
39 |
40 | 41 | 42 | 43 | 44 |

Constructor

45 | 46 | 47 | 48 |

new Client()

49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
Source:
95 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
128 | 129 | 130 |

Extends

131 | 132 | 133 | 134 | 135 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 |

Methods

156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 |

(async, static) sender(options)

164 | 165 | 166 | 167 | 168 | 169 | 170 |
171 | The sender method implements the Zabbix Sender protocol natively in 172 | JavaScript. There is no need to authenticate with Zabbix to use sender 173 | method. Just pass an object with server, host, key and value properties. 174 |
175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 |
Parameters:
185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 220 | 221 | 222 | 223 | 224 | 225 | 227 | 228 | 229 | 230 | 231 |
NameTypeDescription
options 213 | 214 | 215 | object 216 | 217 | 218 | 219 | An object contains the payload to send to Zabbix 226 | sender.
232 | 233 | 234 | 235 | 236 | 237 | 238 |
Properties:
239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 277 | 278 | 279 | 286 | 287 | 288 | 289 | 290 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 309 | 310 | 311 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 338 | 339 | 340 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 367 | 368 | 369 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 399 | 400 | 401 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 |
NameTypeAttributesDescription
port 270 | 271 | 272 | integer 273 | 274 | 275 | 276 | 280 | 281 | <optional>
282 | 283 | 284 | 285 |
Zabbix server port to receive sender traffic. 291 | Defaults to 10051.
server 302 | 303 | 304 | string 305 | 306 | 307 | 308 | 312 | 313 | 314 | 315 | Zabbix server name or IP address
host 331 | 332 | 333 | string 334 | 335 | 336 | 337 | 341 | 342 | 343 | 344 | Zabbix host as configured in frontend
key 360 | 361 | 362 | string 363 | 364 | 365 | 366 | 370 | 371 | 372 | 373 | Zabbix host item key
value 389 | 390 | 391 | string 392 | | 393 | 394 | number 395 | 396 | 397 | 398 | 402 | 403 | 404 | 405 | The value to send
416 | 417 | 418 | 419 | 420 |
421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 |
Source:
448 |
451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 |
459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 |
Example
479 | 480 |
Client.sender({
481 |   server: '127.0.0.1',
482 |   host: 'zabbix.host',
483 |   key: 'item.test.key',
484 |   value: 'Hey there!'
485 | })
486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 |

(async) login() → {Promise}

496 | 497 | 498 | 499 | 500 | 501 | 502 |
503 | A login method to authenticate with Zabbix. 504 |
505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 |
519 | 520 | 521 | 522 | 523 | 524 | 525 |
Inherited From:
526 |
529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 |
Source:
551 |
554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 |
562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 |
Returns:
578 | 579 | 580 |
581 | - a promise which resolves to the http response from the 582 | Zabbix server of string type authentication token. 583 |
584 | 585 | 586 | 587 |
588 |
589 | Type 590 |
591 |
592 | 593 | Promise 594 | 595 | 596 |
597 |
598 | 599 | 600 | 601 | 602 | 603 | 604 |
Example
605 | 606 |
Zabbix.login()
607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 |

(async) logout() → {Promise}

617 | 618 | 619 | 620 | 621 | 622 | 623 |
624 | A logout method to close the Zabbix server session. 625 |
626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 |
640 | 641 | 642 | 643 | 644 | 645 | 646 |
Inherited From:
647 |
650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 |
Source:
672 |
675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 |
683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 |
Returns:
699 | 700 | 701 |
702 | - a promise which resolves to the http response from the 703 | Zabbix server of boolean truthy value. 704 |
705 | 706 | 707 | 708 |
709 |
710 | Type 711 |
712 |
713 | 714 | Promise 715 | 716 | 717 |
718 |
719 | 720 | 721 | 722 | 723 | 724 | 725 |
Example
726 | 727 |
Zabbix.logout()
728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 |

(async) request(method, params) → {Promise}

738 | 739 | 740 | 741 | 742 | 743 | 744 |
745 | A request method to make Zabbix API calls. 746 |
747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 |
Parameters:
757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 818 | 819 | 820 | 821 | 822 | 823 | 825 | 826 | 827 | 828 | 829 |
NameTypeDescription
method 785 | 786 | 787 | string 788 | 789 | 790 | 791 | the Zabbix API method being called.
params 808 | 809 | 810 | object 811 | | 812 | 813 | array 814 | 815 | 816 | 817 | The parameters that will be passed to the 824 | Zabbix API method.
830 | 831 | 832 | 833 | 834 | 835 | 836 |
837 | 838 | 839 | 840 | 841 | 842 | 843 |
Inherited From:
844 |
847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 |
Source:
869 |
872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 |
880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 |
Returns:
896 | 897 | 898 |
899 | - a promise which resolves to the http response from the 900 | Zabbix server of string, object or array type. 901 |
902 | 903 | 904 | 905 |
906 |
907 | Type 908 |
909 |
910 | 911 | Promise 912 | 913 | 914 |
915 |
916 | 917 | 918 | 919 | 920 | 921 | 922 |
Example
923 | 924 |
Zabbix.request('host.get', { limit: 1 })
925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 |
935 | 936 |
937 | 938 | 939 | 940 | 941 |
942 | 943 | 946 | 947 |
948 | 949 |
950 | Documentation generated by JSDoc 3.6.2 on Fri May 24 2019 19:18:00 GMT-0700 (Pacific Daylight Time) 951 |
952 | 953 | 954 | 955 | 956 | --------------------------------------------------------------------------------