EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
test-meshcentral-api.js
Go to the documentation of this file.
1/**
2 * Test script for MeshCentral API integration
3 */
4
5require('dotenv').config();
6const MeshCentralAPI = require('./lib/meshcentral-api');
7
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';
11
12/**
13 *
14 */
15async function testMeshCentralAPI() {
16 console.log('๐Ÿงช Testing MeshCentral API Integration\n');
17
18 const api = new MeshCentralAPI(MESHCENTRAL_URL, MESHCENTRAL_USERNAME, MESHCENTRAL_PASSWORD);
19
20 try {
21 // Test 1: Login
22 console.log('1๏ธโƒฃ Testing login...');
23 const loginSuccess = await api.login();
24 if (!loginSuccess) {
25 throw new Error('Login failed');
26 }
27 console.log(' โœ… Login successful\n');
28
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');
34
35 // Test 3: Get Meshes
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);
42 });
43 }
44 console.log(' โœ… Meshes retrieved\n');
45
46 // Test 4: Get Nodes
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}:`, {
54 name: parsed.name,
55 hostname: parsed.hostname,
56 connected: parsed.connected,
57 platform: parsed.platform,
58 ip: parsed.ip
59 });
60 });
61 }
62 console.log(' โœ… Nodes retrieved\n');
63
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');
71
72 // Cleanup
73 api.disconnect();
74
75 console.log('โœ… All tests passed!\n');
76
77 } catch (error) {
78 console.error('โŒ Test failed:', error.message);
79 console.error(error.stack);
80 api.disconnect();
81 process.exit(1);
82 }
83}
84
85testMeshCentralAPI();