EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
test-meshcentral-connection.js
Go to the documentation of this file.
1/**
2 * Test MeshCentral API Connection
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_USER = process.env.MESHCENTRAL_ADMIN_USER || 'admin';
10const MESHCENTRAL_PASSWORD = process.env.MESHCENTRAL_ADMIN_PASS || 'admin';
11
12console.log('šŸ”Œ Testing MeshCentral Connection...\n');
13console.log(`URL: ${MESHCENTRAL_URL}`);
14console.log(`User: ${MESHCENTRAL_USER}`);
15console.log(`Password: ${MESHCENTRAL_PASSWORD.replace(/./g, '*')}\n`);
16
17/**
18 *
19 */
20async function testConnection() {
21 try {
22 const api = new MeshCentralAPI({
23 url: MESHCENTRAL_URL,
24 username: MESHCENTRAL_USER,
25 password: MESHCENTRAL_PASSWORD
26 });
27
28 console.log('1ļøāƒ£ Attempting login...');
29 await api.login();
30 console.log('āœ… Login successful!\n');
31
32 console.log('2ļøāƒ£ Fetching device groups...');
33 const meshes = await api.getMeshes();
34 console.log(`āœ… Found ${meshes.length} device groups:\n`);
35
36 if (meshes.length === 0) {
37 console.log(' (No device groups found)\n');
38 } else {
39 meshes.forEach((mesh, i) => {
40 console.log(` ${i + 1}. ${mesh.name || 'Unnamed'}`);
41 console.log(` ID: ${mesh._id}`);
42 console.log(` Type: ${mesh.mtype || 'unknown'}`);
43 });
44 console.log();
45 }
46
47 console.log('āœ… MeshCentral connection test successful!');
48 return true;
49
50 } catch (error) {
51 console.error('\nāŒ Connection test failed:');
52 console.error(` Error: ${error.message}`);
53 if (error.stack) {
54 console.error(`\n Stack:\n${error.stack}`);
55 }
56 return false;
57 }
58}
59
60testConnection()
61 .then((success) => {
62 process.exit(success ? 0 : 1);
63 });