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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jaarnio/tripplite-poweralert

v3.0.1

Published

Enterprise-grade Tripplite PDU SDK with singleton connection management and WebSocket real-time monitoring

Readme

@jaarnio/tripplite-poweralert

Enterprise-grade Node.js SDK for Tripplite PDU management with real-time WebSocket monitoring and automatic session management.

Installation

npm install @jaarnio/tripplite-poweralert

Quick Start

const { TripplitePDUSDK } = require('@jaarnio/tripplite-poweralert');

const sdk = new TripplitePDUSDK({
  ip: '192.168.1.100',
  username: 'admin',
  password: 'password'
});

// Start WebSocket server and connect to PDU
await sdk.startWebSocketService();

// Get all outlets
const outlets = await sdk.getAllOutlets();

// Control an outlet
await sdk.controlOutlet(1, 'on');

Features

  • Singleton Connection Management - Prevents session stacking on PDU hardware
  • Automatic Token Management - Persists and reuses authentication tokens across restarts
  • Real-time WebSocket Server - Monitor and control outlets via WebSocket
  • REST API Wrapper - Simple methods for all PDU operations
  • Automatic Session Refresh - Tokens refresh before expiry
  • Built-in Caching - Reduces API calls with intelligent caching

API Reference

Constructor

new TripplitePDUSDK(config)

Config Options:

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | ip | string | Yes | - | PDU IP address | | username | string | Yes | - | PDU username | | password | string | Yes | - | PDU password | | port | number | No | 443 | PDU HTTPS port | | wsPort | number | No | 8080 | WebSocket server port | | pollInterval | number | No | 5000 | State polling interval (ms) | | persistTokens | boolean | No | true | Save tokens to disk | | tokenStorePath | string | No | ~/.tripplite-pdu-tokens/{ip}.json | Token storage location |

Methods

startWebSocketService(port?: number): Promise<void>

Start the WebSocket server and connect to PDU.

await sdk.startWebSocketService(8080);

getAllOutlets(): Promise<Outlet[]>

Get all outlet states.

const outlets = await sdk.getAllOutlets();
// Returns: [{ id: 1, name: "Server", state: "on", description: "Main Server" }]

getOutlet(outletId: number): Promise<Outlet>

Get specific outlet state.

const outlet = await sdk.getOutlet(1);

controlOutlet(outletId: number, action: 'on' | 'off' | 'cycle'): Promise<boolean>

Control outlet power state.

await sdk.controlOutlet(1, 'on');   // Turn on
await sdk.controlOutlet(1, 'off');  // Turn off
await sdk.controlOutlet(1, 'cycle'); // Power cycle

renameOutlet(outletId: number, newName: string, description?: string): Promise<Outlet>

Rename an outlet and optionally update its description.

await sdk.renameOutlet(1, 'Database Server');
// Or with description
await sdk.renameOutlet(1, 'Database Server', 'Primary PostgreSQL instance');

getDeviceInfo(): Promise<PDUDevice>

Get PDU device information.

const info = await sdk.getDeviceInfo();
// Returns: { model: "PDUMH15NET", name: "PDU-01", ... }

stop(): Promise<void>

Stop the SDK and clean up connections.

await sdk.stop();

getStats(): object

Get WebSocket server and cache statistics.

const stats = sdk.getStats();
// Returns: {
//   running: true,
//   clients: 2,
//   outlets: 8,
//   cacheStats: {
//     hits: 45,
//     misses: 12,
//     size: 8
//   }
// }

WebSocket Protocol

Connect to the WebSocket server to receive real-time updates:

const ws = new WebSocket('ws://localhost:8080');

// Subscribe to updates
ws.send(JSON.stringify({
  action: 'subscribe',
  type: 'full'  // or 'outlet' with outletIds: [1, 2, 3]
}));

Message Types

Connection

{
  "type": "connection",
  "status": "connected",
  "version": "1.0.0",
  "timestamp": "2024-01-01T12:00:00Z"
}

Initial State

{
  "type": "initial_state",
  "data": {
    "device": { "model": "PDUMH15NET", "name": "PDU-01" },
    "outlets": [
      { "id": 1, "name": "Server", "state": "on", "description": "Main Server" }
    ]
  }
}

State Update

{
  "type": "update",
  "changes": [
    {
      "outlet": 1,
      "field": "state",
      "oldValue": "off",
      "newValue": "on"
    }
  ]
}

Control Outlet

{
  "action": "action",
  "outletId": 1,
  "operation": "on"
}

Rename Outlet

{
  "action": "rename",
  "outletId": 1,
  "name": "New Name",
  "description": "New Description"
}

Token Persistence

The SDK automatically saves authentication tokens to prevent session stacking. Tokens are stored at:

  • Linux/Mac: ~/.tripplite-pdu-tokens/{ip}.json
  • Windows: %USERPROFILE%\.tripplite-pdu-tokens\{ip}.json

To disable token persistence:

const sdk = new TripplitePDUSDK({
  ip: '192.168.1.100',
  username: 'admin',
  password: 'password',
  persistTokens: false
});

Examples

Basic Server

const { TripplitePDUSDK } = require('@jaarnio/tripplite-poweralert');

async function main() {
  const sdk = new TripplitePDUSDK({
    ip: process.env.PDU_IP,
    username: process.env.PDU_USER,
    password: process.env.PDU_PASS
  });

  await sdk.startWebSocketService();
  
  const outlets = await sdk.getAllOutlets();
  outlets.forEach(outlet => {
    console.log(`Outlet ${outlet.id}: ${outlet.state}`);
  });

  // Handle shutdown
  process.on('SIGINT', async () => {
    await sdk.stop();
    process.exit(0);
  });
}

main().catch(console.error);

WebSocket Client

const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8080');

ws.on('open', () => {
  // Subscribe to all outlets
  ws.send(JSON.stringify({
    action: 'subscribe',
    type: 'full'
  }));
});

ws.on('message', (data) => {
  const message = JSON.parse(data);
  console.log('Received:', message.type);
  
  if (message.type === 'update') {
    message.changes.forEach(change => {
      console.log(`Outlet ${change.outlet}: ${change.field} = ${change.newValue}`);
    });
  }
});

Error Handling

The SDK throws errors for connection and authentication issues:

try {
  await sdk.startWebSocketService();
} catch (error) {
  if (error.code === 'AUTH_FAILED') {
    console.error('Authentication failed:', error.message);
  } else if (error.code === 'PDU_UNREACHABLE') {
    console.error('Cannot connect to PDU:', error.message);
  }
}

Environment Variables

Create a .env file for configuration:

PDU_IP=192.168.1.100
PDU_USER=admin
PDU_PASS=password

Requirements

  • Node.js >= 16.0.0
  • Network access to Tripplite PDU
  • PDU credentials with API access

License

MIT

Support

For issues and questions, visit: https://github.com/jaarnio/tripplite-poweralert/issues