-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the whole project with async/await and no dependency (#15)
* v2.0.0 * shellcheck SC1117 fix * remove postgres port forwarding from docker-compose * remove unsed dev dependency * bug fix * compatibility fix for node 8 * docs update
- Loading branch information
1 parent
5e56188
commit e20f5c0
Showing
19 changed files
with
612 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ npm-debug.log | |
package-lock.json | ||
node_modules | ||
coverage | ||
.nyc_output | ||
out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ sudo: required | |
|
||
language: node_js | ||
node_js: | ||
- "6" | ||
- "8" | ||
- "9" | ||
- "10" | ||
- "12" | ||
|
||
services: | ||
- docker | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,58 @@ | ||
# Zabbix API Client (zabbix-promise) | ||
# Zabbix API Client | ||
|
||
[Zabbix](https://www.zabbix.com/) is an open source monitoring software for | ||
networks and applications. It is designed to monitor and track the status of | ||
various network services, servers, and hardware. | ||
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/). | ||
|
||
**Zabbix-promise** is an abstract module written in JavaScript for | ||
[Node.js >= 6](https://nodejs.org/) to interface with the | ||
[Zabbix API >= 3.0](https://www.zabbix.com/documentation/3.0/manual/api) using | ||
ES2015 native promises. | ||
**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. | ||
|
||
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). | ||
|
||
**Table of Contents** | ||
|
||
<!-- toc --> | ||
|
||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [getHost](examples/getHost.js) | ||
- [createHost](examples/createHost.js) | ||
- [zabbixSender](examples/zabbixSender.js) | ||
- [Debugging](#debugging) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
<!-- tocstop --> | ||
|
||
## Install | ||
|
||
`npm install zabbix-promise --save` | ||
```js | ||
$ npm install zabbix-promise --save | ||
``` | ||
|
||
## Usage | ||
|
||
## Examples | ||
Please check the examples below to get started. | ||
|
||
- [getHost](examples/getHost.js) | ||
- [createHost](examples/createHost.js) | ||
- [getEvents](examples/getEvents.js) | ||
- [sendValues](examples/sendValues.js) | ||
- [zabbixSender](examples/zabbixSender.js) | ||
|
||
## Debugging | ||
|
||
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*`. | ||
|
||
```js | ||
$ NODE_DEBUG=zp* node getHost.js | ||
``` | ||
|
||
## Contributing | ||
|
||
👋Thanks for thinking about contributing to zabbix-promise! There are a few ways you may contribute to the project. | ||
|
||
1. Use the package in your projects and report any bugs you may find by filing issues. | ||
2. Submit examples to cover the Zabbix APIs that are not in examples already by sending pull request. | ||
3. Submit test cases to cover all or most of the Zabbix APIs by sending pull request. | ||
|
||
## License | ||
|
||
[MIT](LICENSE) | ||
|
||
Copyright (c) 2016-2019 Sumit Goel. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
/** | ||
* In this example, we will create a Zabbix host "yet-another-host". | ||
* We need at least one host group and interface details as this information | ||
* is required to create a new host. We will query the host groups and get the | ||
* last group id from the return values. | ||
*/ | ||
|
||
const Zabbix = require('../index') | ||
|
||
const whiteSpaceCount = 2 | ||
const zabbix = new Zabbix( | ||
'http://127.0.0.1:8080/api_jsonrpc.php', | ||
'Admin', | ||
'zabbix' | ||
) | ||
const zabbix = new Zabbix({ | ||
url: 'http://127.0.0.1:8080/api_jsonrpc.php', | ||
user: 'Admin', | ||
password: 'zabbix' | ||
}) | ||
|
||
zabbix.login() | ||
.then(() => zabbix.request('host.create', { | ||
'host': 'zabbix-agent1', | ||
'groups': [{ 'groupid': '2' }], | ||
'interfaces': [ | ||
{ | ||
'dns': 'zabbix-agent1', | ||
'ip': '', | ||
'main': 1, | ||
'port': '10050', | ||
'type': 1, | ||
'useip': 0 | ||
} | ||
], | ||
'templates': [{ 'templateid': '10001' }], | ||
'inventory_mode': 1 | ||
})) | ||
.then((value) => console.log(JSON.stringify(value, null, whiteSpaceCount))) | ||
.then(() => zabbix.logout()) | ||
.catch((reson) => console.log(JSON.stringify(reson, null, whiteSpaceCount))) | ||
const main = async () => { | ||
try { | ||
await zabbix.login() | ||
const groups = await zabbix.request('hostgroup.get', {}) | ||
const groupId = groups[groups.length - 1].groupid | ||
const host = await zabbix.request('host.create', { | ||
host: 'yet-another-host', | ||
groups: [{ groupid: groupId }], | ||
interfaces: [{ | ||
type: 1, | ||
main: 1, | ||
useip: 1, | ||
ip: '127.0.0.1', | ||
dns: '', | ||
port: '10050' | ||
}] | ||
}) | ||
console.log(host) | ||
zabbix.logout() | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
/** | ||
* In this example, we will query Zabbix hosts and apply a filter for host | ||
* "zabbix-promise-host" and include the interfaces as well. | ||
*/ | ||
|
||
const Zabbix = require('../index') | ||
|
||
const whiteSpaceCount = 2 | ||
const zabbix = new Zabbix( | ||
'http://127.0.0.1:8080/api_jsonrpc.php', | ||
'Admin', | ||
'zabbix' | ||
) | ||
const zabbix = new Zabbix({ | ||
url: 'http://127.0.0.1:8080/api_jsonrpc.php', | ||
user: 'Admin', | ||
password: 'zabbix' | ||
}) | ||
|
||
zabbix.login() | ||
.then(() => zabbix.request('host.get', { | ||
'output': [ | ||
'hostid', | ||
'host' | ||
], | ||
'limit': 1 | ||
})) | ||
.then((value) => console.log(JSON.stringify(value, null, whiteSpaceCount))) | ||
.then(() => zabbix.logout()) | ||
.catch((reson) => console.log(JSON.stringify(reson, null, whiteSpaceCount))) | ||
const main = async () => { | ||
try { | ||
await zabbix.login() | ||
const hosts = await zabbix.request('host.get', { | ||
selectInterfaces: 'extend', | ||
filter: { | ||
host: 'zabbix-promise-host' | ||
} | ||
}) | ||
console.log(JSON.stringify(hosts, null, 2)) | ||
zabbix.logout() | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* In this example, we will send values to Zabbix trapper item type. There is | ||
* no need for Zabbix Sender binary as zabbix-promise package implements the | ||
* sender protocol in native JavaScript/Node.js. | ||
*/ | ||
|
||
const zabbix = require('../index') | ||
|
||
const main = async () => { | ||
try { | ||
const result = await zabbix.sender({ | ||
server: '127.0.0.1', | ||
host: 'zabbix-promise-host', | ||
key: 'zabbix.promise.key', | ||
value: Math.random() | ||
}) | ||
console.log(result) | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
main() |
Oops, something went wrong.