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

apc-pdu-snmp

v1.2.0

Published

APC PDU module utilizing SNMP

Downloads

9

Readme

APC PDU SNMP Control

Module for providing basic management of APC PDUs. Such as turning outlets on and off, the current power state and total power draw for the PDU.

Installation

npm install apc-pdu-snmp

Usage

Currently the only option which is supported is host when creating the object.

var apcPdu = require('apc-pdu-snmp');

var pdu = new apcPdu({
  host: '', // IP Address/Hostname
  community: 'private' // Optional community
});

A full range of examples can be found within the examples directory.

Method

getTotalOutlets(callback)

Get the total number of outlets on the PDU.

Arguments

  • callback(err, totalOutlets) - Callback function for error/response handling

Example

pdu.getTotalOutlets(function(err, totalOutlets) {
  if (err) {
    console.log(err);
    return;
  }
  
  console.log('Total outlets:', totalOutlets);
});

getOutletName(outletNumber, callback)

Get an outlet name as configured on the PDU.

Arguments

  • outletNumber - Integer of the outlet number to get the name for
  • callback(err, name) - Callback function for error/response handling

Example

Get the name out outlet 1.

pdu.getOutletName(1, function(err, name) {
  if (err) {
    console.log(err);
    return;
  }
  
  console.log('Outlet 1 name:', name);
});

getOutletNames(callback)

Get all outlet names as configured on the PDU.

Arguments

  • callback(err, names) - Callback function for error/response handling

Example

pdu.getOutletNames(function(err, names) {
  if (err) {
    console.log(err);
    return;
  }
  
  console.log('All outlet names:', names);
});

The names variable will contain an object, keys as the outlet number and the value being the outlet name eg.

{ 
  '1': 'Outlet 1',
  '2': 'Outlet 2',
  '3': 'Outlet 3'
}

getOutletPowerState(outletNumber, callback)

Get the power state of an outlet.

State variable will return either:

  • 0 - off
  • 1 - on

Arguments

  • outletNumber - Integer of the outlet number to get the power state for
  • callback(err, state) - Callback function for error/response handling

Example

Get the power state for outlet 1.

pdu.getOutletPowerState(1, function(err, state) {
  if (err) {
    console.log(err);
    return;
  }
  
  console.log('Outlet 1 is currently:', state == '1' ? 'On' : 'Off');
});

getPowerDraw(callback)

Get the power draw of the whole PDU in amps.

Arguments

  • callback(err, amps) - Callback function for error/response handling

Example

pdu.getPowerDraw(function(err, amps) {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Power draw is currently:', draw, 'amps');
});

getLowLoadThreshold(callback)

Get the configured low load warning threshold in amps.

Arguments

  • callback(err, amps) - Callback function for error/response handling

Example

pdu.getLowLoadThreshold(function(err, amps) {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Low warning threshold is', amps, 'amps');
});

getNearLoadThreshold(callback)

Get the configured near load warning threshold in amps.

Arguments

  • callback(err, amps) - Callback function for error/response handling

Example

pdu.getNearLoadThreshold(function(err, amps) {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Near overload warning threshold is,', amps, 'amps');
});

getOverloadThreshold(callback)

Get the configured overload alarm threshold in amps.

Arguments

  • callback(err, amps) - Callback function for error/response handling

Example

pdu.getOverloadThreshold(function(err, amps) {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Overload alarm threshold is', amps, 'amps');
});

getLoadState(callback)

Get the current load state.

Arguments

  • callback(err, state) - Callback function for error/response handling. The state variable will contain an integer as per the table below.

|State|Translation| |-----|-----------| |1|bankLoadNormal| |2|bankLoadLow| |3|bankLoadNearOverload| |4|bankLoadOverload|

The translated key is available within the library using apcPdu.loadState, as shown in the example below.

Example

pdu.getLoadState(function(err, state) {
  if (err) {
    console.log(err);
    return;
  }

  console.log('The current load state is', apcPdu.loadState[state], '(', state, ')');
});

setPowerState(outletNumber, state, callback)

Turn an outlet on/off.

Arguments

  • outletNumber - Outlet as an integer
  • state - Boolean, true is on, false is off. Alternatively a number, 3 is reboot.
  • callback(err) - Callback for error/success handling

Example

Turn outlet 1 on.

pdu.setPowerState(1, true, function(err) {
  if (err) {
    console.log(err);
    return;
  }
  
  console.log('Successfully turned outlet 1 on');
});

The state variable should be a boolean or number. If a boolean, use true to turn an outlet on and false to turn and outlet off. If a number, use a raw sPDUOutletCtl code:

  • outletOn: 1

  • outletOff: 2

  • outletReboot: 3

  • outletUnknown: 4

  • outletOnWithDelay: 5

  • outletOffWithDelay: 6

  • outletRebootWithDelay: 7

Notes

Hopefully will have some time in the future to improve the features and add some tests as using the examples for testing is pretty bad :)

All the MIBs have been hard coded into this module, for more details see the PowerNet-MIB ftp://ftp.apc.com/apc/public/software/pnetmib/mib/411/powernet411.mib

Acknowledgements

Wouldn't have been able to build this without this great article on SNMP for APC PDUs by Joshua Tobin SNMP Tutorial – APC PDUs

Contributors

Licence

The MIT License (MIT)