Files
nupst/ts/constants.ts

175 lines
3.9 KiB
TypeScript

/**
* NUPST Constants
*
* Central location for all timeout, interval, and threshold values.
* This makes configuration easier and code more self-documenting.
*/
/**
* Default timing values in milliseconds
*/
export const TIMING = {
/** Default interval between UPS status checks (30 seconds) */
CHECK_INTERVAL_MS: 30000,
/** Interval for idle monitoring mode (60 seconds) */
IDLE_CHECK_INTERVAL_MS: 60000,
/** Interval for checking config file changes (60 seconds) */
CONFIG_CHECK_INTERVAL_MS: 60000,
/** Interval for logging periodic status updates (5 minutes) */
LOG_INTERVAL_MS: 5 * 60 * 1000,
/** Maximum time to monitor during shutdown (5 minutes) */
MAX_SHUTDOWN_MONITORING_MS: 5 * 60 * 1000,
/** Interval for UPS checks during shutdown (30 seconds) */
SHUTDOWN_CHECK_INTERVAL_MS: 30000,
} as const;
/**
* SNMP-related constants
*/
export const SNMP = {
/** Default SNMP port */
DEFAULT_PORT: 161,
/** Default SNMP timeout (5 seconds) */
DEFAULT_TIMEOUT_MS: 5000,
/** Number of SNMP retries */
RETRIES: 2,
/** Timeout for noAuthNoPriv security level (5 seconds) */
TIMEOUT_NO_AUTH_MS: 5000,
/** Timeout for authNoPriv security level (10 seconds) */
TIMEOUT_AUTH_MS: 10000,
/** Timeout for authPriv security level (15 seconds) */
TIMEOUT_AUTH_PRIV_MS: 15000,
/** Maximum timeout for connection tests (10 seconds) */
MAX_TEST_TIMEOUT_MS: 10000,
} as const;
/**
* Default threshold values
*/
export const THRESHOLDS = {
/** Default battery capacity threshold for shutdown (60%) */
DEFAULT_BATTERY_PERCENT: 60,
/** Default runtime threshold for shutdown (20 minutes) */
DEFAULT_RUNTIME_MINUTES: 20,
/** Emergency runtime threshold during shutdown (5 minutes) */
EMERGENCY_RUNTIME_MINUTES: 5,
} as const;
/**
* Webhook action constants
*/
export const WEBHOOK = {
/** Default webhook request timeout (10 seconds) */
DEFAULT_TIMEOUT_MS: 10000,
} as const;
/**
* Script action constants
*/
export const SCRIPT = {
/** Default script execution timeout (60 seconds) */
DEFAULT_TIMEOUT_MS: 60000,
} as const;
/**
* Shutdown action constants
*/
export const SHUTDOWN = {
/** Default shutdown delay (5 minutes) */
DEFAULT_DELAY_MINUTES: 5,
} as const;
/**
* HTTP Server constants
*/
export const HTTP_SERVER = {
/** Default HTTP server port */
DEFAULT_PORT: 8080,
/** Default URL path for UPS status endpoint */
DEFAULT_PATH: '/ups-status',
} as const;
/**
* Network failure detection constants
*/
export const NETWORK = {
/** Number of consecutive failures before marking UPS as unreachable */
CONSECUTIVE_FAILURE_THRESHOLD: 3,
/** Maximum tracked consecutive failures (prevents overflow) */
MAX_CONSECUTIVE_FAILURES: 100,
} as const;
/**
* UPSD/NIS protocol constants
*/
export const UPSD = {
/** Default UPSD port (NUT standard) */
DEFAULT_PORT: 3493,
/** Default timeout in milliseconds */
DEFAULT_TIMEOUT_MS: 5000,
/** Default NUT device name */
DEFAULT_UPS_NAME: 'ups',
} as const;
/**
* Pause/resume constants
*/
export const PAUSE = {
/** Path to the pause state file */
FILE_PATH: '/etc/nupst/pause',
/** Maximum pause duration (24 hours) */
MAX_DURATION_MS: 24 * 60 * 60 * 1000,
} as const;
/**
* Proxmox VM shutdown constants
*/
export const PROXMOX = {
/** Default Proxmox API port */
DEFAULT_PORT: 8006,
/** Default Proxmox host */
DEFAULT_HOST: 'localhost',
/** Default timeout for VM/CT shutdown in seconds */
DEFAULT_STOP_TIMEOUT_SECONDS: 120,
/** Poll interval for checking VM/CT status in seconds */
STATUS_POLL_INTERVAL_SECONDS: 5,
/** Proxmox API base path */
API_BASE: '/api2/json',
} as const;
/**
* UI/Display constants
*/
export const UI = {
/** Default width for log boxes */
DEFAULT_BOX_WIDTH: 45,
/** Wide box width for status displays */
WIDE_BOX_WIDTH: 60,
/** Extra wide box width for detailed info */
EXTRA_WIDE_BOX_WIDTH: 70,
} as const;