2 * Test script for MeshCentral API integration
5require('dotenv').config();
6const MeshCentralAPI = require('./lib/meshcentral-api');
8const MESHCENTRAL_URL = process.env.MESHCENTRAL_URL || 'https://rmm-psa-meshcentral-aq48h.ondigitalocean.app';
9const MESHCENTRAL_USERNAME = process.env.MESHCENTRAL_USERNAME || '~t:2jt4e92jNss43lyJ';
10const MESHCENTRAL_PASSWORD = process.env.MESHCENTRAL_PASSWORD || '2GimaJ6MJDlq6P2Jrsso';
15async function testMeshCentralAPI() {
16 console.log('๐งช Testing MeshCentral API Integration\n');
18 const api = new MeshCentralAPI(MESHCENTRAL_URL, MESHCENTRAL_USERNAME, MESHCENTRAL_PASSWORD);
22 console.log('1๏ธโฃ Testing login...');
23 const loginSuccess = await api.login();
25 throw new Error('Login failed');
27 console.log(' โ
Login successful\n');
29 // Test 2: Get Server Info
30 console.log('2๏ธโฃ Testing server info...');
31 const serverInfo = await api.getServerInfo();
32 console.log(' ๐ Server:', JSON.stringify(serverInfo, null, 2));
33 console.log(' โ
Server info retrieved\n');
36 console.log('3๏ธโฃ Testing get meshes...');
37 const meshes = await api.getMeshes();
38 console.log(` ๐ฆ Found ${meshes.length} mesh(es)`);
39 if (meshes.length > 0) {
40 meshes.forEach((mesh, i) => {
41 console.log(` Mesh ${i + 1}:`, mesh._id || mesh.meshid, '-', mesh.name);
44 console.log(' โ
Meshes retrieved\n');
47 console.log('4๏ธโฃ Testing get nodes...');
48 const nodes = await api.getNodes();
49 console.log(` ๐ฅ๏ธ Found ${nodes.length} device(s)`);
50 if (nodes.length > 0) {
51 nodes.forEach((node, i) => {
52 const parsed = MeshCentralAPI.parseNodeData(node);
53 console.log(` Device ${i + 1}:`, {
55 hostname: parsed.hostname,
56 connected: parsed.connected,
57 platform: parsed.platform,
62 console.log(' โ
Nodes retrieved\n');
64 // Test 5: Generate Login Token
65 console.log('5๏ธโฃ Testing login token generation...');
66 const tokenData = await api.generateLoginToken();
67 console.log(' ๐๏ธ Token:', tokenData.token.substring(0, 20) + '...');
68 console.log(' ๐ Embed URL:', tokenData.embedUrl.substring(0, 60) + '...');
69 console.log(' โฐ Expires:', tokenData.expiresAt);
70 console.log(' โ
Login token generated\n');
75 console.log('โ
All tests passed!\n');
78 console.error('โ Test failed:', error.message);
79 console.error(error.stack);