2 * Test MeshCentral API Connection
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_USER = process.env.MESHCENTRAL_ADMIN_USER || 'admin';
10const MESHCENTRAL_PASSWORD = process.env.MESHCENTRAL_ADMIN_PASS || 'admin';
12console.log('š Testing MeshCentral Connection...\n');
13console.log(`URL: ${MESHCENTRAL_URL}`);
14console.log(`User: ${MESHCENTRAL_USER}`);
15console.log(`Password: ${MESHCENTRAL_PASSWORD.replace(/./g, '*')}\n`);
20async function testConnection() {
22 const api = new MeshCentralAPI({
24 username: MESHCENTRAL_USER,
25 password: MESHCENTRAL_PASSWORD
28 console.log('1ļøā£ Attempting login...');
30 console.log('ā
Login successful!\n');
32 console.log('2ļøā£ Fetching device groups...');
33 const meshes = await api.getMeshes();
34 console.log(`ā
Found ${meshes.length} device groups:\n`);
36 if (meshes.length === 0) {
37 console.log(' (No device groups found)\n');
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'}`);
47 console.log('ā
MeshCentral connection test successful!');
51 console.error('\nā Connection test failed:');
52 console.error(` Error: ${error.message}`);
54 console.error(`\n Stack:\n${error.stack}`);
62 process.exit(success ? 0 : 1);