EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
check-meshes.js
Go to the documentation of this file.
1#!/usr/bin/env node
2require('dotenv').config();
3const MeshCentralAPI = require('../lib/meshcentral-api');
4
5/**
6 *
7 */
8async function checkMeshes() {
9 console.log('šŸ” Checking MeshCentral device groups...\n');
10
11 const api = new MeshCentralAPI({
12 url: process.env.MESHCENTRAL_URL,
13 username: process.env.MESHCENTRAL_ADMIN_USER || process.env.MESHCENTRAL_USERNAME,
14 password: process.env.MESHCENTRAL_ADMIN_PASS || process.env.MESHCENTRAL_PASSWORD
15 });
16
17 try {
18 // Login
19 console.log('šŸ”‘ Logging in...');
20 await api.login();
21 console.log('āœ… Logged in successfully\n');
22
23 // Get all meshes
24 console.log('šŸ“¦ Fetching device groups...');
25 const meshes = await api.getMeshes();
26
27 // Close WebSocket
28 if (api.ws) {
29 api.ws.close();
30 }
31
32 console.log(`\nāœ… Found ${meshes.length} device group(s):\n`);
33
34 if (meshes.length === 0) {
35 console.log(' (No device groups found)');
36 } else {
37 meshes.forEach((mesh, index) => {
38 console.log(` ${index + 1}. ${mesh.name || 'Unnamed'}`);
39 console.log(` ID: ${mesh._id}`);
40 console.log(` Type: ${mesh.mtype === 2 ? 'Agent Mesh' : 'Unknown'}`);
41 console.log('');
42 });
43 }
44
45 } catch (error) {
46 console.error('āŒ Error:', error.message);
47 process.exit(1);
48 } finally {
49 process.exit(0);
50 }
51}
52
53checkMeshes();