Files
nupst/ts/snmp/types.ts
Juergen Kunz bb87316dd3
All checks were successful
CI / Type Check & Lint (push) Successful in 7s
CI / Build Test (Current Platform) (push) Successful in 5s
Release / build-and-release (push) Successful in 44s
CI / Build All Platforms (push) Successful in 49s
fix(snmp): correct power status interpretation using OID set mappings
Move power status value interpretation from hardcoded logic to OID set configuration.
Each UPS model now defines its own value mappings (e.g., CyberPower: 2=online, 3=onBattery).

Fixes incorrect status display where UPS showed "On Battery" when actually online.

Changes:
- Add POWER_STATUS_VALUES to IOidSet interface
- Define value mappings for all UPS models (cyberpower, apc, eaton, tripplite, liebert)
- Refactor determinePowerStatus() to use OID set mappings instead of hardcoded values
- CyberPower now correctly interprets value 2 as online (was incorrectly onBattery)
2025-10-19 23:48:13 +00:00

102 lines
2.4 KiB
TypeScript

/**
* Type definitions for SNMP module
*/
import { Buffer } from 'node:buffer';
/**
* UPS status interface
*/
export interface IUpsStatus {
/** Current power status */
powerStatus: 'online' | 'onBattery' | 'unknown';
/** Battery capacity percentage */
batteryCapacity: number;
/** Remaining runtime in minutes */
batteryRuntime: number;
/** Raw values from SNMP responses */
raw: Record<string, any>;
}
/**
* SNMP OID Sets for different UPS brands
*/
export interface IOidSet {
/** OID for power status */
POWER_STATUS: string;
/** OID for battery capacity */
BATTERY_CAPACITY: string;
/** OID for battery runtime */
BATTERY_RUNTIME: string;
/** Power status value mappings */
POWER_STATUS_VALUES?: {
/** SNMP value that indicates UPS is online (on AC power) */
online: number;
/** SNMP value that indicates UPS is on battery */
onBattery: number;
};
}
/**
* Supported UPS model types
*/
export type TUpsModel = 'cyberpower' | 'apc' | 'eaton' | 'tripplite' | 'liebert' | 'custom';
/**
* SNMP Configuration interface
*/
export interface ISnmpConfig {
/** SNMP server host */
host: string;
/** SNMP server port (default 161) */
port: number;
/** SNMP version (1, 2, or 3) */
version: number;
/** Timeout in milliseconds */
timeout: number;
context?: string;
// SNMPv1/v2c
/** Community string for SNMPv1/v2c */
community?: string;
// SNMPv3
/** Security level for SNMPv3 */
securityLevel?: 'noAuthNoPriv' | 'authNoPriv' | 'authPriv';
/** Username for SNMPv3 authentication */
username?: string;
/** Authentication protocol for SNMPv3 */
authProtocol?: 'MD5' | 'SHA';
/** Authentication key for SNMPv3 */
authKey?: string;
/** Privacy protocol for SNMPv3 */
privProtocol?: 'DES' | 'AES';
/** Privacy key for SNMPv3 */
privKey?: string;
// UPS model and custom OIDs
/** UPS model for OID selection */
upsModel?: TUpsModel;
/** Custom OIDs when using custom UPS model */
customOIDs?: IOidSet;
}
/**
* SNMPv3 security parameters
*/
export interface ISnmpV3SecurityParams {
/** Engine ID for the SNMP server */
msgAuthoritativeEngineID: Buffer;
/** Engine boots counter */
msgAuthoritativeEngineBoots: number;
/** Engine time counter */
msgAuthoritativeEngineTime: number;
/** Username for authentication */
msgUserName: string;
/** Authentication parameters */
msgAuthenticationParameters: Buffer;
/** Privacy parameters */
msgPrivacyParameters: Buffer;
}