snow-flow 8.39.1 → 8.39.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/base-mcp-server.d.ts +3 -0
- package/dist/mcp/base-mcp-server.d.ts.map +1 -1
- package/dist/mcp/base-mcp-server.js +48 -21
- package/dist/mcp/base-mcp-server.js.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/index.d.ts +6 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/index.d.ts.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/index.js +19 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/index.js.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_email_logs.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_email_logs.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_email_logs.js +185 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_email_logs.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_flow_execution_logs.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_flow_execution_logs.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_flow_execution_logs.js +280 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_flow_execution_logs.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_inbound_http_logs.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_inbound_http_logs.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_inbound_http_logs.js +233 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_inbound_http_logs.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_outbound_http_logs.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_outbound_http_logs.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_outbound_http_logs.js +218 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_outbound_http_logs.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_scheduled_job_logs.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_scheduled_job_logs.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_scheduled_job_logs.js +276 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_scheduled_job_logs.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_slow_queries.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_slow_queries.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_slow_queries.js +340 -0
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_get_slow_queries.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/index.d.ts +10 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/index.d.ts.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/integration/index.js +34 -1
- package/dist/mcp/servicenow-mcp-unified/tools/integration/index.js.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_configure_mid_server.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_configure_mid_server.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_configure_mid_server.js +397 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_configure_mid_server.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_connection_alias.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_connection_alias.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_connection_alias.js +234 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_connection_alias.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_credential_alias.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_credential_alias.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_credential_alias.js +280 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_credential_alias.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_flow_action.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_flow_action.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_flow_action.js +358 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_flow_action.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_oauth_profile.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_oauth_profile.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_oauth_profile.js +237 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_create_oauth_profile.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_install_spoke.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_install_spoke.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_install_spoke.js +326 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_install_spoke.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_mid_capabilities.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_mid_capabilities.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_mid_capabilities.js +442 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_mid_capabilities.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_oauth_tokens.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_oauth_tokens.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_oauth_tokens.js +348 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_oauth_tokens.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_spoke_connection.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_spoke_connection.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_spoke_connection.js +427 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_manage_spoke_connection.js.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_test_mid_connectivity.d.ts +12 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_test_mid_connectivity.d.ts.map +1 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_test_mid_connectivity.js +432 -0
- package/dist/mcp/servicenow-mcp-unified/tools/integration/snow_test_mid_connectivity.js.map +1 -0
- package/dist/monitoring/performance-tracker.d.ts +1 -1
- package/dist/monitoring/performance-tracker.d.ts.map +1 -1
- package/dist/monitoring/performance-tracker.js +44 -9
- package/dist/monitoring/performance-tracker.js.map +1 -1
- package/dist/snow-flow-system.d.ts +12 -2
- package/dist/snow-flow-system.d.ts.map +1 -1
- package/dist/snow-flow-system.js +55 -12
- package/dist/snow-flow-system.js.map +1 -1
- package/dist/templates/agents-md-template.d.ts +2 -2
- package/dist/templates/agents-md-template.d.ts.map +1 -1
- package/dist/templates/agents-md-template.js +57 -2
- package/dist/templates/agents-md-template.js.map +1 -1
- package/dist/templates/claude-md-template.d.ts +2 -2
- package/dist/templates/claude-md-template.d.ts.map +1 -1
- package/dist/templates/claude-md-template.js +17 -1
- package/dist/templates/claude-md-template.js.map +1 -1
- package/dist/utils/mcp-on-demand-manager.d.ts.map +1 -1
- package/dist/utils/mcp-on-demand-manager.js +18 -5
- package/dist/utils/mcp-on-demand-manager.js.map +1 -1
- package/dist/utils/mcp-persistent-guard.d.ts +4 -0
- package/dist/utils/mcp-persistent-guard.d.ts.map +1 -1
- package/dist/utils/mcp-persistent-guard.js +26 -2
- package/dist/utils/mcp-persistent-guard.js.map +1 -1
- package/dist/utils/mcp-process-manager.d.ts.map +1 -1
- package/dist/utils/mcp-process-manager.js +5 -0
- package/dist/utils/mcp-process-manager.js.map +1 -1
- package/dist/utils/memory-safe-collections.d.ts +119 -0
- package/dist/utils/memory-safe-collections.d.ts.map +1 -0
- package/dist/utils/memory-safe-collections.js +212 -0
- package/dist/utils/memory-safe-collections.js.map +1 -0
- package/dist/utils/timer-registry.d.ts +138 -0
- package/dist/utils/timer-registry.d.ts.map +1 -0
- package/dist/utils/timer-registry.js +289 -0
- package/dist/utils/timer-registry.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* snow_test_mid_connectivity - Test MID Server connectivity
|
|
4
|
+
*
|
|
5
|
+
* Test connectivity from MID Servers to external endpoints,
|
|
6
|
+
* validate network paths, and diagnose connection issues.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.author = exports.version = exports.toolDefinition = void 0;
|
|
10
|
+
exports.execute = execute;
|
|
11
|
+
const auth_js_1 = require("../../shared/auth.js");
|
|
12
|
+
const error_handler_js_1 = require("../../shared/error-handler.js");
|
|
13
|
+
exports.toolDefinition = {
|
|
14
|
+
name: 'snow_test_mid_connectivity',
|
|
15
|
+
description: 'Test MID Server connectivity to external endpoints and diagnose network issues',
|
|
16
|
+
category: 'integration',
|
|
17
|
+
subcategory: 'mid-server',
|
|
18
|
+
use_cases: ['mid-server', 'connectivity', 'troubleshooting', 'network'],
|
|
19
|
+
complexity: 'intermediate',
|
|
20
|
+
frequency: 'medium',
|
|
21
|
+
permission: 'write',
|
|
22
|
+
allowedRoles: ['developer', 'admin'],
|
|
23
|
+
inputSchema: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
action: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
enum: ['test_endpoint', 'test_port', 'ping', 'dns_lookup', 'traceroute', 'full_diagnostic'],
|
|
29
|
+
description: 'Type of connectivity test to perform',
|
|
30
|
+
default: 'test_endpoint'
|
|
31
|
+
},
|
|
32
|
+
mid_server_name: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: 'Name of the MID Server to test from'
|
|
35
|
+
},
|
|
36
|
+
mid_server_id: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'sys_id of the MID Server to test from'
|
|
39
|
+
},
|
|
40
|
+
target_host: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
description: 'Target hostname or IP address'
|
|
43
|
+
},
|
|
44
|
+
target_port: {
|
|
45
|
+
type: 'number',
|
|
46
|
+
description: 'Target port number (for port test)',
|
|
47
|
+
default: 443
|
|
48
|
+
},
|
|
49
|
+
target_url: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Full URL to test (for endpoint test)'
|
|
52
|
+
},
|
|
53
|
+
timeout_seconds: {
|
|
54
|
+
type: 'number',
|
|
55
|
+
description: 'Timeout for the test in seconds',
|
|
56
|
+
default: 30
|
|
57
|
+
},
|
|
58
|
+
protocol: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
enum: ['tcp', 'udp', 'http', 'https'],
|
|
61
|
+
description: 'Protocol to use for port test',
|
|
62
|
+
default: 'tcp'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
required: ['action']
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
async function execute(args, context) {
|
|
69
|
+
var action = args.action || 'test_endpoint';
|
|
70
|
+
var mid_server_name = args.mid_server_name || '';
|
|
71
|
+
var mid_server_id = args.mid_server_id || '';
|
|
72
|
+
var target_host = args.target_host || '';
|
|
73
|
+
var target_port = args.target_port || 443;
|
|
74
|
+
var target_url = args.target_url || '';
|
|
75
|
+
var timeout_seconds = args.timeout_seconds || 30;
|
|
76
|
+
var protocol = args.protocol || 'tcp';
|
|
77
|
+
try {
|
|
78
|
+
var client = await (0, auth_js_1.getAuthenticatedClient)(context);
|
|
79
|
+
// Resolve MID Server ID if name provided
|
|
80
|
+
var midId = mid_server_id;
|
|
81
|
+
if (!midId && mid_server_name) {
|
|
82
|
+
var lookupResponse = await client.get('/api/now/table/ecc_agent', {
|
|
83
|
+
params: {
|
|
84
|
+
sysparm_query: 'name=' + mid_server_name + '^status=Up',
|
|
85
|
+
sysparm_limit: 1,
|
|
86
|
+
sysparm_fields: 'sys_id,name,ip_address'
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
if (lookupResponse.data.result && lookupResponse.data.result.length > 0) {
|
|
90
|
+
midId = lookupResponse.data.result[0].sys_id;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return (0, error_handler_js_1.createErrorResult)('MID Server not found or not running: ' + mid_server_name);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// If no MID Server specified, list available ones
|
|
97
|
+
if (!midId) {
|
|
98
|
+
var availableResponse = await client.get('/api/now/table/ecc_agent', {
|
|
99
|
+
params: {
|
|
100
|
+
sysparm_query: 'status=Up^validated=true',
|
|
101
|
+
sysparm_limit: 10,
|
|
102
|
+
sysparm_fields: 'sys_id,name,ip_address,host_name'
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
var available = availableResponse.data.result || [];
|
|
106
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
107
|
+
action: 'list_available',
|
|
108
|
+
message: 'No MID Server specified. Available MID Servers:',
|
|
109
|
+
mid_servers: available.map(function (m) {
|
|
110
|
+
return {
|
|
111
|
+
sys_id: m.sys_id,
|
|
112
|
+
name: m.name,
|
|
113
|
+
ip_address: m.ip_address,
|
|
114
|
+
host_name: m.host_name
|
|
115
|
+
};
|
|
116
|
+
}),
|
|
117
|
+
usage: 'Provide mid_server_name or mid_server_id to run connectivity tests'
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Get MID Server details
|
|
121
|
+
var midDetails = await client.get('/api/now/table/ecc_agent/' + midId, {
|
|
122
|
+
params: {
|
|
123
|
+
sysparm_fields: 'name,ip_address,host_name,status'
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
var midServer = midDetails.data.result;
|
|
127
|
+
if (action === 'test_endpoint') {
|
|
128
|
+
if (!target_url) {
|
|
129
|
+
return (0, error_handler_js_1.createErrorResult)('target_url is required for test_endpoint action');
|
|
130
|
+
}
|
|
131
|
+
// Queue an HTTP probe via ECC queue
|
|
132
|
+
var probeScript = `
|
|
133
|
+
var probe = new GlideRecord('ecc_queue');
|
|
134
|
+
probe.initialize();
|
|
135
|
+
probe.agent = ${JSON.stringify(midId)};
|
|
136
|
+
probe.topic = 'Probe';
|
|
137
|
+
probe.name = 'HTTPProbe';
|
|
138
|
+
probe.source = 'snow-flow-connectivity-test';
|
|
139
|
+
probe.queue = 'output';
|
|
140
|
+
|
|
141
|
+
var payload = {
|
|
142
|
+
url: ${JSON.stringify(target_url)},
|
|
143
|
+
timeout: ${timeout_seconds * 1000}
|
|
144
|
+
};
|
|
145
|
+
probe.payload = JSON.stringify(payload);
|
|
146
|
+
|
|
147
|
+
var sysId = probe.insert();
|
|
148
|
+
|
|
149
|
+
// Wait briefly for response
|
|
150
|
+
var response = new GlideRecord('ecc_queue');
|
|
151
|
+
response.addQuery('source', probe.sys_id);
|
|
152
|
+
response.addQuery('queue', 'input');
|
|
153
|
+
response.setLimit(1);
|
|
154
|
+
|
|
155
|
+
var maxWait = ${timeout_seconds};
|
|
156
|
+
var waited = 0;
|
|
157
|
+
var result = null;
|
|
158
|
+
|
|
159
|
+
while (waited < maxWait && !result) {
|
|
160
|
+
gs.sleep(1000);
|
|
161
|
+
waited++;
|
|
162
|
+
response.query();
|
|
163
|
+
if (response.next()) {
|
|
164
|
+
result = {
|
|
165
|
+
success: true,
|
|
166
|
+
response_received: true,
|
|
167
|
+
payload: response.payload.toString()
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!result) {
|
|
173
|
+
result = {
|
|
174
|
+
success: true,
|
|
175
|
+
response_received: false,
|
|
176
|
+
message: 'Probe queued, check ECC queue for results',
|
|
177
|
+
ecc_queue_id: sysId
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
gs.print(JSON.stringify(result));
|
|
182
|
+
`;
|
|
183
|
+
var probeResponse = await client.post('/api/now/table/sys_script_execution', {
|
|
184
|
+
script: probeScript,
|
|
185
|
+
description: 'Test endpoint from MID: ' + target_url
|
|
186
|
+
});
|
|
187
|
+
var probeOutput = probeResponse.data.result?.output || '';
|
|
188
|
+
var probeMatch = probeOutput.match(/\{[\s\S]*\}/);
|
|
189
|
+
var probeResult = probeMatch ? JSON.parse(probeMatch[0]) : { success: false, error: 'Unknown error' };
|
|
190
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
191
|
+
action: 'test_endpoint',
|
|
192
|
+
mid_server: {
|
|
193
|
+
name: midServer.name,
|
|
194
|
+
ip_address: midServer.ip_address
|
|
195
|
+
},
|
|
196
|
+
target: target_url,
|
|
197
|
+
result: probeResult
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else if (action === 'test_port') {
|
|
201
|
+
if (!target_host) {
|
|
202
|
+
return (0, error_handler_js_1.createErrorResult)('target_host is required for test_port action');
|
|
203
|
+
}
|
|
204
|
+
// Queue a port test via ECC queue
|
|
205
|
+
var portTestScript = `
|
|
206
|
+
var probe = new GlideRecord('ecc_queue');
|
|
207
|
+
probe.initialize();
|
|
208
|
+
probe.agent = ${JSON.stringify(midId)};
|
|
209
|
+
probe.topic = 'Probe';
|
|
210
|
+
probe.name = 'TCPProbe';
|
|
211
|
+
probe.source = 'snow-flow-port-test';
|
|
212
|
+
probe.queue = 'output';
|
|
213
|
+
|
|
214
|
+
var payload = {
|
|
215
|
+
host: ${JSON.stringify(target_host)},
|
|
216
|
+
port: ${target_port},
|
|
217
|
+
protocol: ${JSON.stringify(protocol)},
|
|
218
|
+
timeout: ${timeout_seconds * 1000}
|
|
219
|
+
};
|
|
220
|
+
probe.payload = JSON.stringify(payload);
|
|
221
|
+
|
|
222
|
+
var sysId = probe.insert();
|
|
223
|
+
|
|
224
|
+
gs.print(JSON.stringify({
|
|
225
|
+
success: true,
|
|
226
|
+
message: 'Port test queued',
|
|
227
|
+
ecc_queue_id: sysId,
|
|
228
|
+
target: ${JSON.stringify(target_host)} + ':' + ${target_port}
|
|
229
|
+
}));
|
|
230
|
+
`;
|
|
231
|
+
var portTestResponse = await client.post('/api/now/table/sys_script_execution', {
|
|
232
|
+
script: portTestScript,
|
|
233
|
+
description: 'Test port from MID: ' + target_host + ':' + target_port
|
|
234
|
+
});
|
|
235
|
+
var portOutput = portTestResponse.data.result?.output || '';
|
|
236
|
+
var portMatch = portOutput.match(/\{[^}]+\}/);
|
|
237
|
+
var portResult = portMatch ? JSON.parse(portMatch[0]) : { success: false, error: 'Unknown error' };
|
|
238
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
239
|
+
action: 'test_port',
|
|
240
|
+
mid_server: {
|
|
241
|
+
name: midServer.name,
|
|
242
|
+
ip_address: midServer.ip_address
|
|
243
|
+
},
|
|
244
|
+
target: {
|
|
245
|
+
host: target_host,
|
|
246
|
+
port: target_port,
|
|
247
|
+
protocol: protocol
|
|
248
|
+
},
|
|
249
|
+
result: portResult,
|
|
250
|
+
note: 'Check ECC queue for actual test results'
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
else if (action === 'ping') {
|
|
254
|
+
if (!target_host) {
|
|
255
|
+
return (0, error_handler_js_1.createErrorResult)('target_host is required for ping action');
|
|
256
|
+
}
|
|
257
|
+
var pingScript = `
|
|
258
|
+
var probe = new GlideRecord('ecc_queue');
|
|
259
|
+
probe.initialize();
|
|
260
|
+
probe.agent = ${JSON.stringify(midId)};
|
|
261
|
+
probe.topic = 'Probe';
|
|
262
|
+
probe.name = 'ICMPProbe';
|
|
263
|
+
probe.source = 'snow-flow-ping-test';
|
|
264
|
+
probe.queue = 'output';
|
|
265
|
+
|
|
266
|
+
var payload = {
|
|
267
|
+
host: ${JSON.stringify(target_host)},
|
|
268
|
+
count: 4,
|
|
269
|
+
timeout: ${timeout_seconds * 1000}
|
|
270
|
+
};
|
|
271
|
+
probe.payload = JSON.stringify(payload);
|
|
272
|
+
|
|
273
|
+
var sysId = probe.insert();
|
|
274
|
+
|
|
275
|
+
gs.print(JSON.stringify({
|
|
276
|
+
success: true,
|
|
277
|
+
message: 'Ping test queued',
|
|
278
|
+
ecc_queue_id: sysId,
|
|
279
|
+
target: ${JSON.stringify(target_host)}
|
|
280
|
+
}));
|
|
281
|
+
`;
|
|
282
|
+
var pingResponse = await client.post('/api/now/table/sys_script_execution', {
|
|
283
|
+
script: pingScript,
|
|
284
|
+
description: 'Ping from MID: ' + target_host
|
|
285
|
+
});
|
|
286
|
+
var pingOutput = pingResponse.data.result?.output || '';
|
|
287
|
+
var pingMatch = pingOutput.match(/\{[^}]+\}/);
|
|
288
|
+
var pingResult = pingMatch ? JSON.parse(pingMatch[0]) : { success: false, error: 'Unknown error' };
|
|
289
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
290
|
+
action: 'ping',
|
|
291
|
+
mid_server: {
|
|
292
|
+
name: midServer.name,
|
|
293
|
+
ip_address: midServer.ip_address
|
|
294
|
+
},
|
|
295
|
+
target: target_host,
|
|
296
|
+
result: pingResult,
|
|
297
|
+
note: 'Check ECC queue for ping results'
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
else if (action === 'dns_lookup') {
|
|
301
|
+
if (!target_host) {
|
|
302
|
+
return (0, error_handler_js_1.createErrorResult)('target_host is required for dns_lookup action');
|
|
303
|
+
}
|
|
304
|
+
var dnsScript = `
|
|
305
|
+
var probe = new GlideRecord('ecc_queue');
|
|
306
|
+
probe.initialize();
|
|
307
|
+
probe.agent = ${JSON.stringify(midId)};
|
|
308
|
+
probe.topic = 'Probe';
|
|
309
|
+
probe.name = 'DNSProbe';
|
|
310
|
+
probe.source = 'snow-flow-dns-test';
|
|
311
|
+
probe.queue = 'output';
|
|
312
|
+
|
|
313
|
+
var payload = {
|
|
314
|
+
hostname: ${JSON.stringify(target_host)},
|
|
315
|
+
timeout: ${timeout_seconds * 1000}
|
|
316
|
+
};
|
|
317
|
+
probe.payload = JSON.stringify(payload);
|
|
318
|
+
|
|
319
|
+
var sysId = probe.insert();
|
|
320
|
+
|
|
321
|
+
gs.print(JSON.stringify({
|
|
322
|
+
success: true,
|
|
323
|
+
message: 'DNS lookup queued',
|
|
324
|
+
ecc_queue_id: sysId,
|
|
325
|
+
hostname: ${JSON.stringify(target_host)}
|
|
326
|
+
}));
|
|
327
|
+
`;
|
|
328
|
+
var dnsResponse = await client.post('/api/now/table/sys_script_execution', {
|
|
329
|
+
script: dnsScript,
|
|
330
|
+
description: 'DNS lookup from MID: ' + target_host
|
|
331
|
+
});
|
|
332
|
+
var dnsOutput = dnsResponse.data.result?.output || '';
|
|
333
|
+
var dnsMatch = dnsOutput.match(/\{[^}]+\}/);
|
|
334
|
+
var dnsResult = dnsMatch ? JSON.parse(dnsMatch[0]) : { success: false, error: 'Unknown error' };
|
|
335
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
336
|
+
action: 'dns_lookup',
|
|
337
|
+
mid_server: {
|
|
338
|
+
name: midServer.name,
|
|
339
|
+
ip_address: midServer.ip_address
|
|
340
|
+
},
|
|
341
|
+
hostname: target_host,
|
|
342
|
+
result: dnsResult,
|
|
343
|
+
note: 'Check ECC queue for DNS resolution results'
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else if (action === 'full_diagnostic') {
|
|
347
|
+
if (!target_host && !target_url) {
|
|
348
|
+
return (0, error_handler_js_1.createErrorResult)('target_host or target_url is required for full_diagnostic action');
|
|
349
|
+
}
|
|
350
|
+
var diagTarget = target_host || new URL(target_url).hostname;
|
|
351
|
+
var diagPort = target_port || (target_url && target_url.startsWith('https') ? 443 : 80);
|
|
352
|
+
// Run multiple tests
|
|
353
|
+
var diagnosticScript = `
|
|
354
|
+
var results = {
|
|
355
|
+
mid_server: ${JSON.stringify(midServer.name)},
|
|
356
|
+
target: ${JSON.stringify(diagTarget)},
|
|
357
|
+
tests: {}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// Create probes for each test type
|
|
361
|
+
var probes = ['ICMPProbe', 'TCPProbe', 'DNSProbe'];
|
|
362
|
+
var eccIds = [];
|
|
363
|
+
|
|
364
|
+
for (var i = 0; i < probes.length; i++) {
|
|
365
|
+
var probe = new GlideRecord('ecc_queue');
|
|
366
|
+
probe.initialize();
|
|
367
|
+
probe.agent = ${JSON.stringify(midId)};
|
|
368
|
+
probe.topic = 'Probe';
|
|
369
|
+
probe.name = probes[i];
|
|
370
|
+
probe.source = 'snow-flow-diagnostic';
|
|
371
|
+
probe.queue = 'output';
|
|
372
|
+
|
|
373
|
+
var payload = {};
|
|
374
|
+
if (probes[i] === 'ICMPProbe') {
|
|
375
|
+
payload = { host: ${JSON.stringify(diagTarget)}, count: 2 };
|
|
376
|
+
} else if (probes[i] === 'TCPProbe') {
|
|
377
|
+
payload = { host: ${JSON.stringify(diagTarget)}, port: ${diagPort} };
|
|
378
|
+
} else if (probes[i] === 'DNSProbe') {
|
|
379
|
+
payload = { hostname: ${JSON.stringify(diagTarget)} };
|
|
380
|
+
}
|
|
381
|
+
probe.payload = JSON.stringify(payload);
|
|
382
|
+
|
|
383
|
+
var sysId = probe.insert();
|
|
384
|
+
eccIds.push({ probe: probes[i], ecc_id: sysId });
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
results.queued_probes = eccIds;
|
|
388
|
+
results.message = 'Diagnostic probes queued. Check ECC queue for results.';
|
|
389
|
+
results.success = true;
|
|
390
|
+
|
|
391
|
+
gs.print(JSON.stringify(results));
|
|
392
|
+
`;
|
|
393
|
+
var diagResponse = await client.post('/api/now/table/sys_script_execution', {
|
|
394
|
+
script: diagnosticScript,
|
|
395
|
+
description: 'Full diagnostic from MID to: ' + diagTarget
|
|
396
|
+
});
|
|
397
|
+
var diagOutput = diagResponse.data.result?.output || '';
|
|
398
|
+
var diagMatch = diagOutput.match(/\{[\s\S]*\}/);
|
|
399
|
+
var diagResult = diagMatch ? JSON.parse(diagMatch[0]) : { success: false, error: 'Unknown error' };
|
|
400
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
401
|
+
action: 'full_diagnostic',
|
|
402
|
+
mid_server: {
|
|
403
|
+
name: midServer.name,
|
|
404
|
+
ip_address: midServer.ip_address
|
|
405
|
+
},
|
|
406
|
+
target: {
|
|
407
|
+
host: diagTarget,
|
|
408
|
+
port: diagPort
|
|
409
|
+
},
|
|
410
|
+
result: diagResult,
|
|
411
|
+
instructions: [
|
|
412
|
+
'DNS probe will resolve hostname to IP',
|
|
413
|
+
'ICMP probe will test basic connectivity (ping)',
|
|
414
|
+
'TCP probe will test port connectivity',
|
|
415
|
+
'Check ECC queue for detailed results',
|
|
416
|
+
'Use snow_get_logs to view any errors'
|
|
417
|
+
]
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return (0, error_handler_js_1.createErrorResult)('Unknown action: ' + action);
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
if (error.response?.status === 403) {
|
|
424
|
+
return (0, error_handler_js_1.createErrorResult)('Permission denied (403): Your ServiceNow user lacks permissions to test MID connectivity. ' +
|
|
425
|
+
'Required roles: "mid_server" or "admin".');
|
|
426
|
+
}
|
|
427
|
+
return (0, error_handler_js_1.createErrorResult)(error.message);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
exports.version = '1.0.0';
|
|
431
|
+
exports.author = 'Snow-Flow Team';
|
|
432
|
+
//# sourceMappingURL=snow_test_mid_connectivity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snow_test_mid_connectivity.js","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/integration/snow_test_mid_connectivity.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA+DH,0BAyYC;AArcD,kDAA8D;AAC9D,oEAAuF;AAE1E,QAAA,cAAc,GAAsB;IAC/C,IAAI,EAAE,4BAA4B;IAClC,WAAW,EAAE,gFAAgF;IAC7F,QAAQ,EAAE,aAAa;IACvB,WAAW,EAAE,YAAY;IACzB,SAAS,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,SAAS,CAAC;IACvE,UAAU,EAAE,cAAc;IAC1B,SAAS,EAAE,QAAQ;IAEnB,UAAU,EAAE,OAAO;IACnB,YAAY,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC;IACpC,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,iBAAiB,CAAC;gBAC3F,WAAW,EAAE,sCAAsC;gBACnD,OAAO,EAAE,eAAe;aACzB;YACD,eAAe,EAAE;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,qCAAqC;aACnD;YACD,aAAa,EAAE;gBACb,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,uCAAuC;aACrD;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,+BAA+B;aAC7C;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,W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,EAAE;oBACV,IAAI,EAAE,SAAS,CAAC,IAAI;oBACpB,UAAU,EAAE,SAAS,CAAC,UAAU;iBACjC;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,UAAU;oBAChB,IAAI,EAAE,QAAQ;iBACf;gBACD,MAAM,EAAE,UAAU;gBAClB,YAAY,EAAE;oBACZ,uCAAuC;oBACvC,gDAAgD;oBAChD,uCAAuC;oBACvC,sCAAsC;oBACtC,sCAAsC;iBACvC;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAA,oCAAiB,EAAC,kBAAkB,GAAG,MAAM,CAAC,CAAC;IAExD,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;YACnC,OAAO,IAAA,oCAAiB,EACtB,4FAA4F;gBAC5F,0CAA0C,CAC3C,CAAC;QACJ,CAAC;QACD,OAAO,IAAA,oCAAiB,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAEY,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,MAAM,GAAG,gBAAgB,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Real-time metrics collection and analysis
|
|
4
4
|
*/
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
|
-
import { MemorySystem } from '../memory/memory-system';
|
|
6
|
+
import { MemorySystem } from '../memory/memory-system.js';
|
|
7
7
|
export interface PerformanceMetric {
|
|
8
8
|
id: string;
|
|
9
9
|
operation: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performance-tracker.d.ts","sourceRoot":"","sources":["../../src/monitoring/performance-tracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"performance-tracker.d.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,EAAE,CAAC;IAwD9E;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB/B;;OAEG;YACW,uBAAuB;IAgCrC,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,uBAAuB;IA6B/B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,sBAAsB;YAWhB,YAAY;YA0BZ,gBAAgB;YAwBhB,iBAAiB;IAY/B,OAAO,CAAC,0BAA0B;IA6BlC,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,wBAAwB;YA6BlB,qBAAqB;IASnC,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,uBAAuB;CA0ChC"}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.PerformanceTracker = void 0;
|
|
8
8
|
const events_1 = require("events");
|
|
9
|
-
const
|
|
9
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
10
|
+
const timer_registry_js_1 = require("../utils/timer-registry.js");
|
|
10
11
|
class PerformanceTracker extends events_1.EventEmitter {
|
|
11
12
|
constructor(options) {
|
|
12
13
|
super();
|
|
@@ -15,7 +16,7 @@ class PerformanceTracker extends events_1.EventEmitter {
|
|
|
15
16
|
this.initialized = false;
|
|
16
17
|
this.memory = options.memory;
|
|
17
18
|
this.config = options.config;
|
|
18
|
-
this.logger = new
|
|
19
|
+
this.logger = new logger_js_1.Logger('PerformanceTracker');
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Initialize the performance tracker
|
|
@@ -53,6 +54,17 @@ class PerformanceTracker extends events_1.EventEmitter {
|
|
|
53
54
|
resourceUsage: this.captureResourceUsage()
|
|
54
55
|
};
|
|
55
56
|
this.activeOperations.set(id, metric);
|
|
57
|
+
// MEMORY FIX: Set cleanup timeout for orphaned operations
|
|
58
|
+
// This only cleans up operations that were NEVER completed (crash/timeout scenarios).
|
|
59
|
+
// Normal operations complete via endOperation() which clears this timeout.
|
|
60
|
+
// Default: 30 minutes - very conservative to allow for long-running operations
|
|
61
|
+
const orphanTimeout = parseInt(process.env.SNOW_OPERATION_TIMEOUT || String(30 * 60 * 1000)); // 30 minutes default
|
|
62
|
+
timer_registry_js_1.timerRegistry.registerTimeout(`perf-operation-cleanup-${id}`, () => {
|
|
63
|
+
if (this.activeOperations.has(id)) {
|
|
64
|
+
this.logger.warn(`Cleaning up orphaned operation: ${id} (${operation}) - exceeded ${orphanTimeout}ms`);
|
|
65
|
+
this.activeOperations.delete(id);
|
|
66
|
+
}
|
|
67
|
+
}, orphanTimeout);
|
|
56
68
|
// Emit start event
|
|
57
69
|
this.emit('operation:start', {
|
|
58
70
|
id,
|
|
@@ -68,6 +80,8 @@ class PerformanceTracker extends events_1.EventEmitter {
|
|
|
68
80
|
const metric = this.activeOperations.get(operationId);
|
|
69
81
|
if (!metric || operationId === 'not_sampled')
|
|
70
82
|
return;
|
|
83
|
+
// MEMORY FIX: Clear the orphan cleanup timeout since we're ending properly
|
|
84
|
+
timer_registry_js_1.timerRegistry.clearTimeout(`perf-operation-cleanup-${operationId}`);
|
|
71
85
|
metric.endTime = Date.now();
|
|
72
86
|
metric.duration = metric.endTime - metric.startTime;
|
|
73
87
|
metric.success = result.success;
|
|
@@ -80,10 +94,21 @@ class PerformanceTracker extends events_1.EventEmitter {
|
|
|
80
94
|
metric.resourceUsage = this.calculateResourceDelta(metric.resourceUsage, finalResourceUsage);
|
|
81
95
|
// Remove from active and add to buffer
|
|
82
96
|
this.activeOperations.delete(operationId);
|
|
97
|
+
// MEMORY FIX: Hard limit on buffer - drop oldest if exceeds limit
|
|
98
|
+
// Default: 2000 entries - very conservative, allows for lots of operations
|
|
99
|
+
// Only drops the oldest 20% when limit is hit
|
|
100
|
+
const maxBufferSize = parseInt(process.env.SNOW_METRICS_BUFFER_SIZE || '2000');
|
|
101
|
+
if (this.metricsBuffer.length >= maxBufferSize) {
|
|
102
|
+
const keepCount = Math.floor(maxBufferSize * 0.8); // Keep 80%
|
|
103
|
+
this.metricsBuffer = this.metricsBuffer.slice(-keepCount);
|
|
104
|
+
this.logger.warn(`Metrics buffer exceeded ${maxBufferSize}, keeping newest ${keepCount} entries`);
|
|
105
|
+
}
|
|
83
106
|
this.metricsBuffer.push(metric);
|
|
84
107
|
// Store immediately if buffer is large
|
|
85
108
|
if (this.metricsBuffer.length >= 100) {
|
|
86
|
-
await this.flushMetrics()
|
|
109
|
+
await this.flushMetrics().catch(err => {
|
|
110
|
+
this.logger.error('Failed to flush metrics:', err);
|
|
111
|
+
});
|
|
87
112
|
}
|
|
88
113
|
// Emit end event
|
|
89
114
|
this.emit('operation:end', {
|
|
@@ -299,13 +324,19 @@ class PerformanceTracker extends events_1.EventEmitter {
|
|
|
299
324
|
*/
|
|
300
325
|
async shutdown() {
|
|
301
326
|
this.logger.info('Shutting down Performance Tracker...');
|
|
302
|
-
//
|
|
327
|
+
// MEMORY FIX: Clear intervals via timerRegistry
|
|
328
|
+
timer_registry_js_1.timerRegistry.clearInterval('performance-tracker-aggregation');
|
|
329
|
+
timer_registry_js_1.timerRegistry.clearInterval('performance-tracker-resource-monitor');
|
|
330
|
+
// Also clear legacy timer if it exists
|
|
303
331
|
if (this.aggregationTimer) {
|
|
304
332
|
clearInterval(this.aggregationTimer);
|
|
305
333
|
}
|
|
306
334
|
// Flush remaining metrics
|
|
307
335
|
await this.flushMetrics();
|
|
336
|
+
// MEMORY FIX: Clear active operations map
|
|
337
|
+
this.activeOperations.clear();
|
|
308
338
|
this.initialized = false;
|
|
339
|
+
this.logger.info('Performance Tracker shutdown complete');
|
|
309
340
|
}
|
|
310
341
|
/**
|
|
311
342
|
* Private helper methods
|
|
@@ -342,14 +373,16 @@ class PerformanceTracker extends events_1.EventEmitter {
|
|
|
342
373
|
`);
|
|
343
374
|
}
|
|
344
375
|
startAggregation() {
|
|
345
|
-
|
|
376
|
+
// MEMORY FIX: Use timerRegistry for proper cleanup
|
|
377
|
+
timer_registry_js_1.timerRegistry.registerInterval('performance-tracker-aggregation', async () => {
|
|
346
378
|
await this.flushMetrics();
|
|
347
379
|
await this.aggregateMetrics();
|
|
348
|
-
}, this.config.aggregationInterval
|
|
380
|
+
}, this.config.aggregationInterval, true // unref
|
|
381
|
+
);
|
|
349
382
|
}
|
|
350
383
|
startResourceMonitoring() {
|
|
351
|
-
//
|
|
352
|
-
|
|
384
|
+
// MEMORY FIX: Use timerRegistry for proper cleanup
|
|
385
|
+
timer_registry_js_1.timerRegistry.registerInterval('performance-tracker-resource-monitor', () => {
|
|
353
386
|
const usage = this.captureResourceUsage();
|
|
354
387
|
// Check thresholds
|
|
355
388
|
if (usage.memoryUsage > 0.8) {
|
|
@@ -366,7 +399,9 @@ class PerformanceTracker extends events_1.EventEmitter {
|
|
|
366
399
|
threshold: 0.8
|
|
367
400
|
});
|
|
368
401
|
}
|
|
369
|
-
}, 10000
|
|
402
|
+
}, 10000, // Every 10 seconds
|
|
403
|
+
true // unref
|
|
404
|
+
);
|
|
370
405
|
}
|
|
371
406
|
captureResourceUsage() {
|
|
372
407
|
const usage = process.cpuUsage();
|