Files
nut-ups-mcp/test_nut.js

94 lines
3.1 KiB
JavaScript
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* Quick test script to verify NUT UPS MCP functionality
*/
import { NUTClient } from './dist/client.js';
import { config } from 'dotenv';
// Load environment variables
config();
const NUT_HOST = process.env.NUT_HOST || 'localhost';
const NUT_PORT = parseInt(process.env.NUT_PORT || '3493');
const NUT_USERNAME = process.env.NUT_USERNAME;
const NUT_PASSWORD = process.env.NUT_PASSWORD;
async function testNUTConnection() {
console.log('🔌 Connecting to NUT server...');
console.log(` Host: ${NUT_HOST}:${NUT_PORT}`);
console.log(` User: ${NUT_USERNAME || '(no auth)'}\n`);
const client = new NUTClient(NUT_HOST, NUT_PORT, NUT_USERNAME, NUT_PASSWORD);
try {
// Connect
await client.connect();
console.log('✅ Connected successfully!\n');
// List UPS devices
console.log('📋 Listing UPS devices...');
const devices = await client.listUPS();
console.log(`Found ${devices.length} UPS device(s):\n`);
devices.forEach(d => {
console.log(`${d.name}: ${d.description}`);
});
console.log('');
if (devices.length > 0) {
const upsName = devices[0].name;
console.log(`📊 Getting complete status for: ${upsName}\n`);
// Get all variables
const vars = await client.getUPSVars(upsName);
// Group variables by category
const battery = vars.filter(v => v.name.startsWith('battery.'));
const input = vars.filter(v => v.name.startsWith('input.'));
const output = vars.filter(v => v.name.startsWith('output.'));
const ups = vars.filter(v => v.name.startsWith('ups.'));
const device = vars.filter(v => v.name.startsWith('device.'));
console.log('🔋 BATTERY STATUS:');
battery.forEach(v => console.log(` ${v.name}: ${v.value}`));
console.log('\n⚡ INPUT:');
input.forEach(v => console.log(` ${v.name}: ${v.value}`));
console.log('\n🔌 OUTPUT:');
output.forEach(v => console.log(` ${v.name}: ${v.value}`));
console.log('\n🖥 UPS:');
ups.forEach(v => console.log(` ${v.name}: ${v.value}`));
console.log('\n🔧 DEVICE:');
device.forEach(v => console.log(` ${v.name}: ${v.value}`));
// Show other variables
const other = vars.filter(v =>
!v.name.startsWith('battery.') &&
!v.name.startsWith('input.') &&
!v.name.startsWith('output.') &&
!v.name.startsWith('ups.') &&
!v.name.startsWith('device.')
);
if (other.length > 0) {
console.log('\n📝 OTHER:');
other.forEach(v => console.log(` ${v.name}: ${v.value}`));
}
}
client.disconnect();
console.log('\n✅ Test completed successfully!');
} catch (error) {
console.error('\n❌ Error:', error.message);
client.disconnect();
process.exit(1);
}
}
testNUTConnection();