EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
get-meshcentral-nodeid.js
Go to the documentation of this file.
1const MeshCentralAPI = require('./lib/meshcentral-api.js');
2require('dotenv').config();
3
4const api = new MeshCentralAPI({
5 url: process.env.MESHCENTRAL_URL,
6 username: process.env.MESHCENTRAL_USERNAME,
7 password: process.env.MESHCENTRAL_PASSWORD
8});
9
10/**
11 *
12 */
13async function main() {
14 try {
15 console.log('šŸ” Logging in to MeshCentral...');
16 await api.login();
17
18 console.log('šŸ“” Scraping device list from web interface...');
19 const html = await api._request('GET', '/');
20
21 // Extract node IDs from the HTML
22 const nodeMatches = html.match(/node\/[a-zA-Z0-9\/_-]+/g) || [];
23 const uniqueNodes = [...new Set(nodeMatches)];
24
25 if (uniqueNodes.length === 0) {
26 console.log('āŒ No devices found. Make sure the MeshAgent is running and connected.');
27 return;
28 }
29
30 console.log(`\nāœ… Found ${uniqueNodes.length} device(s):\n`);
31 uniqueNodes.forEach((nodeId, index) => {
32 console.log(`${index + 1}. ${nodeId}`);
33 });
34
35 // Try to get more details for the first device
36 if (uniqueNodes.length > 0) {
37 console.log('\nšŸ“‹ First device details:');
38 console.log('Node ID:', uniqueNodes[0]);
39 console.log('\nUse this node ID to link to agent_id 115');
40 }
41
42 } catch (error) {
43 console.error('āŒ Error:', error.message);
44 }
45}
46
47main();