npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bettercorp/node-zabbix-sender

v2.0.12

Published

A zabbix_sender implementation, to send zabbix item(s) using the zabbix trapper protocol in NodeJS/Typescript.

Downloads

32

Readme

About this library

The library is an implementation of zabbix_sender utility, which sends items data to zabbix server using the zabbix trapper protocol. Because the library is a pure Node.js/Typescript implementation, it doesn't require invocation of zabbix_sender utility. So there is no any child_process involved!

Basic usage example

import { ZabbixSender } from '@bettercorp/node-zabbix-sender'
const Sender = new ZabbixSender('zabbix.example.com');

// Add items to request
let req = Sender.add('webserver', 'httpd.running', 0);
req.add('mysql.ping', 1, 'dbserver');

// Add item with default host
req.add('httpd.logs.size', 1024);

// Add item with timestamp 
req.add('httpd.running', 1, 1634645976, 'webserver');

// Add item with timestamp and nanoseconds
req.add('mysql.ping', 0, 1634645976, 758000000, 'dbserver');

// Add item with default host with timestamp. The host has to be set to an empty string in this case.
req.add('httpd.logs.size', 1024, 1634645976);

// Send the items to zabbix trapper
console.dir(await req.send());

Another example, with addItem & send combined

import { ZabbixSender } from '@bettercorp/node-zabbix-sender'  
const Sender = new ZabbixSender('zabbix.example.com');  

// Here is an example: add item and & send it  
console.log(await Sender.add('cpu_load', 0.15).send());  

// Or just send a single item quickly  
console.log(await Sender.send('cpu_load', 0.15));

Instance options

Whenever you create a new instance of zabbix sender, there are several property options:

(host: string, port: number = 10051, timeout: number = 5000, timestamps: boolean = false, nsTiming: boolean = false, hostname: string = hostname()))
  • host and port are self-explanatory, the zabbix server host & port
  • timeout is a socket timeout in milliseconds, when connecting to the zabbix server
  • timestamps when you add, timestamp will be added as well
  • nsTiming will set timestamps to true, nanoseconds portion of the timestamp seconds will be added to the item
  • hostname a target monitored host in zabbix. used when you don't specify the host when you add, see example above

Instance methods

(item: ZabbixSenderItem)  
(key: string, value: number)  
(key: string, value: number, hostname: string)  
(key: string, value: number, timestamp: number)  
(key: string, value: number, timestamp: number, hostname: string)  
(key: string, value: number, timestamp: number, ns: number)  
(key: string, value: number, timestamp: number, ns: number, hostname: string)  

Adds an item to the request payload. ns or timestamp can only be set if timestamps and nsTiming are also set to true respectively. If timestamps and nsTiming are true respectively but not set in this request, the current system time will be used.
The return value is self instance, so chaining can be used.

.length

Just returns the number of items.

send()

Sends all items that were added to the request payload. In case of error, the previously added items will be kept, for the next send invocation.

Protocol References

  • https://www.zabbix.com/documentation/6.0/manual/appendix/items/trapper
  • https://www.zabbix.com/documentation/6.0/manual/appendix/protocols/header_datalen

License

Licensed under the MIT License. See the LICENSE file for details.