apc-pdu-snmp

1.2.0 • Public • Published

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)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    0
    • 0.0.1
  • 1.2.0
    1
    • latest

Version History

Package Sidebar

Install

npm i apc-pdu-snmp

Weekly Downloads

1

Version

1.2.0

License

MIT

Last publish

Collaborators

  • phillipsnick