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

node-nut

v1.0.3

Published

NodeJS client for NUT (Network UPS Tools)

Downloads

3,914

Readme

Node-NUT

Node-NUT is a NodeJS module that implements a NUT (Network UPS Tools) client.

Version compatibility information

v1.0.0 introduce callbacks into all functions including a second "error" parameter. This error parameter is null on success or a text on error. Please see the updated method documentation below.

This change should not break existing code because you can simply ignore the second parameter, but there is one change coming with it:

When with v0.0.x an error occured in one of the "Get-List-Of" methods then the callback was pot. never called at all. This has changed now because now the callback is also called in errorcases, but then with an empty object/list in return. So you may want to include error handling code that not strange things happens in error cases.

Events

ready

This event is emitted when the connection to the NUT server is established.

error

Emitted when there was an error establishing the connection or with the network communication to the server.

close

Emitted when the connection to the NUT server is closed.

Functions (tested)

start()

Starts the connection to the server.

GetUPSList (callback)

Calls the callback function with the list of UPS as an object as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. Keys in the object are the UPS names and the values are the provided description for this UPS.

GetUPSVars (upsname, callback)

Calls the callback function with the list of VARs of upsname as an object as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. Keys in the object are the VAR names and the values are the current VAR values.

GetUPSCommands (upsname, callback)

Calls the callback function with the list of COMMANDs available in upsname as an array as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. The values in the array are the available COMMANDs.

GetCommandDescription (upsname, cmdname, callback)

Calls the callback function with the description for the given cmdname as a string as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. The description is returned as string.

RunUPSCommand (upsname, command, callback)

Rund the COMMAND given by command. The callback is called with one parameter err which is null on success or contains an error string on error and can be used to check the result of the call.

Note: Some commands need to set Username and Password before, else it returns an Error! Please consult the documentation of your UPS system.

SetUsername (username, callback)

Set the password for the connection. The callback is called with one parameter err which is null on success or contains an error string on error and can be used to check the result of the call.

Note: Incorrect values may not generate an error when setting the username, but when executing the command later on!

SetPassword (password, callback)

Set the password for the connection. The callback is called with one parameter err which is null on success or contains an error string on error and can be used to check the result of the call.

Note: Incorrect values may not generate an error when setting the password, but when executing the command later on!

GetRWVars (upsname, callback)

Calls the callback function with the list of RW-VARs of upsname as an object as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. Keys in the object are the RW-VAR names and the values are the current RW-VAR values.

SetRWVar (upsname, varname, value, callback)

Set the value of the RW-VAR given by varname. The callback is called with one parameter err which is null on success or contains an error string on error and can be used to check the result of the call.

GetVarType (upsname, varname, callback)

Calls the callback function with the type for the given varname as a string as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null.

The following types are defined, and multiple words may be returned:

  • RW: this variable may be set to another value with SET
  • ENUM: an enumerated type, which supports a few specific values
  • STRING:n: this is a string of maximum length n
  • RANGE: this is an numeric, either integer or float, comprised in the range (see LIST RANGE)
  • NUMBER: this is a simple numeric value, either integer or float :

For more details see http://networkupstools.org/docs/developer-guide.chunked/ar01s09.html#_type

GetVarDescription (upsname, varname, callback)

Calls the callback function with the description for the given varname as a string as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. The description is returned as string.

GetEnumsForVar (upsname, varname, callback)

Calls the callback function with the list of allowed ENUM values for the given varname as an array as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. The values in the array are the available ENUMs.

GetRangesForVar (upsname, varname, callback)

Calls the callback function with the list of allowed RANGEs for the values for the given varname as an array as the first parameter. If the second parameter is not null then an error happened and the first object is returned as null. The values in the array are objects with the keys min and max for the various ranges.

Master (upsname, callback)

Send the MASTER command to the given upsname. The callback is called with one parameter err which is null on success or contains an error string on error and can be used to check the result of the call.

FSD (upsname, callback)

Send the FSD command to the given upsname. The callback is called with one parameter err which is null on success or contains an error string on error and can be used to check the result of the call.

ListClients (upsname)

help(callback)

Call the callback function with the result of the command help as a string.

ver (callback)

Call the callback function with the version of the server as a string.

netVer (callback)

Call the callback function with the version of the network protocol as a string.

Example

var Nut = require('node-nut');

oNut = new Nut(3493, 'localhost');

oNut.on('error', function(err) {
	console.log('There was an error: ' + err);
});

oNut.on('close', function() {
	console.log('Connection closed.');
});

oNut.on('ready', function() {
	self = this;
	this.GetUPSList(function(upslist, err) {
        if (err) console.log('Error: ' + err)
        console.log(upslist);
		self.close();
	});
});

oNut.start();

Links

Protocol: http://networkupstools.org/docs/developer-guide.chunked/ar01s09.html