nerdgram1337 1.6.1 → 1.8.5
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/README.md +2 -1
- package/dist/{chunk-AWVTRON2.js → chunk-2WFLIMQG.js} +11 -3
- package/dist/chunk-3WBI2WV6.js +18 -0
- package/dist/{chunk-LYMG57VV.js → chunk-46CLFN4M.js} +24 -5
- package/dist/{chunk-BCO66AYP.js → chunk-7NPZMMPE.js} +7 -4
- package/dist/chunk-7O4HSURR.js +3396 -0
- package/dist/{chunk-KA5X3YY6.js → chunk-7XBDBMFZ.js} +9 -60
- package/dist/{chunk-JL7RYIQE.js → chunk-ARL7TA3D.js} +902 -440
- package/dist/{chunk-5C6VO4LC.js → chunk-BW6ANOTX.js} +38 -0
- package/dist/chunk-DHVVDJDI.js +470 -0
- package/dist/chunk-DWP7W42J.js +12 -0
- package/dist/{chunk-LXSDAIF4.js → chunk-GD2NZSZO.js} +42 -18
- package/dist/chunk-GI4QATKE.js +87 -0
- package/dist/chunk-GK3V52XM.js +70 -0
- package/dist/chunk-KIK3WXJL.js +959 -0
- package/dist/{chunk-7YIBJCTH.js → chunk-M4HT24R6.js} +22 -9
- package/dist/chunk-M63FV47T.js +14 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-TDN24VZZ.js +196 -0
- package/dist/chunk-TFNQIO7Z.js +21 -0
- package/dist/chunk-TVIG7AQK.js +78 -0
- package/dist/chunk-WYQ4QDCF.js +85 -0
- package/dist/chunk-XC6UP46Q.js +15 -0
- package/dist/cli.js +185 -6
- package/package.json +1 -1
|
@@ -0,0 +1,3396 @@
|
|
|
1
|
+
import {
|
|
2
|
+
importInputFromBody
|
|
3
|
+
} from "./chunk-TVIG7AQK.js";
|
|
4
|
+
import "./chunk-DHVVDJDI.js";
|
|
5
|
+
import "./chunk-7XBDBMFZ.js";
|
|
6
|
+
import "./chunk-TDN24VZZ.js";
|
|
7
|
+
import "./chunk-GK3V52XM.js";
|
|
8
|
+
import "./chunk-M4HT24R6.js";
|
|
9
|
+
import "./chunk-WCRNLGMN.js";
|
|
10
|
+
import "./chunk-WYQ4QDCF.js";
|
|
11
|
+
import {
|
|
12
|
+
canonicalIp,
|
|
13
|
+
validateNetwork
|
|
14
|
+
} from "./chunk-ARL7TA3D.js";
|
|
15
|
+
import "./chunk-M63FV47T.js";
|
|
16
|
+
import "./chunk-BW6ANOTX.js";
|
|
17
|
+
import "./chunk-6LCHDAAN.js";
|
|
18
|
+
import {
|
|
19
|
+
__export
|
|
20
|
+
} from "./chunk-MLKGABMK.js";
|
|
21
|
+
|
|
22
|
+
// server/src/translators/infra.ts
|
|
23
|
+
var TRANSLATOR_INFRA = ["bundled", "helpers", "index", "infra", "limits", "registry", "request", "run", "types"];
|
|
24
|
+
|
|
25
|
+
// server/src/translators/limits.ts
|
|
26
|
+
var CONVERT_MAX_INPUT_BYTES = 4 * 1024 * 1024;
|
|
27
|
+
function translatorFail(status, message, code2 = "invalid") {
|
|
28
|
+
return Object.assign(new Error(message), { status, code: code2 });
|
|
29
|
+
}
|
|
30
|
+
function assertConvertInputSize(bytes) {
|
|
31
|
+
if (!Number.isFinite(bytes) || bytes < 0) {
|
|
32
|
+
throw translatorFail(400, "The export size is not valid.");
|
|
33
|
+
}
|
|
34
|
+
if (bytes > CONVERT_MAX_INPUT_BYTES) {
|
|
35
|
+
throw translatorFail(413, "The export is larger than 4 MiB.", "too_large");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// server/src/translators/helpers.ts
|
|
40
|
+
function isRecord(value) {
|
|
41
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
function pushWarning(warnings, path2, message) {
|
|
44
|
+
if (warnings.some((item) => item.message === message)) return;
|
|
45
|
+
warnings.push({ path: path2, message });
|
|
46
|
+
}
|
|
47
|
+
function noteUnmapped(warnings, pointer, record, used, label) {
|
|
48
|
+
for (const key of Object.keys(record).sort()) {
|
|
49
|
+
if (used.has(key)) continue;
|
|
50
|
+
pushWarning(warnings, `${pointer}/${key}`, `Ignored unmapped ${label} field "${key}".`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function integerLike(value) {
|
|
54
|
+
if (typeof value === "number" && Number.isInteger(value)) return value;
|
|
55
|
+
if (typeof value === "string" && /^-?\d+$/.test(value.trim())) {
|
|
56
|
+
const parsed = Number(value.trim());
|
|
57
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function numberLike(value) {
|
|
62
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
63
|
+
if (typeof value === "string" && value.trim()) {
|
|
64
|
+
const parsed = Number(value.trim());
|
|
65
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
function idKey(value) {
|
|
70
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
71
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
function textOf(value) {
|
|
75
|
+
return typeof value === "string" ? value.trim() : "";
|
|
76
|
+
}
|
|
77
|
+
function nestedText(value, keys) {
|
|
78
|
+
if (typeof value === "string") return value.trim();
|
|
79
|
+
if (!isRecord(value)) return "";
|
|
80
|
+
for (const key of keys) {
|
|
81
|
+
const item = textOf(value[key]);
|
|
82
|
+
if (item) return item;
|
|
83
|
+
}
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
function collapsedRef(value) {
|
|
87
|
+
if (typeof value === "number" && Number.isFinite(value)) return true;
|
|
88
|
+
return typeof value === "string" && /^\d+$/.test(value.trim());
|
|
89
|
+
}
|
|
90
|
+
function sectionList(value, keys) {
|
|
91
|
+
if (value == null) return { present: false, items: [], next: "", bad: false };
|
|
92
|
+
if (Array.isArray(value)) return { present: true, items: value, next: "", bad: false };
|
|
93
|
+
if (!isRecord(value)) return { present: true, items: [], next: "", bad: true };
|
|
94
|
+
const next = textOf(value.next);
|
|
95
|
+
if (Array.isArray(value.results)) return { present: true, items: value.results, next, bad: false };
|
|
96
|
+
for (const key of keys) {
|
|
97
|
+
if (Array.isArray(value[key])) return { present: true, items: value[key], next, bad: false };
|
|
98
|
+
}
|
|
99
|
+
return { present: true, items: [], next, bad: true };
|
|
100
|
+
}
|
|
101
|
+
function splitCidr(value) {
|
|
102
|
+
const text = value.trim();
|
|
103
|
+
const slash = text.lastIndexOf("/");
|
|
104
|
+
if (slash <= 0) return null;
|
|
105
|
+
const rawAddress = text.slice(0, slash).trim();
|
|
106
|
+
const prefix = Number(text.slice(slash + 1));
|
|
107
|
+
if (!Number.isInteger(prefix)) return null;
|
|
108
|
+
const family = rawAddress.includes(":") ? "ipv6" : "ipv4";
|
|
109
|
+
const max = family === "ipv4" ? 32 : 128;
|
|
110
|
+
if (prefix < 0 || prefix > max) return null;
|
|
111
|
+
const address = canonicalIp(rawAddress, family);
|
|
112
|
+
if (!address) return null;
|
|
113
|
+
return { address, prefix, family };
|
|
114
|
+
}
|
|
115
|
+
function hostAddress(value) {
|
|
116
|
+
const text = textOf(value);
|
|
117
|
+
if (!text) return "";
|
|
118
|
+
const cidr = splitCidr(text);
|
|
119
|
+
if (cidr) return cidr.address;
|
|
120
|
+
return canonicalIp(text, text.includes(":") ? "ipv6" : "ipv4") ?? "";
|
|
121
|
+
}
|
|
122
|
+
function formatRate(value, unit) {
|
|
123
|
+
if (!Number.isFinite(value) || value <= 0) return "";
|
|
124
|
+
const bps = unit === "kbps" ? value * 1e3 : value;
|
|
125
|
+
if (!Number.isFinite(bps) || bps <= 0) return "";
|
|
126
|
+
const steps = [
|
|
127
|
+
{ div: 1e12, suffix: "T" },
|
|
128
|
+
{ div: 1e9, suffix: "G" },
|
|
129
|
+
{ div: 1e6, suffix: "M" },
|
|
130
|
+
{ div: 1e3, suffix: "K" }
|
|
131
|
+
];
|
|
132
|
+
for (const step of steps) {
|
|
133
|
+
if (bps >= step.div && bps % step.div === 0) return `${bps / step.div}${step.suffix}`;
|
|
134
|
+
}
|
|
135
|
+
if (bps % 1 === 0) return String(bps);
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
function statusUpDown(value) {
|
|
139
|
+
if (value == null || value === "") return "";
|
|
140
|
+
if (value === true || value === 1 || value === "1") return "up";
|
|
141
|
+
if (value === false || value === 0 || value === "0") return "down";
|
|
142
|
+
if (typeof value === "string") {
|
|
143
|
+
const text = value.trim().toLowerCase();
|
|
144
|
+
if (text === "up") return "up";
|
|
145
|
+
if (text === "down") return "down";
|
|
146
|
+
if (!text) return "";
|
|
147
|
+
}
|
|
148
|
+
return "other";
|
|
149
|
+
}
|
|
150
|
+
function blankDevice(name, extra = {}) {
|
|
151
|
+
return {
|
|
152
|
+
platform: "",
|
|
153
|
+
model: "",
|
|
154
|
+
role: "",
|
|
155
|
+
site: "",
|
|
156
|
+
managementIp: "",
|
|
157
|
+
diagram: "",
|
|
158
|
+
...extra,
|
|
159
|
+
name
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function blankInterface(device, name, extra = {}) {
|
|
163
|
+
return {
|
|
164
|
+
description: "",
|
|
165
|
+
speed: "",
|
|
166
|
+
adminStatus: "",
|
|
167
|
+
operStatus: "",
|
|
168
|
+
ipv4: [],
|
|
169
|
+
ipv6: [],
|
|
170
|
+
vrf: "",
|
|
171
|
+
switchportMode: "",
|
|
172
|
+
accessVlan: null,
|
|
173
|
+
trunkVlans: null,
|
|
174
|
+
nativeVlan: null,
|
|
175
|
+
lag: "",
|
|
176
|
+
...extra,
|
|
177
|
+
device,
|
|
178
|
+
name
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function blankLink(aDevice, aInterface, bDevice, bInterface, label = "", inferred = false) {
|
|
182
|
+
return {
|
|
183
|
+
a: { device: aDevice, interface: aInterface },
|
|
184
|
+
b: { device: bDevice, interface: bInterface },
|
|
185
|
+
label,
|
|
186
|
+
inferred
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function ensureDevice(devices, name, extra = {}) {
|
|
190
|
+
const trimmed = name.trim();
|
|
191
|
+
const found = devices.find((device) => device.name.toLowerCase() === trimmed.toLowerCase());
|
|
192
|
+
if (found) return found.name;
|
|
193
|
+
devices.push(blankDevice(trimmed, extra));
|
|
194
|
+
return trimmed;
|
|
195
|
+
}
|
|
196
|
+
function ensureLinkEnds(devices, interfaces, links) {
|
|
197
|
+
const known = new Set(devices.map((device) => device.name.toLowerCase()));
|
|
198
|
+
for (const link of links) {
|
|
199
|
+
for (const end of [link.a, link.b]) {
|
|
200
|
+
if (!known.has(end.device.toLowerCase())) continue;
|
|
201
|
+
ensureInterface(interfaces, end.device, end.interface);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function ensureInterface(interfaces, device, name, extra = {}) {
|
|
206
|
+
if (!device || !name) return;
|
|
207
|
+
if (interfaces.some((item) => item.device.toLowerCase() === device.toLowerCase() && item.name === name)) return;
|
|
208
|
+
interfaces.push(blankInterface(device, name, extra));
|
|
209
|
+
}
|
|
210
|
+
function cmp(a, b) {
|
|
211
|
+
if (a < b) return -1;
|
|
212
|
+
if (a > b) return 1;
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
function cleanAddress(address) {
|
|
216
|
+
const family = address.address.includes(":") ? "ipv6" : "ipv4";
|
|
217
|
+
const canonical = canonicalIp(address.address, family);
|
|
218
|
+
if (!canonical) return null;
|
|
219
|
+
if (!Number.isInteger(address.prefix)) return null;
|
|
220
|
+
return { address: canonical, prefix: address.prefix };
|
|
221
|
+
}
|
|
222
|
+
function publishDevice(device) {
|
|
223
|
+
const out = { name: device.name };
|
|
224
|
+
if (device.platform) out.platform = device.platform;
|
|
225
|
+
if (device.model) out.model = device.model;
|
|
226
|
+
if (device.role) out.role = device.role;
|
|
227
|
+
if (device.site) out.site = device.site;
|
|
228
|
+
if (device.managementIp) out.managementIp = device.managementIp;
|
|
229
|
+
if (device.diagram) out.diagram = device.diagram;
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
function publishInterface(item) {
|
|
233
|
+
const out = { device: item.device, name: item.name };
|
|
234
|
+
if (item.description) out.description = item.description;
|
|
235
|
+
if (item.speed) out.speed = item.speed;
|
|
236
|
+
if (item.adminStatus) out.adminStatus = item.adminStatus;
|
|
237
|
+
if (item.operStatus) out.operStatus = item.operStatus;
|
|
238
|
+
const ipv4 = item.ipv4.map(cleanAddress).filter((address) => address != null);
|
|
239
|
+
const ipv6 = item.ipv6.map(cleanAddress).filter((address) => address != null);
|
|
240
|
+
if (ipv4.length > 0) out.ipv4 = ipv4;
|
|
241
|
+
if (ipv6.length > 0) out.ipv6 = ipv6;
|
|
242
|
+
if (item.vrf) out.vrf = item.vrf;
|
|
243
|
+
if (item.switchportMode) out.switchportMode = item.switchportMode;
|
|
244
|
+
if (item.accessVlan != null) out.accessVlan = item.accessVlan;
|
|
245
|
+
if (item.trunkVlans) out.trunkVlans = [...item.trunkVlans];
|
|
246
|
+
if (item.nativeVlan != null) out.nativeVlan = item.nativeVlan;
|
|
247
|
+
if (item.lag) out.lag = item.lag;
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
function publishLink(link) {
|
|
251
|
+
const out = {
|
|
252
|
+
a: { device: link.a.device, interface: link.a.interface },
|
|
253
|
+
b: { device: link.b.device, interface: link.b.interface }
|
|
254
|
+
};
|
|
255
|
+
if (link.label) out.label = link.label;
|
|
256
|
+
if (link.inferred) out.inferred = true;
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
function publishVlan(vlan) {
|
|
260
|
+
const out = { id: vlan.id };
|
|
261
|
+
if (vlan.name) out.name = vlan.name;
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
function publishDocument(document) {
|
|
265
|
+
const devices = [...document.devices].sort((a, b) => cmp(a.name, b.name)).map(publishDevice);
|
|
266
|
+
const interfaces = [...document.interfaces].sort((a, b) => cmp(a.device, b.device) || cmp(a.name, b.name)).map(publishInterface);
|
|
267
|
+
const links = [...document.links].sort(
|
|
268
|
+
(a, b) => cmp(a.a.device, b.a.device) || cmp(a.a.interface, b.a.interface) || cmp(a.b.device, b.b.device) || cmp(a.b.interface, b.b.interface) || cmp(a.label, b.label)
|
|
269
|
+
).map(publishLink);
|
|
270
|
+
const vlans = [...document.vlans].sort((a, b) => a.id - b.id).map(publishVlan);
|
|
271
|
+
return { schemaVersion: 1, format: "network", devices, interfaces, links, vlans };
|
|
272
|
+
}
|
|
273
|
+
function linkKey(link) {
|
|
274
|
+
const left = `${link.a.device.toLowerCase()}\0${link.a.interface}`;
|
|
275
|
+
const right = `${link.b.device.toLowerCase()}\0${link.b.interface}`;
|
|
276
|
+
return left < right ? `${left}\0${right}` : `${right}\0${left}`;
|
|
277
|
+
}
|
|
278
|
+
function dedupeLinks(links) {
|
|
279
|
+
const seen = /* @__PURE__ */ new Map();
|
|
280
|
+
const out = [];
|
|
281
|
+
for (const link of links) {
|
|
282
|
+
if (!link.a.device || !link.a.interface || !link.b.device || !link.b.interface) continue;
|
|
283
|
+
if (link.a.device.toLowerCase() === link.b.device.toLowerCase() && link.a.interface === link.b.interface) continue;
|
|
284
|
+
const key = linkKey(link);
|
|
285
|
+
const index = seen.get(key);
|
|
286
|
+
if (index == null) {
|
|
287
|
+
seen.set(key, out.length);
|
|
288
|
+
out.push(link);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const kept = out[index];
|
|
292
|
+
if (kept?.inferred && !link.inferred) out[index] = link;
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
function sortWarnings(warnings) {
|
|
297
|
+
return [...warnings].sort((a, b) => cmp(a.path, b.path) || cmp(a.message, b.message));
|
|
298
|
+
}
|
|
299
|
+
function vlanId(value) {
|
|
300
|
+
const id = integerLike(value);
|
|
301
|
+
if (id == null || id < 1 || id > 4094) return null;
|
|
302
|
+
return id;
|
|
303
|
+
}
|
|
304
|
+
function plural(count, noun) {
|
|
305
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// server/src/translators/run.ts
|
|
309
|
+
import { parse as parseYaml } from "yaml";
|
|
310
|
+
|
|
311
|
+
// server/src/translators/registry.ts
|
|
312
|
+
import { readdir } from "node:fs/promises";
|
|
313
|
+
import path from "node:path";
|
|
314
|
+
import { fileURLToPath } from "node:url";
|
|
315
|
+
|
|
316
|
+
// server/src/translators/batfish.ts
|
|
317
|
+
var batfish_exports = {};
|
|
318
|
+
__export(batfish_exports, {
|
|
319
|
+
default: () => batfish_default
|
|
320
|
+
});
|
|
321
|
+
var IFACE_USED = /* @__PURE__ */ new Set([
|
|
322
|
+
"Interface",
|
|
323
|
+
"Access_VLAN",
|
|
324
|
+
"Active",
|
|
325
|
+
"Admin_Up",
|
|
326
|
+
"All_Prefixes",
|
|
327
|
+
"Allowed_VLANs",
|
|
328
|
+
"Bandwidth",
|
|
329
|
+
"Description",
|
|
330
|
+
"Native_VLAN",
|
|
331
|
+
"Primary_Address",
|
|
332
|
+
"Switchport_Mode",
|
|
333
|
+
"VRF"
|
|
334
|
+
]);
|
|
335
|
+
var EDGE_USED = /* @__PURE__ */ new Set(["Interface", "IPs", "Remote_Interface", "Remote_IPs"]);
|
|
336
|
+
var VLAN_USED = /* @__PURE__ */ new Set(["Node", "VLAN_ID", "Interfaces", "Name", "VLAN_Name"]);
|
|
337
|
+
var L1_USED = /* @__PURE__ */ new Set(["node1", "node2"]);
|
|
338
|
+
function recordsOf(value) {
|
|
339
|
+
if (value == null) return [];
|
|
340
|
+
if (Array.isArray(value)) return value.filter(isRecord);
|
|
341
|
+
if (!isRecord(value)) return [];
|
|
342
|
+
if (Array.isArray(value.rows)) return value.rows.filter(isRecord);
|
|
343
|
+
if (Array.isArray(value.answerElements)) {
|
|
344
|
+
return value.answerElements.flatMap((element) => isRecord(element) && Array.isArray(element.rows) ? element.rows.filter(isRecord) : []);
|
|
345
|
+
}
|
|
346
|
+
if (Array.isArray(value.columns) && Array.isArray(value.data)) {
|
|
347
|
+
const columns2 = value.columns.map((item) => textOf(item));
|
|
348
|
+
return value.data.filter(Array.isArray).map((row) => {
|
|
349
|
+
const record = {};
|
|
350
|
+
columns2.forEach((column, index) => {
|
|
351
|
+
record[column] = row[index];
|
|
352
|
+
});
|
|
353
|
+
return record;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
const keys = Object.keys(value);
|
|
357
|
+
if (keys.length === 0) return [];
|
|
358
|
+
const columns = keys.filter((key) => Array.isArray(value[key]) || isRecord(value[key]) && !Array.isArray(value[key]));
|
|
359
|
+
if (columns.length === 0) return [value];
|
|
360
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
361
|
+
for (const key of columns) {
|
|
362
|
+
const column = value[key];
|
|
363
|
+
if (Array.isArray(column)) column.forEach((_, index) => indexes.add(String(index)));
|
|
364
|
+
else if (isRecord(column)) Object.keys(column).forEach((index) => indexes.add(index));
|
|
365
|
+
}
|
|
366
|
+
const rows6 = [];
|
|
367
|
+
for (const index of [...indexes].sort((a, b) => Number(a) - Number(b))) {
|
|
368
|
+
const row = {};
|
|
369
|
+
for (const key of columns) {
|
|
370
|
+
const column = value[key];
|
|
371
|
+
if (Array.isArray(column)) row[key] = column[Number(index)];
|
|
372
|
+
else if (isRecord(column)) row[key] = column[index];
|
|
373
|
+
}
|
|
374
|
+
rows6.push(row);
|
|
375
|
+
}
|
|
376
|
+
return rows6.length > 0 ? rows6 : [value];
|
|
377
|
+
}
|
|
378
|
+
function section(input, keys) {
|
|
379
|
+
for (const key of keys) {
|
|
380
|
+
if (key in input) return input[key];
|
|
381
|
+
}
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
function endOf(value) {
|
|
385
|
+
if (isRecord(value)) {
|
|
386
|
+
const host = textOf(value.hostname);
|
|
387
|
+
const iface = textOf(value.interface) || textOf(value.interfaceName);
|
|
388
|
+
if (host && iface) return { host, iface };
|
|
389
|
+
}
|
|
390
|
+
const text = textOf(value);
|
|
391
|
+
const match = /^(.+)\[(.+)]$/.exec(text);
|
|
392
|
+
if (!match?.[1] || !match[2]) return null;
|
|
393
|
+
return { host: match[1], iface: match[2] };
|
|
394
|
+
}
|
|
395
|
+
function endKey(end) {
|
|
396
|
+
return `${end.host.toLowerCase()}\0${end.iface}`;
|
|
397
|
+
}
|
|
398
|
+
function pairKey(a, b) {
|
|
399
|
+
const left = endKey(a);
|
|
400
|
+
const right = endKey(b);
|
|
401
|
+
return left < right ? `${left}\0${right}` : `${right}\0${left}`;
|
|
402
|
+
}
|
|
403
|
+
function prefixes(value) {
|
|
404
|
+
if (Array.isArray(value)) return value.map(textOf).filter(Boolean);
|
|
405
|
+
const text = textOf(value);
|
|
406
|
+
return text ? [text] : [];
|
|
407
|
+
}
|
|
408
|
+
function parseVlans(value) {
|
|
409
|
+
if (Array.isArray(value)) return value.map((item) => vlanId(item)).filter((item) => item != null);
|
|
410
|
+
const text = textOf(value);
|
|
411
|
+
if (!text) return [];
|
|
412
|
+
const ids = [];
|
|
413
|
+
for (const part of text.split(",")) {
|
|
414
|
+
const piece = part.trim();
|
|
415
|
+
const range = /^(\d+)\s*-\s*(\d+)$/.exec(piece);
|
|
416
|
+
if (range?.[1] && range[2]) {
|
|
417
|
+
const start = vlanId(range[1]);
|
|
418
|
+
const end = vlanId(range[2]);
|
|
419
|
+
if (start != null && end != null) {
|
|
420
|
+
for (let id2 = start; id2 <= end && id2 <= start + 64; id2 += 1) ids.push(id2);
|
|
421
|
+
}
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
const id = vlanId(piece);
|
|
425
|
+
if (id != null) ids.push(id);
|
|
426
|
+
}
|
|
427
|
+
return ids;
|
|
428
|
+
}
|
|
429
|
+
function speedOf(value) {
|
|
430
|
+
const number = numberLike(value);
|
|
431
|
+
if (number == null || number <= 0) return "";
|
|
432
|
+
return formatRate(number, number >= 1e6 ? "bps" : "kbps");
|
|
433
|
+
}
|
|
434
|
+
function mapInterfaces(rows6, warnings) {
|
|
435
|
+
const devices = [];
|
|
436
|
+
const interfaces = [];
|
|
437
|
+
const known = /* @__PURE__ */ new Set();
|
|
438
|
+
rows6.forEach((row, index) => {
|
|
439
|
+
const pointer = `/interfaceProperties/${index}`;
|
|
440
|
+
noteUnmapped(warnings, pointer, row, IFACE_USED, "interface");
|
|
441
|
+
const end = endOf(row.Interface);
|
|
442
|
+
if (!end) {
|
|
443
|
+
pushWarning(warnings, pointer, "Skipped an interface row with no node and port.");
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (!known.has(end.host.toLowerCase())) {
|
|
447
|
+
known.add(end.host.toLowerCase());
|
|
448
|
+
devices.push(blankDevice(end.host));
|
|
449
|
+
}
|
|
450
|
+
const addresses = [...prefixes(row.All_Prefixes), ...prefixes(row.Primary_Address)];
|
|
451
|
+
const ipv4 = [];
|
|
452
|
+
const ipv6 = [];
|
|
453
|
+
for (const prefix of addresses) {
|
|
454
|
+
const cidr = splitCidr(prefix);
|
|
455
|
+
if (!cidr) continue;
|
|
456
|
+
const stored = { address: cidr.address, prefix: cidr.prefix };
|
|
457
|
+
const list = cidr.family === "ipv4" ? ipv4 : ipv6;
|
|
458
|
+
if (!list.some((item) => item.address === stored.address && item.prefix === stored.prefix)) list.push(stored);
|
|
459
|
+
}
|
|
460
|
+
const mode = textOf(row.Switchport_Mode).toLowerCase();
|
|
461
|
+
const switchportMode = mode === "access" ? "access" : mode === "trunk" ? "trunk" : "";
|
|
462
|
+
const admin = statusUpDown(row.Admin_Up);
|
|
463
|
+
const oper = statusUpDown(row.Active);
|
|
464
|
+
const vrf = textOf(row.VRF);
|
|
465
|
+
interfaces.push(
|
|
466
|
+
blankInterface(end.host, end.iface, {
|
|
467
|
+
description: textOf(row.Description),
|
|
468
|
+
adminStatus: admin === "up" || admin === "down" ? admin : "",
|
|
469
|
+
operStatus: oper === "up" || oper === "down" ? oper : "",
|
|
470
|
+
speed: speedOf(row.Bandwidth),
|
|
471
|
+
ipv4,
|
|
472
|
+
ipv6,
|
|
473
|
+
vrf: vrf && vrf.toLowerCase() !== "default" ? vrf : "",
|
|
474
|
+
switchportMode,
|
|
475
|
+
accessVlan: switchportMode === "access" ? vlanId(row.Access_VLAN) : null,
|
|
476
|
+
nativeVlan: switchportMode === "trunk" ? vlanId(row.Native_VLAN) : null,
|
|
477
|
+
trunkVlans: switchportMode === "trunk" ? parseVlans(row.Allowed_VLANs) : null
|
|
478
|
+
})
|
|
479
|
+
);
|
|
480
|
+
});
|
|
481
|
+
return { devices, interfaces };
|
|
482
|
+
}
|
|
483
|
+
function layer1Pairs(value, warnings) {
|
|
484
|
+
const body = isRecord(value) && Array.isArray(value.edges) ? value : isRecord(value) && isRecord(value.layer1_topology) ? value.layer1_topology : value;
|
|
485
|
+
const edges = isRecord(body) && Array.isArray(body.edges) ? body.edges : [];
|
|
486
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
487
|
+
const links = [];
|
|
488
|
+
const devices = [];
|
|
489
|
+
edges.forEach((edge, index) => {
|
|
490
|
+
const pointer = `/layer1_topology/edges/${index}`;
|
|
491
|
+
if (!isRecord(edge)) return;
|
|
492
|
+
noteUnmapped(warnings, pointer, edge, L1_USED, "layer 1 edge");
|
|
493
|
+
const a = isRecord(edge.node1) ? { host: textOf(edge.node1.hostname), iface: textOf(edge.node1.interfaceName) } : null;
|
|
494
|
+
const b = isRecord(edge.node2) ? { host: textOf(edge.node2.hostname), iface: textOf(edge.node2.interfaceName) } : null;
|
|
495
|
+
if (!a?.host || !a.iface || !b?.host || !b.iface) {
|
|
496
|
+
pushWarning(warnings, pointer, "Skipped a layer 1 edge that does not name both ends.");
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
pairs.add(pairKey(a, b));
|
|
500
|
+
ensureDevice(devices, a.host);
|
|
501
|
+
ensureDevice(devices, b.host);
|
|
502
|
+
links.push(blankLink(a.host, a.iface, b.host, b.iface));
|
|
503
|
+
});
|
|
504
|
+
return { pairs, links, devices };
|
|
505
|
+
}
|
|
506
|
+
function mapLayer3(rows6, physical, devices, warnings) {
|
|
507
|
+
const links = [];
|
|
508
|
+
rows6.forEach((row, index) => {
|
|
509
|
+
const pointer = `/layer3Edges/${index}`;
|
|
510
|
+
noteUnmapped(warnings, pointer, row, EDGE_USED, "layer 3 edge");
|
|
511
|
+
const a = endOf(row.Interface);
|
|
512
|
+
const b = endOf(row.Remote_Interface);
|
|
513
|
+
if (!a || !b) {
|
|
514
|
+
pushWarning(warnings, pointer, "Skipped a layer 3 edge that does not name both interfaces.");
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const inferred = !physical.has(pairKey(a, b));
|
|
518
|
+
ensureDevice(devices, a.host);
|
|
519
|
+
ensureDevice(devices, b.host);
|
|
520
|
+
links.push(blankLink(a.host, a.iface, b.host, b.iface, "", inferred));
|
|
521
|
+
});
|
|
522
|
+
return links;
|
|
523
|
+
}
|
|
524
|
+
function mapVlans(rows6, warnings) {
|
|
525
|
+
const vlans = [];
|
|
526
|
+
const seen = /* @__PURE__ */ new Set();
|
|
527
|
+
rows6.forEach((row, index) => {
|
|
528
|
+
noteUnmapped(warnings, `/switchedVlanProperties/${index}`, row, VLAN_USED, "VLAN");
|
|
529
|
+
const id = vlanId(row.VLAN_ID);
|
|
530
|
+
if (id == null || seen.has(id)) return;
|
|
531
|
+
seen.add(id);
|
|
532
|
+
vlans.push({ id, name: textOf(row.Name) || textOf(row.VLAN_Name) });
|
|
533
|
+
});
|
|
534
|
+
return vlans;
|
|
535
|
+
}
|
|
536
|
+
function convertBatfish(input) {
|
|
537
|
+
if (!isRecord(input) && !Array.isArray(input)) throw translatorFail(400, "A Batfish export must be a JSON object or array.");
|
|
538
|
+
const warnings = [];
|
|
539
|
+
const root = isRecord(input) ? input : { interfaceProperties: input };
|
|
540
|
+
const ifaceRows = recordsOf(section(root, ["interfaceProperties", "interface_properties"]) ?? (Array.isArray(input) ? input : null));
|
|
541
|
+
const mapped = mapInterfaces(ifaceRows, warnings);
|
|
542
|
+
const layer1 = layer1Pairs(section(root, ["layer1_topology", "layer1"]), warnings);
|
|
543
|
+
for (const device of layer1.devices) ensureDevice(mapped.devices, device.name);
|
|
544
|
+
const layer3 = mapLayer3(recordsOf(section(root, ["layer3Edges", "layer3_edges"])), layer1.pairs, mapped.devices, warnings);
|
|
545
|
+
const links = dedupeLinks([...layer1.links, ...layer3]);
|
|
546
|
+
const vlans = mapVlans(recordsOf(section(root, ["switchedVlanProperties", "switched_vlan_properties"])), warnings);
|
|
547
|
+
ensureLinkEnds(mapped.devices, mapped.interfaces, links);
|
|
548
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
549
|
+
return {
|
|
550
|
+
document: publishDocument({ devices: mapped.devices, interfaces: mapped.interfaces, links, vlans }),
|
|
551
|
+
warnings: sortWarnings(warnings)
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
var batfish = {
|
|
555
|
+
id: "batfish",
|
|
556
|
+
name: "Batfish",
|
|
557
|
+
formatHint: "Saved Batfish question JSON, with an optional layer1 topology",
|
|
558
|
+
placeholder: `{
|
|
559
|
+
"interfaceProperties": [],
|
|
560
|
+
"layer3Edges": [],
|
|
561
|
+
"layer1_topology": { "edges": [] }
|
|
562
|
+
}`,
|
|
563
|
+
convert: convertBatfish
|
|
564
|
+
};
|
|
565
|
+
var batfish_default = batfish;
|
|
566
|
+
|
|
567
|
+
// server/src/translators/catalyst-center.ts
|
|
568
|
+
var catalyst_center_exports = {};
|
|
569
|
+
__export(catalyst_center_exports, {
|
|
570
|
+
default: () => catalyst_center_default
|
|
571
|
+
});
|
|
572
|
+
var NODE_USED = /* @__PURE__ */ new Set(["id", "label", "ip", "deviceType", "nodeType", "role", "family", "platformId", "siteId", "additionalInfo"]);
|
|
573
|
+
var LINK_USED = /* @__PURE__ */ new Set(["id", "source", "target", "startPortName", "endPortName", "linkStatus", "startPortSpeed"]);
|
|
574
|
+
var DEVICE_USED = /* @__PURE__ */ new Set([
|
|
575
|
+
"id",
|
|
576
|
+
"instanceUuid",
|
|
577
|
+
"hostname",
|
|
578
|
+
"managementIpAddress",
|
|
579
|
+
"platformId",
|
|
580
|
+
"softwareType",
|
|
581
|
+
"softwareVersion",
|
|
582
|
+
"role",
|
|
583
|
+
"family",
|
|
584
|
+
"type"
|
|
585
|
+
]);
|
|
586
|
+
var SITE_USED = /* @__PURE__ */ new Set(["id", "name", "groupNameHierarchy", "siteName"]);
|
|
587
|
+
function rows(value, keys) {
|
|
588
|
+
if (value == null) return [];
|
|
589
|
+
if (isRecord(value) && isRecord(value.response)) return rows(value.response, keys);
|
|
590
|
+
const section2 = sectionList(value, [...keys, "response"]);
|
|
591
|
+
return section2.bad ? [] : section2.items;
|
|
592
|
+
}
|
|
593
|
+
function topologyOf(input) {
|
|
594
|
+
const physical = isRecord(input.physicalTopology) ? input.physicalTopology : input;
|
|
595
|
+
const body = isRecord(physical.response) ? physical.response : physical;
|
|
596
|
+
return {
|
|
597
|
+
nodes: rows(body.nodes ?? body, ["nodes"]),
|
|
598
|
+
links: rows(isRecord(body) && "links" in body ? body.links : input.links, ["links"])
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
function mapInventory(items, warnings) {
|
|
602
|
+
const byId = /* @__PURE__ */ new Map();
|
|
603
|
+
const byName = /* @__PURE__ */ new Map();
|
|
604
|
+
items.forEach((item, index) => {
|
|
605
|
+
if (!isRecord(item)) return;
|
|
606
|
+
noteUnmapped(warnings, `/network-device/${index}`, item, DEVICE_USED, "network device");
|
|
607
|
+
const id = idKey(item.id) || idKey(item.instanceUuid);
|
|
608
|
+
if (id) byId.set(id, item);
|
|
609
|
+
const name = textOf(item.hostname);
|
|
610
|
+
if (name) byName.set(name.toLowerCase(), item);
|
|
611
|
+
});
|
|
612
|
+
return { byId, byName };
|
|
613
|
+
}
|
|
614
|
+
function mapSites(items, warnings) {
|
|
615
|
+
const byId = /* @__PURE__ */ new Map();
|
|
616
|
+
items.forEach((item, index) => {
|
|
617
|
+
if (!isRecord(item)) return;
|
|
618
|
+
noteUnmapped(warnings, `/sites/${index}`, item, SITE_USED, "site");
|
|
619
|
+
const name = textOf(item.name) || textOf(item.groupNameHierarchy);
|
|
620
|
+
const id = idKey(item.id);
|
|
621
|
+
if (id && name) byId.set(id, name);
|
|
622
|
+
});
|
|
623
|
+
return byId;
|
|
624
|
+
}
|
|
625
|
+
function mapNodes(items, inventory, sites, warnings) {
|
|
626
|
+
const devices = [];
|
|
627
|
+
const byId = /* @__PURE__ */ new Map();
|
|
628
|
+
const seen = /* @__PURE__ */ new Set();
|
|
629
|
+
items.forEach((item, index) => {
|
|
630
|
+
const pointer = `/nodes/${index}`;
|
|
631
|
+
if (!isRecord(item)) return;
|
|
632
|
+
noteUnmapped(warnings, pointer, item, NODE_USED, "node");
|
|
633
|
+
const label = textOf(item.label);
|
|
634
|
+
if (!label) {
|
|
635
|
+
pushWarning(warnings, pointer, "Skipped a node with no label.");
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (seen.has(label.toLowerCase())) return;
|
|
639
|
+
seen.add(label.toLowerCase());
|
|
640
|
+
const extra = inventory.byId.get(idKey(item.id)) ?? inventory.byName.get(label.toLowerCase());
|
|
641
|
+
const siteId = idKey(item.siteId);
|
|
642
|
+
const site = siteId && sites.get(siteId) || "";
|
|
643
|
+
devices.push(
|
|
644
|
+
blankDevice(label, {
|
|
645
|
+
managementIp: hostAddress(extra?.managementIpAddress) || hostAddress(item.ip),
|
|
646
|
+
model: textOf(extra?.platformId) || textOf(item.platformId),
|
|
647
|
+
platform: textOf(extra?.softwareType) || textOf(item.family),
|
|
648
|
+
role: textOf(extra?.role) || textOf(item.role),
|
|
649
|
+
site
|
|
650
|
+
})
|
|
651
|
+
);
|
|
652
|
+
const id = idKey(item.id);
|
|
653
|
+
if (id) byId.set(id, { name: label, site });
|
|
654
|
+
});
|
|
655
|
+
return { devices, byId };
|
|
656
|
+
}
|
|
657
|
+
function mapLinks(items, nodes, warnings) {
|
|
658
|
+
const links = [];
|
|
659
|
+
items.forEach((item, index) => {
|
|
660
|
+
const pointer = `/links/${index}`;
|
|
661
|
+
if (!isRecord(item)) return;
|
|
662
|
+
noteUnmapped(warnings, pointer, item, LINK_USED, "link");
|
|
663
|
+
const source = nodes.get(idKey(item.source));
|
|
664
|
+
const target = nodes.get(idKey(item.target));
|
|
665
|
+
const start = textOf(item.startPortName);
|
|
666
|
+
const end = textOf(item.endPortName);
|
|
667
|
+
if (!source || !target || !start || !end) {
|
|
668
|
+
pushWarning(warnings, pointer, "Skipped a link that does not resolve both nodes and port names.");
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
links.push(blankLink(source.name, start, target.name, end, textOf(item.linkStatus)));
|
|
672
|
+
});
|
|
673
|
+
return dedupeLinks(links);
|
|
674
|
+
}
|
|
675
|
+
function convertCatalyst(input) {
|
|
676
|
+
if (!isRecord(input)) throw translatorFail(400, "A Catalyst Center export must be a JSON object.");
|
|
677
|
+
const warnings = [];
|
|
678
|
+
const topology = topologyOf(input);
|
|
679
|
+
const inventory = mapInventory(rows(input["network-device"] ?? input.networkDevice ?? input.devices, ["response", "devices"]), warnings);
|
|
680
|
+
const sites = mapSites(rows(input.sites ?? input.siteTopology, ["sites", "response"]), warnings);
|
|
681
|
+
const nodes = mapNodes(topology.nodes, inventory, sites, warnings);
|
|
682
|
+
const links = mapLinks(topology.links, nodes.byId, warnings);
|
|
683
|
+
const interfaces = [];
|
|
684
|
+
ensureLinkEnds(nodes.devices, interfaces, links);
|
|
685
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
686
|
+
return {
|
|
687
|
+
document: publishDocument({ devices: nodes.devices, interfaces, links, vlans: [] }),
|
|
688
|
+
warnings: sortWarnings(warnings)
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
var catalystCenter = {
|
|
692
|
+
id: "catalyst-center",
|
|
693
|
+
name: "Cisco Catalyst Center",
|
|
694
|
+
formatHint: "Saved Catalyst Center physical topology JSON",
|
|
695
|
+
placeholder: `{
|
|
696
|
+
"response": {
|
|
697
|
+
"nodes": [ { "id": "1", "label": "core-rtr" } ],
|
|
698
|
+
"links": []
|
|
699
|
+
}
|
|
700
|
+
}`,
|
|
701
|
+
convert: convertCatalyst
|
|
702
|
+
};
|
|
703
|
+
var catalyst_center_default = catalystCenter;
|
|
704
|
+
|
|
705
|
+
// server/src/translators/librenms.ts
|
|
706
|
+
var librenms_exports = {};
|
|
707
|
+
__export(librenms_exports, {
|
|
708
|
+
default: () => librenms_default
|
|
709
|
+
});
|
|
710
|
+
var DEVICE_USED2 = /* @__PURE__ */ new Set(["device_id", "hostname", "sysName", "display", "hardware", "os", "location", "ip"]);
|
|
711
|
+
var PORT_USED = /* @__PURE__ */ new Set([
|
|
712
|
+
"port_id",
|
|
713
|
+
"device_id",
|
|
714
|
+
"ifName",
|
|
715
|
+
"ifAlias",
|
|
716
|
+
"ifDescr",
|
|
717
|
+
"ifSpeed",
|
|
718
|
+
"ifHighSpeed",
|
|
719
|
+
"ifAdminStatus",
|
|
720
|
+
"ifOperStatus",
|
|
721
|
+
"vlans",
|
|
722
|
+
"ifVrf",
|
|
723
|
+
"addresses",
|
|
724
|
+
"ips"
|
|
725
|
+
]);
|
|
726
|
+
var LINK_USED2 = /* @__PURE__ */ new Set([
|
|
727
|
+
"id",
|
|
728
|
+
"local_port_id",
|
|
729
|
+
"local_device_id",
|
|
730
|
+
"remote_port_id",
|
|
731
|
+
"remote_device_id",
|
|
732
|
+
"remote_hostname",
|
|
733
|
+
"remote_port",
|
|
734
|
+
"remote_platform",
|
|
735
|
+
"active"
|
|
736
|
+
]);
|
|
737
|
+
var IP_USED = /* @__PURE__ */ new Set(["port_id", "ipv4_address", "ipv4_prefixlen", "ipv6_address", "ipv6_prefixlen", "ipv6_compressed", "address"]);
|
|
738
|
+
function locationOf(value) {
|
|
739
|
+
if (typeof value === "string") return value.trim();
|
|
740
|
+
if (!isRecord(value)) return "";
|
|
741
|
+
return textOf(value.name) || textOf(value.location);
|
|
742
|
+
}
|
|
743
|
+
function readNamed(warnings, root, key, inner) {
|
|
744
|
+
if (!(key in root)) return null;
|
|
745
|
+
const section2 = sectionList(root[key], [key, ...inner, "results"]);
|
|
746
|
+
if (section2.next) pushWarning(warnings, `/${key}`, `Ignored next page URL on ${key}. NerdGram does not fetch it.`);
|
|
747
|
+
if (section2.bad) {
|
|
748
|
+
pushWarning(warnings, `/${key}`, `${key} is not a list or a LibreNMS ${key} envelope.`);
|
|
749
|
+
return [];
|
|
750
|
+
}
|
|
751
|
+
return section2.items;
|
|
752
|
+
}
|
|
753
|
+
function mapDevices(items, warnings) {
|
|
754
|
+
const devices = [];
|
|
755
|
+
const ids = /* @__PURE__ */ new Map();
|
|
756
|
+
const seen = /* @__PURE__ */ new Set();
|
|
757
|
+
items.forEach((item, index) => {
|
|
758
|
+
const pointer = `/devices/${index}`;
|
|
759
|
+
if (!isRecord(item)) {
|
|
760
|
+
pushWarning(warnings, pointer, "Skipped a device that is not an object.");
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
noteUnmapped(warnings, pointer, item, DEVICE_USED2, "device");
|
|
764
|
+
const hostname = textOf(item.hostname);
|
|
765
|
+
const sysName = textOf(item.sysName);
|
|
766
|
+
const display = textOf(item.display);
|
|
767
|
+
const name = hostname || sysName || display;
|
|
768
|
+
if (!name) {
|
|
769
|
+
pushWarning(warnings, pointer, "Skipped a device with no hostname.");
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
if (!hostname && sysName) pushWarning(warnings, pointer, `Device ${item.device_id ?? index + 1} has no hostname, so sysName was used.`);
|
|
773
|
+
else if (!hostname && !sysName && display) pushWarning(warnings, pointer, `Device ${item.device_id ?? index + 1} has no hostname, so display was used.`);
|
|
774
|
+
if (seen.has(name.toLowerCase())) {
|
|
775
|
+
pushWarning(warnings, pointer, `Duplicate device "${name}" was skipped.`);
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
seen.add(name.toLowerCase());
|
|
779
|
+
const ip = hostAddress(item.ip);
|
|
780
|
+
if (textOf(item.ip) && !ip) pushWarning(warnings, `${pointer}/ip`, `Device ${name} ip is not an IP address, so managementIp was left empty.`);
|
|
781
|
+
devices.push(
|
|
782
|
+
blankDevice(name, {
|
|
783
|
+
model: textOf(item.hardware),
|
|
784
|
+
platform: textOf(item.os),
|
|
785
|
+
site: locationOf(item.location),
|
|
786
|
+
managementIp: ip
|
|
787
|
+
})
|
|
788
|
+
);
|
|
789
|
+
const id = idKey(item.device_id);
|
|
790
|
+
if (id) ids.set(id, name);
|
|
791
|
+
});
|
|
792
|
+
return { devices, ids };
|
|
793
|
+
}
|
|
794
|
+
function portSpeed(item, warnings, pointer, label) {
|
|
795
|
+
const speed = item.ifSpeed;
|
|
796
|
+
const parsed = speed == null || speed === "" ? null : typeof speed === "number" ? speed : Number(textOf(speed));
|
|
797
|
+
if (parsed != null && Number.isFinite(parsed) && parsed > 0) return formatRate(parsed, "bps");
|
|
798
|
+
if (parsed != null && (!Number.isFinite(parsed) || parsed < 0)) {
|
|
799
|
+
pushWarning(warnings, `${pointer}/ifSpeed`, `Port ${label} ifSpeed is not a number, so speed was left empty.`);
|
|
800
|
+
return "";
|
|
801
|
+
}
|
|
802
|
+
const high = item.ifHighSpeed;
|
|
803
|
+
const mbps = high == null || high === "" ? null : typeof high === "number" ? high : Number(textOf(high));
|
|
804
|
+
if (mbps != null && Number.isFinite(mbps) && mbps > 0) return formatRate(mbps * 1e6, "bps");
|
|
805
|
+
return "";
|
|
806
|
+
}
|
|
807
|
+
function portStatus(value, warnings, pointer, label, field) {
|
|
808
|
+
const status = statusUpDown(value);
|
|
809
|
+
if (status === "other") {
|
|
810
|
+
pushWarning(warnings, `${pointer}/${field}`, `Port ${label} ${field} "${String(value)}" is not up or down, so it was left empty.`);
|
|
811
|
+
return "";
|
|
812
|
+
}
|
|
813
|
+
return status;
|
|
814
|
+
}
|
|
815
|
+
function vrfOf(value, warnings, pointer) {
|
|
816
|
+
if (value == null || value === "" || value === 0 || value === "0") return "";
|
|
817
|
+
const text = textOf(value);
|
|
818
|
+
if (!text) return "";
|
|
819
|
+
if (/^\d+$/.test(text)) {
|
|
820
|
+
pushWarning(warnings, `${pointer}/ifVrf`, "Port ifVrf is an id, not a name, so vrf was left empty.");
|
|
821
|
+
return "";
|
|
822
|
+
}
|
|
823
|
+
return text;
|
|
824
|
+
}
|
|
825
|
+
function vlansOf(value, warnings, pointer, label) {
|
|
826
|
+
const empty = { mode: "", access: null, native: null, trunk: null };
|
|
827
|
+
if (value == null) return empty;
|
|
828
|
+
if (!Array.isArray(value)) {
|
|
829
|
+
pushWarning(warnings, `${pointer}/vlans`, `Port ${label} vlans is not a list, so switchport mode was left empty.`);
|
|
830
|
+
return empty;
|
|
831
|
+
}
|
|
832
|
+
const untagged = [];
|
|
833
|
+
const tagged = [];
|
|
834
|
+
let unclear = false;
|
|
835
|
+
for (const item of value) {
|
|
836
|
+
if (!isRecord(item)) continue;
|
|
837
|
+
const id = vlanId(item.vlan);
|
|
838
|
+
if (id == null) continue;
|
|
839
|
+
const flag = item.untagged;
|
|
840
|
+
const isUntagged = flag === 1 || flag === "1" || flag === true;
|
|
841
|
+
const isTagged = flag === 0 || flag === "0" || flag === false;
|
|
842
|
+
if (isUntagged) untagged.push(id);
|
|
843
|
+
else if (isTagged) tagged.push(id);
|
|
844
|
+
else unclear = true;
|
|
845
|
+
}
|
|
846
|
+
if (tagged.length > 0) {
|
|
847
|
+
return { mode: "trunk", access: null, native: untagged.length === 1 ? untagged[0] : null, trunk: tagged };
|
|
848
|
+
}
|
|
849
|
+
if (untagged.length === 1 && !unclear) return { mode: "access", access: untagged[0], native: null, trunk: null };
|
|
850
|
+
if (untagged.length > 0 || unclear) {
|
|
851
|
+
pushWarning(warnings, `${pointer}/vlans`, `Port ${label} VLAN rows do not set a switchport mode, so switchport mode was left empty.`);
|
|
852
|
+
}
|
|
853
|
+
return empty;
|
|
854
|
+
}
|
|
855
|
+
function mapPorts(items, deviceIds, warnings) {
|
|
856
|
+
const interfaces = [];
|
|
857
|
+
const byId = /* @__PURE__ */ new Map();
|
|
858
|
+
const addresses = [];
|
|
859
|
+
const seen = /* @__PURE__ */ new Set();
|
|
860
|
+
items.forEach((item, index) => {
|
|
861
|
+
const pointer = `/ports/${index}`;
|
|
862
|
+
if (!isRecord(item)) {
|
|
863
|
+
pushWarning(warnings, pointer, "Skipped a port that is not an object.");
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
noteUnmapped(warnings, pointer, item, PORT_USED, "port");
|
|
867
|
+
const name = textOf(item.ifName);
|
|
868
|
+
const device = deviceIds.get(idKey(item.device_id)) ?? "";
|
|
869
|
+
if (!device || !name) {
|
|
870
|
+
pushWarning(warnings, pointer, `Skipped port ${name || idKey(item.port_id) || String(index + 1)} because its device is not in this export.`);
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
const pair = `${device.toLowerCase()}\0${name}`;
|
|
874
|
+
if (seen.has(pair)) {
|
|
875
|
+
pushWarning(warnings, pointer, `Duplicate interface ${device} ${name} was skipped.`);
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
seen.add(pair);
|
|
879
|
+
const label = `${device} ${name}`;
|
|
880
|
+
const vlans = vlansOf(item.vlans, warnings, pointer, label);
|
|
881
|
+
interfaces.push(
|
|
882
|
+
blankInterface(device, name, {
|
|
883
|
+
description: textOf(item.ifAlias) || textOf(item.ifDescr),
|
|
884
|
+
speed: portSpeed(item, warnings, pointer, label),
|
|
885
|
+
adminStatus: portStatus(item.ifAdminStatus, warnings, pointer, label, "ifAdminStatus"),
|
|
886
|
+
operStatus: portStatus(item.ifOperStatus, warnings, pointer, label, "ifOperStatus"),
|
|
887
|
+
vrf: vrfOf(item.ifVrf, warnings, pointer),
|
|
888
|
+
switchportMode: vlans.mode,
|
|
889
|
+
accessVlan: vlans.access,
|
|
890
|
+
nativeVlan: vlans.native,
|
|
891
|
+
trunkVlans: vlans.trunk
|
|
892
|
+
})
|
|
893
|
+
);
|
|
894
|
+
const id = idKey(item.port_id);
|
|
895
|
+
if (id) byId.set(id, { device, name });
|
|
896
|
+
const nested = Array.isArray(item.addresses) ? item.addresses : Array.isArray(item.ips) ? item.ips : [];
|
|
897
|
+
for (const row of nested) addresses.push(...readAddressRow(row, id));
|
|
898
|
+
});
|
|
899
|
+
return { interfaces, byId, addresses };
|
|
900
|
+
}
|
|
901
|
+
function readAddressRow(item, fallbackPort) {
|
|
902
|
+
if (!isRecord(item)) return [];
|
|
903
|
+
const portId = idKey(item.port_id) || fallbackPort;
|
|
904
|
+
const rows6 = [];
|
|
905
|
+
const v4 = addressFrom(textOf(item.ipv4_address), item.ipv4_prefixlen);
|
|
906
|
+
const v6text = textOf(item.ipv6_address) || textOf(item.ipv6_compressed);
|
|
907
|
+
const v6 = addressFrom(v6text, item.ipv6_prefixlen);
|
|
908
|
+
const generic = splitCidr(textOf(item.address));
|
|
909
|
+
if (v4) rows6.push({ portId, address: v4 });
|
|
910
|
+
if (v6) rows6.push({ portId, address: v6 });
|
|
911
|
+
if (!v4 && !v6 && generic) rows6.push({ portId, address: generic });
|
|
912
|
+
return rows6;
|
|
913
|
+
}
|
|
914
|
+
function addressFrom(address, prefixValue) {
|
|
915
|
+
if (!address) return null;
|
|
916
|
+
const cidr = splitCidr(address.includes("/") ? address : "");
|
|
917
|
+
if (cidr) return { address: cidr.address, prefix: cidr.prefix };
|
|
918
|
+
const prefix = typeof prefixValue === "number" ? prefixValue : Number(textOf(prefixValue));
|
|
919
|
+
if (!Number.isInteger(prefix)) return null;
|
|
920
|
+
const family = address.includes(":") ? "ipv6" : "ipv4";
|
|
921
|
+
const canonical = hostAddress(address);
|
|
922
|
+
if (!canonical) return null;
|
|
923
|
+
const max = family === "ipv4" ? 32 : 128;
|
|
924
|
+
if (prefix < 0 || prefix > max) return null;
|
|
925
|
+
return { address: canonical, prefix };
|
|
926
|
+
}
|
|
927
|
+
function assignAddresses(rows6, interfaces, byId, warnings) {
|
|
928
|
+
const byPair = new Map(interfaces.map((item) => [`${item.device.toLowerCase()}\0${item.name}`, item]));
|
|
929
|
+
let skipped = 0;
|
|
930
|
+
for (const row of rows6) {
|
|
931
|
+
const ref = byId.get(row.portId);
|
|
932
|
+
const iface = ref ? byPair.get(`${ref.device.toLowerCase()}\0${ref.name}`) : void 0;
|
|
933
|
+
if (!iface) {
|
|
934
|
+
skipped += 1;
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
const list = row.address.address.includes(":") ? iface.ipv6 : iface.ipv4;
|
|
938
|
+
if (!list.some((item) => item.address === row.address.address && item.prefix === row.address.prefix)) list.push(row.address);
|
|
939
|
+
}
|
|
940
|
+
if (skipped > 0) pushWarning(warnings, "/ips", `Ignored ${plural(skipped, "port address")} that ${skipped === 1 ? "does" : "do"} not match a port in this export.`);
|
|
941
|
+
}
|
|
942
|
+
function isInactive(value) {
|
|
943
|
+
return value === false || value === 0 || value === "0" || typeof value === "string" && value.trim().toLowerCase() === "false";
|
|
944
|
+
}
|
|
945
|
+
function ensureDevice2(devices, name, platform) {
|
|
946
|
+
const found = devices.find((device) => device.name.toLowerCase() === name.toLowerCase());
|
|
947
|
+
if (found) return found.name;
|
|
948
|
+
devices.push(blankDevice(name, { platform }));
|
|
949
|
+
return name;
|
|
950
|
+
}
|
|
951
|
+
function mapLinks2(items, devices, deviceIds, ports, warnings) {
|
|
952
|
+
const links = [];
|
|
953
|
+
let inactive2 = 0;
|
|
954
|
+
items.forEach((item, index) => {
|
|
955
|
+
const pointer = `/links/${index}`;
|
|
956
|
+
if (!isRecord(item)) {
|
|
957
|
+
pushWarning(warnings, pointer, "Skipped a link that is not an object.");
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
noteUnmapped(warnings, pointer, item, LINK_USED2, "link");
|
|
961
|
+
if (isInactive(item.active)) {
|
|
962
|
+
inactive2 += 1;
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
const local = ports.get(idKey(item.local_port_id));
|
|
966
|
+
const localDevice = deviceIds.get(idKey(item.local_device_id)) ?? local?.device ?? "";
|
|
967
|
+
const localName = local?.name ?? "";
|
|
968
|
+
if (!localDevice || !localName) {
|
|
969
|
+
pushWarning(warnings, pointer, `Link ${idKey(item.id) || index + 1} has no local port in this export, so it was skipped.`);
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const remoteId = idKey(item.remote_device_id);
|
|
973
|
+
const remoteKnown = remoteId ? deviceIds.get(remoteId) : "";
|
|
974
|
+
const remotePort = ports.get(idKey(item.remote_port_id));
|
|
975
|
+
const remoteName = textOf(item.remote_hostname);
|
|
976
|
+
let remoteDevice = remoteKnown || remotePort?.device || "";
|
|
977
|
+
let remoteInterface = remotePort?.name || textOf(item.remote_port);
|
|
978
|
+
if (!remoteDevice && remoteName && remoteInterface) {
|
|
979
|
+
remoteDevice = ensureDevice2(devices, remoteName, textOf(item.remote_platform));
|
|
980
|
+
}
|
|
981
|
+
if (remoteKnown && remotePort?.device && remotePort.device.toLowerCase() !== remoteKnown.toLowerCase()) {
|
|
982
|
+
remoteInterface = textOf(item.remote_port) || remotePort.name;
|
|
983
|
+
}
|
|
984
|
+
if (!remoteDevice || !remoteInterface) {
|
|
985
|
+
pushWarning(warnings, pointer, `Link ${idKey(item.id) || index + 1} has no remote device in this export, so it was skipped.`);
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
links.push(blankLink(localDevice, localName, remoteDevice, remoteInterface));
|
|
989
|
+
});
|
|
990
|
+
if (inactive2 > 0) pushWarning(warnings, "/links", `Ignored ${plural(inactive2, "inactive link")}.`);
|
|
991
|
+
return dedupeLinks(links);
|
|
992
|
+
}
|
|
993
|
+
function addPlaceholderInterfaces(devices, interfaces, links) {
|
|
994
|
+
const known = new Set(interfaces.map((item) => `${item.device.toLowerCase()}\0${item.name}`));
|
|
995
|
+
const deviceNames = new Set(devices.map((device) => device.name.toLowerCase()));
|
|
996
|
+
for (const link of links) {
|
|
997
|
+
for (const end of [link.a, link.b]) {
|
|
998
|
+
if (!deviceNames.has(end.device.toLowerCase())) continue;
|
|
999
|
+
const key = `${end.device.toLowerCase()}\0${end.interface}`;
|
|
1000
|
+
if (known.has(key)) continue;
|
|
1001
|
+
interfaces.push(blankInterface(end.device, end.interface));
|
|
1002
|
+
known.add(key);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
function collectAddresses(root, nested, warnings) {
|
|
1007
|
+
const rows6 = [...nested];
|
|
1008
|
+
const section2 = readNamed(warnings, root, "ips", ["addresses", "ips"]) ?? readNamed(warnings, root, "addresses", ["addresses"]);
|
|
1009
|
+
if (!section2) return rows6;
|
|
1010
|
+
section2.forEach((item) => {
|
|
1011
|
+
if (isRecord(item)) noteUnmapped(warnings, "/ips", item, IP_USED, "port address");
|
|
1012
|
+
rows6.push(...readAddressRow(item, ""));
|
|
1013
|
+
});
|
|
1014
|
+
return rows6;
|
|
1015
|
+
}
|
|
1016
|
+
function convertLibreNms(input) {
|
|
1017
|
+
if (!isRecord(input)) throw translatorFail(400, "A LibreNMS export must be a JSON object.");
|
|
1018
|
+
const warnings = [];
|
|
1019
|
+
const deviceItems = readNamed(warnings, input, "devices", ["devices"]) ?? [];
|
|
1020
|
+
const portItems = readNamed(warnings, input, "ports", ["ports", "port"]) ?? [];
|
|
1021
|
+
const linkItems = readNamed(warnings, input, "links", ["links"]) ?? [];
|
|
1022
|
+
const mappedDevices = mapDevices(deviceItems, warnings);
|
|
1023
|
+
const mappedPorts = mapPorts(portItems, mappedDevices.ids, warnings);
|
|
1024
|
+
const addresses = collectAddresses(input, mappedPorts.addresses, warnings);
|
|
1025
|
+
assignAddresses(addresses, mappedPorts.interfaces, mappedPorts.byId, warnings);
|
|
1026
|
+
const links = mapLinks2(linkItems, mappedDevices.devices, mappedDevices.ids, mappedPorts.byId, warnings);
|
|
1027
|
+
addPlaceholderInterfaces(mappedDevices.devices, mappedPorts.interfaces, links);
|
|
1028
|
+
if (mappedDevices.devices.length > 0 && mappedPorts.interfaces.length === 0 && links.length === 0) {
|
|
1029
|
+
pushWarning(warnings, "", "No interfaces in this export.");
|
|
1030
|
+
}
|
|
1031
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
1032
|
+
return {
|
|
1033
|
+
document: publishDocument({ devices: mappedDevices.devices, interfaces: mappedPorts.interfaces, links, vlans: [] }),
|
|
1034
|
+
warnings: sortWarnings(warnings)
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
var librenms = {
|
|
1038
|
+
id: "librenms",
|
|
1039
|
+
name: "LibreNMS",
|
|
1040
|
+
formatHint: "Saved LibreNMS API export (devices, ports, links)",
|
|
1041
|
+
placeholder: `{
|
|
1042
|
+
"devices": { "status": "ok", "devices": [ { "hostname": "core-rtr" } ] },
|
|
1043
|
+
"ports": { "status": "ok", "ports": [] },
|
|
1044
|
+
"links": { "status": "ok", "links": [] }
|
|
1045
|
+
}`,
|
|
1046
|
+
convert: convertLibreNms
|
|
1047
|
+
};
|
|
1048
|
+
var librenms_default = librenms;
|
|
1049
|
+
|
|
1050
|
+
// server/src/translators/meraki.ts
|
|
1051
|
+
var meraki_exports = {};
|
|
1052
|
+
__export(meraki_exports, {
|
|
1053
|
+
default: () => meraki_default
|
|
1054
|
+
});
|
|
1055
|
+
var DEVICE_USED3 = /* @__PURE__ */ new Set(["serial", "name", "model", "networkId", "lanIp", "firmware", "mac", "address", "notes", "tags"]);
|
|
1056
|
+
var NETWORK_USED = /* @__PURE__ */ new Set(["id", "name", "organizationId"]);
|
|
1057
|
+
var PORT_USED2 = /* @__PURE__ */ new Set(["lldp", "cdp", "deviceMac", "device"]);
|
|
1058
|
+
var LLDP_USED = /* @__PURE__ */ new Set(["systemName", "portId", "sourcePort", "systemDescription", "chassisId", "managementAddress", "portDescription"]);
|
|
1059
|
+
var CDP_USED = /* @__PURE__ */ new Set(["deviceId", "portId", "sourcePort", "platform", "address", "model"]);
|
|
1060
|
+
function deviceRows(value) {
|
|
1061
|
+
const section2 = sectionList(value, ["devices", "results"]);
|
|
1062
|
+
return section2.bad ? [] : section2.items;
|
|
1063
|
+
}
|
|
1064
|
+
function mapDevices2(items, networks, warnings) {
|
|
1065
|
+
const devices = [];
|
|
1066
|
+
const bySerial = /* @__PURE__ */ new Map();
|
|
1067
|
+
const byName = /* @__PURE__ */ new Map();
|
|
1068
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1069
|
+
items.forEach((item, index) => {
|
|
1070
|
+
const pointer = `/devices/${index}`;
|
|
1071
|
+
if (!isRecord(item)) return;
|
|
1072
|
+
noteUnmapped(warnings, pointer, item, DEVICE_USED3, "device");
|
|
1073
|
+
const serial = textOf(item.serial);
|
|
1074
|
+
const name = textOf(item.name) || serial;
|
|
1075
|
+
if (!name || seen.has(name.toLowerCase())) return;
|
|
1076
|
+
seen.add(name.toLowerCase());
|
|
1077
|
+
const networkId = textOf(item.networkId);
|
|
1078
|
+
devices.push(
|
|
1079
|
+
blankDevice(name, {
|
|
1080
|
+
model: textOf(item.model),
|
|
1081
|
+
managementIp: hostAddress(item.lanIp),
|
|
1082
|
+
site: networks.get(networkId) ?? ""
|
|
1083
|
+
})
|
|
1084
|
+
);
|
|
1085
|
+
if (serial) bySerial.set(serial, name);
|
|
1086
|
+
byName.set(name.toLowerCase(), name);
|
|
1087
|
+
});
|
|
1088
|
+
return { devices, bySerial, byName };
|
|
1089
|
+
}
|
|
1090
|
+
function neighborOf(lldp, cdp, warnings, pointer) {
|
|
1091
|
+
const lldpRow = isRecord(lldp) ? lldp : null;
|
|
1092
|
+
const cdpRow = isRecord(cdp) ? cdp : null;
|
|
1093
|
+
if (lldpRow) noteUnmapped(warnings, `${pointer}/lldp`, lldpRow, LLDP_USED, "LLDP");
|
|
1094
|
+
if (cdpRow) noteUnmapped(warnings, `${pointer}/cdp`, cdpRow, CDP_USED, "CDP");
|
|
1095
|
+
const name = lldpRow && textOf(lldpRow.systemName) || cdpRow && textOf(cdpRow.deviceId) || "";
|
|
1096
|
+
const port = lldpRow && textOf(lldpRow.portId) || cdpRow && textOf(cdpRow.portId) || "";
|
|
1097
|
+
const platform = cdpRow && (textOf(cdpRow.platform) || textOf(cdpRow.model)) || "";
|
|
1098
|
+
if (!name || !port) return null;
|
|
1099
|
+
return { name, port, platform };
|
|
1100
|
+
}
|
|
1101
|
+
function mapLldp(value, devices, bySerial, byName, warnings) {
|
|
1102
|
+
const interfaces = [];
|
|
1103
|
+
const links = [];
|
|
1104
|
+
if (value == null) return { interfaces, links };
|
|
1105
|
+
const entries = [];
|
|
1106
|
+
if (Array.isArray(value)) {
|
|
1107
|
+
value.forEach((item) => {
|
|
1108
|
+
if (!isRecord(item)) return;
|
|
1109
|
+
const serial = textOf(item.serial);
|
|
1110
|
+
if (serial) entries.push({ serial, body: item });
|
|
1111
|
+
});
|
|
1112
|
+
} else if (isRecord(value)) {
|
|
1113
|
+
if (isRecord(value.ports) && textOf(value.serial)) entries.push({ serial: textOf(value.serial), body: value });
|
|
1114
|
+
else {
|
|
1115
|
+
for (const [serial, body] of Object.entries(value)) {
|
|
1116
|
+
if (isRecord(body)) entries.push({ serial, body });
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
entries.forEach(({ serial, body }) => {
|
|
1121
|
+
const device = bySerial.get(serial) || ensureDevice(devices, textOf(body.name) || serial);
|
|
1122
|
+
const ports = isRecord(body.ports) ? body.ports : {};
|
|
1123
|
+
for (const [port, raw] of Object.entries(ports)) {
|
|
1124
|
+
if (!isRecord(raw)) continue;
|
|
1125
|
+
noteUnmapped(warnings, `/lldpCdp/${serial}/${port}`, raw, PORT_USED2, "port");
|
|
1126
|
+
interfaces.push(blankInterface(device, port));
|
|
1127
|
+
const neighbor = neighborOf(raw.lldp, raw.cdp, warnings, `/lldpCdp/${serial}/${port}`);
|
|
1128
|
+
if (!neighbor) continue;
|
|
1129
|
+
const known = byName.get(neighbor.name.toLowerCase());
|
|
1130
|
+
const remote = known || ensureDevice(devices, neighbor.name, { platform: neighbor.platform });
|
|
1131
|
+
links.push(blankLink(device, port, remote, neighbor.port));
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
return { interfaces, links: dedupeLinks(links) };
|
|
1135
|
+
}
|
|
1136
|
+
function convertMeraki(input) {
|
|
1137
|
+
if (!isRecord(input)) throw translatorFail(400, "A Meraki export must be a JSON object.");
|
|
1138
|
+
const warnings = [];
|
|
1139
|
+
const networks = /* @__PURE__ */ new Map();
|
|
1140
|
+
const networkItems = sectionList(input.networks, ["networks"]).items;
|
|
1141
|
+
networkItems.forEach((item, index) => {
|
|
1142
|
+
if (!isRecord(item)) return;
|
|
1143
|
+
noteUnmapped(warnings, `/networks/${index}`, item, NETWORK_USED, "network");
|
|
1144
|
+
const id = textOf(item.id);
|
|
1145
|
+
const name = textOf(item.name);
|
|
1146
|
+
if (id && name) networks.set(id, name);
|
|
1147
|
+
});
|
|
1148
|
+
const deviceItems = deviceRows(input.devices ?? input);
|
|
1149
|
+
const mapped = mapDevices2(deviceItems, networks, warnings);
|
|
1150
|
+
const lldp = mapLldp(input.lldpCdp ?? input.lldp_cdp, mapped.devices, mapped.bySerial, mapped.byName, warnings);
|
|
1151
|
+
const interfaces = [...lldp.interfaces];
|
|
1152
|
+
ensureLinkEnds(mapped.devices, interfaces, lldp.links);
|
|
1153
|
+
if (lldp.links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
1154
|
+
return {
|
|
1155
|
+
document: publishDocument({ devices: mapped.devices, interfaces, links: lldp.links, vlans: [] }),
|
|
1156
|
+
warnings: sortWarnings(warnings)
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
var meraki = {
|
|
1160
|
+
id: "meraki",
|
|
1161
|
+
name: "Meraki Dashboard",
|
|
1162
|
+
formatHint: "Saved Meraki devices and lldpCdp JSON",
|
|
1163
|
+
placeholder: `{
|
|
1164
|
+
"devices": [ { "serial": "Q2XX-AAAA-BBBB", "name": "core-sw", "model": "MS250-24" } ],
|
|
1165
|
+
"lldpCdp": {}
|
|
1166
|
+
}`,
|
|
1167
|
+
convert: convertMeraki
|
|
1168
|
+
};
|
|
1169
|
+
var meraki_default = meraki;
|
|
1170
|
+
|
|
1171
|
+
// server/src/translators/nautobot.ts
|
|
1172
|
+
var nautobot_exports = {};
|
|
1173
|
+
__export(nautobot_exports, {
|
|
1174
|
+
default: () => nautobot_default
|
|
1175
|
+
});
|
|
1176
|
+
var DEVICE_USED4 = /* @__PURE__ */ new Set([
|
|
1177
|
+
"id",
|
|
1178
|
+
"name",
|
|
1179
|
+
"device_type",
|
|
1180
|
+
"platform",
|
|
1181
|
+
"role",
|
|
1182
|
+
"device_role",
|
|
1183
|
+
"location",
|
|
1184
|
+
"site",
|
|
1185
|
+
"primary_ip",
|
|
1186
|
+
"primary_ip4",
|
|
1187
|
+
"status",
|
|
1188
|
+
"url",
|
|
1189
|
+
"display",
|
|
1190
|
+
"object_type"
|
|
1191
|
+
]);
|
|
1192
|
+
var INTERFACE_USED = /* @__PURE__ */ new Set([
|
|
1193
|
+
"id",
|
|
1194
|
+
"device",
|
|
1195
|
+
"name",
|
|
1196
|
+
"description",
|
|
1197
|
+
"enabled",
|
|
1198
|
+
"speed",
|
|
1199
|
+
"mode",
|
|
1200
|
+
"untagged_vlan",
|
|
1201
|
+
"tagged_vlans",
|
|
1202
|
+
"lag",
|
|
1203
|
+
"vrf",
|
|
1204
|
+
"status",
|
|
1205
|
+
"url",
|
|
1206
|
+
"display",
|
|
1207
|
+
"type",
|
|
1208
|
+
"object_type"
|
|
1209
|
+
]);
|
|
1210
|
+
var CABLE_USED = /* @__PURE__ */ new Set([
|
|
1211
|
+
"id",
|
|
1212
|
+
"label",
|
|
1213
|
+
"status",
|
|
1214
|
+
"url",
|
|
1215
|
+
"display",
|
|
1216
|
+
"type",
|
|
1217
|
+
"object_type",
|
|
1218
|
+
"terminations",
|
|
1219
|
+
"a_terminations",
|
|
1220
|
+
"b_terminations",
|
|
1221
|
+
"termination_a",
|
|
1222
|
+
"termination_b",
|
|
1223
|
+
"termination_a_type",
|
|
1224
|
+
"termination_a_id",
|
|
1225
|
+
"termination_b_type",
|
|
1226
|
+
"termination_b_id"
|
|
1227
|
+
]);
|
|
1228
|
+
var IP_USED2 = /* @__PURE__ */ new Set([
|
|
1229
|
+
"id",
|
|
1230
|
+
"address",
|
|
1231
|
+
"ip_address",
|
|
1232
|
+
"interface",
|
|
1233
|
+
"interfaces",
|
|
1234
|
+
"vm_interface",
|
|
1235
|
+
"assigned_object_type",
|
|
1236
|
+
"assigned_object_id",
|
|
1237
|
+
"assigned_object",
|
|
1238
|
+
"object_type",
|
|
1239
|
+
"display",
|
|
1240
|
+
"url",
|
|
1241
|
+
"status"
|
|
1242
|
+
]);
|
|
1243
|
+
var VLAN_USED2 = /* @__PURE__ */ new Set(["id", "vid", "name", "display", "url", "status", "object_type"]);
|
|
1244
|
+
function bareRef(value) {
|
|
1245
|
+
if (typeof value === "number" && Number.isFinite(value)) return true;
|
|
1246
|
+
if (typeof value !== "string") return false;
|
|
1247
|
+
const text = value.trim();
|
|
1248
|
+
return /^\d+$/.test(text) || /^[0-9a-f]{8}-[0-9a-f-]{20,}$/i.test(text);
|
|
1249
|
+
}
|
|
1250
|
+
function takeSection(warnings, value, label) {
|
|
1251
|
+
const section2 = sectionList(value, ["results", label]);
|
|
1252
|
+
if (!section2.present) return null;
|
|
1253
|
+
if (section2.next) pushWarning(warnings, `/${label}`, `Ignored next page URL on ${label}. NerdGram does not fetch it.`);
|
|
1254
|
+
if (section2.bad) {
|
|
1255
|
+
pushWarning(warnings, `/${label}`, `${label} is not a list or a results envelope.`);
|
|
1256
|
+
return [];
|
|
1257
|
+
}
|
|
1258
|
+
return section2.items;
|
|
1259
|
+
}
|
|
1260
|
+
function readRoot(input, warnings) {
|
|
1261
|
+
const ipKey = ["ip-address-to-interface", "ip_address_to_interface", "ip-addresses", "ip_addresses"].find((key) => key in input);
|
|
1262
|
+
if (["devices", "interfaces", "cables", "vlans"].some((key) => key in input) || ipKey) {
|
|
1263
|
+
return {
|
|
1264
|
+
devices: takeSection(warnings, input.devices, "devices") ?? [],
|
|
1265
|
+
interfaces: takeSection(warnings, input.interfaces, "interfaces") ?? [],
|
|
1266
|
+
cables: takeSection(warnings, input.cables, "cables") ?? [],
|
|
1267
|
+
vlans: takeSection(warnings, input.vlans, "vlans") ?? [],
|
|
1268
|
+
ips: takeSection(warnings, ipKey ? input[ipKey] : void 0, ipKey ?? "ip-addresses") ?? []
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
const section2 = sectionList(input, ["results"]);
|
|
1272
|
+
if (section2.next) pushWarning(warnings, "", "Ignored next page URL. NerdGram does not fetch it.");
|
|
1273
|
+
const first = section2.items.find(isRecord);
|
|
1274
|
+
if (!first) return { devices: [], interfaces: [], cables: [], vlans: [], ips: [] };
|
|
1275
|
+
if ("termination_a" in first || "terminations" in first || "a_terminations" in first) {
|
|
1276
|
+
return { devices: [], interfaces: [], cables: section2.items, vlans: [], ips: [] };
|
|
1277
|
+
}
|
|
1278
|
+
if ("vid" in first && first.device == null) return { devices: [], interfaces: [], cables: [], vlans: section2.items, ips: [] };
|
|
1279
|
+
if (first.device != null && first.device_type == null && first.location == null && first.primary_ip4 == null) {
|
|
1280
|
+
return { devices: [], interfaces: section2.items, cables: [], vlans: [], ips: [] };
|
|
1281
|
+
}
|
|
1282
|
+
return { devices: section2.items, interfaces: [], cables: [], vlans: [], ips: [] };
|
|
1283
|
+
}
|
|
1284
|
+
function managementAddress(value, warnings, path2) {
|
|
1285
|
+
if (value == null) return "";
|
|
1286
|
+
if (bareRef(value)) {
|
|
1287
|
+
pushWarning(warnings, path2, "primary IP was not expanded, so managementIp was left empty.");
|
|
1288
|
+
return "";
|
|
1289
|
+
}
|
|
1290
|
+
if (!isRecord(value)) return "";
|
|
1291
|
+
return hostAddress(value.address);
|
|
1292
|
+
}
|
|
1293
|
+
function mapDevices3(items, warnings) {
|
|
1294
|
+
const devices = [];
|
|
1295
|
+
const ids = /* @__PURE__ */ new Map();
|
|
1296
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1297
|
+
items.forEach((item, index) => {
|
|
1298
|
+
const pointer = `/devices/${index}`;
|
|
1299
|
+
if (!isRecord(item)) {
|
|
1300
|
+
pushWarning(warnings, pointer, "Skipped a device that is not an object.");
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
noteUnmapped(warnings, pointer, item, DEVICE_USED4, "device");
|
|
1304
|
+
const name = textOf(item.name);
|
|
1305
|
+
if (!name) {
|
|
1306
|
+
pushWarning(warnings, pointer, "Skipped a device with no name.");
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
if (seen.has(name.toLowerCase())) {
|
|
1310
|
+
pushWarning(warnings, pointer, `Duplicate device "${name}" was skipped.`);
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
seen.add(name.toLowerCase());
|
|
1314
|
+
const location = nestedText(item.location, ["name", "display"]);
|
|
1315
|
+
const site = nestedText(item.site, ["name", "display"]);
|
|
1316
|
+
if (!location && site) {
|
|
1317
|
+
pushWarning(warnings, `${pointer}/site`, `Device ${name} has site and no location. site was used as the location.`);
|
|
1318
|
+
}
|
|
1319
|
+
if (bareRef(item.device_type)) {
|
|
1320
|
+
pushWarning(warnings, `${pointer}/device_type`, `Device ${name} device_type was not expanded, so model was left empty.`);
|
|
1321
|
+
}
|
|
1322
|
+
const primary = isRecord(item.primary_ip4) || bareRef(item.primary_ip4) ? item.primary_ip4 : item.primary_ip;
|
|
1323
|
+
devices.push(
|
|
1324
|
+
blankDevice(name, {
|
|
1325
|
+
model: nestedText(item.device_type, ["model", "display"]),
|
|
1326
|
+
platform: nestedText(item.platform, ["name", "display"]),
|
|
1327
|
+
role: nestedText(isRecord(item.role) ? item.role : item.device_role, ["name", "display"]),
|
|
1328
|
+
site: location || site,
|
|
1329
|
+
managementIp: managementAddress(primary, warnings, `${pointer}/primary_ip4`)
|
|
1330
|
+
})
|
|
1331
|
+
);
|
|
1332
|
+
const id = idKey(item.id);
|
|
1333
|
+
if (id) ids.set(id, name);
|
|
1334
|
+
});
|
|
1335
|
+
return { devices, ids };
|
|
1336
|
+
}
|
|
1337
|
+
function resolveDevice(value, ids) {
|
|
1338
|
+
if (isRecord(value)) {
|
|
1339
|
+
const named = textOf(value.name) || textOf(value.display);
|
|
1340
|
+
if (named) return named;
|
|
1341
|
+
const id2 = idKey(value.id);
|
|
1342
|
+
return id2 && ids.has(id2) ? ids.get(id2) ?? "" : "";
|
|
1343
|
+
}
|
|
1344
|
+
const id = idKey(value);
|
|
1345
|
+
return id && ids.has(id) ? ids.get(id) ?? "" : "";
|
|
1346
|
+
}
|
|
1347
|
+
function mapInterfaces2(items, deviceIds, warnings) {
|
|
1348
|
+
const interfaces = [];
|
|
1349
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1350
|
+
items.forEach((item, index) => {
|
|
1351
|
+
const pointer = `/interfaces/${index}`;
|
|
1352
|
+
if (!isRecord(item)) {
|
|
1353
|
+
pushWarning(warnings, pointer, "Skipped an interface that is not an object.");
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
noteUnmapped(warnings, pointer, item, INTERFACE_USED, "interface");
|
|
1357
|
+
const device = resolveDevice(item.device, deviceIds);
|
|
1358
|
+
const name = textOf(item.name);
|
|
1359
|
+
if (!device || !name) {
|
|
1360
|
+
pushWarning(warnings, pointer, "Skipped an interface with no device or name.");
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
const mode = textOf(item.mode).toLowerCase();
|
|
1364
|
+
const untagged = vlanId(isRecord(item.untagged_vlan) ? item.untagged_vlan.vid : void 0);
|
|
1365
|
+
let switchportMode = "";
|
|
1366
|
+
let accessVlan = null;
|
|
1367
|
+
let nativeVlan = null;
|
|
1368
|
+
let trunkVlans = null;
|
|
1369
|
+
if (mode === "access") {
|
|
1370
|
+
switchportMode = "access";
|
|
1371
|
+
accessVlan = untagged;
|
|
1372
|
+
} else if (mode === "tagged" || mode === "tagged-all") {
|
|
1373
|
+
switchportMode = "trunk";
|
|
1374
|
+
nativeVlan = untagged;
|
|
1375
|
+
trunkVlans = [];
|
|
1376
|
+
if (Array.isArray(item.tagged_vlans)) {
|
|
1377
|
+
for (const vlan of item.tagged_vlans) {
|
|
1378
|
+
const id2 = vlanId(isRecord(vlan) ? vlan.vid : void 0);
|
|
1379
|
+
if (id2 != null && !trunkVlans.includes(id2)) trunkVlans.push(id2);
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
if (mode === "tagged-all" && trunkVlans.length === 0) {
|
|
1383
|
+
pushWarning(warnings, pointer, `Interface ${name} is tagged-all with no VLAN ids.`);
|
|
1384
|
+
}
|
|
1385
|
+
} else if (mode && mode !== "q-in-q") {
|
|
1386
|
+
pushWarning(warnings, `${pointer}/mode`, `Interface mode "${mode}" was not mapped.`);
|
|
1387
|
+
} else if (mode === "q-in-q") {
|
|
1388
|
+
pushWarning(warnings, `${pointer}/mode`, "q-in-q was not mapped.");
|
|
1389
|
+
}
|
|
1390
|
+
const admin = statusUpDown(item.enabled);
|
|
1391
|
+
const speed = formatRate(typeof item.speed === "number" ? item.speed : Number(textOf(item.speed)), "kbps");
|
|
1392
|
+
interfaces.push(
|
|
1393
|
+
blankInterface(device, name, {
|
|
1394
|
+
description: textOf(item.description),
|
|
1395
|
+
speed,
|
|
1396
|
+
adminStatus: admin === "up" || admin === "down" ? admin : "",
|
|
1397
|
+
vrf: nestedText(item.vrf, ["name", "display"]),
|
|
1398
|
+
switchportMode,
|
|
1399
|
+
accessVlan,
|
|
1400
|
+
nativeVlan,
|
|
1401
|
+
trunkVlans,
|
|
1402
|
+
lag: nestedText(item.lag, ["name", "display"])
|
|
1403
|
+
})
|
|
1404
|
+
);
|
|
1405
|
+
const id = idKey(item.id);
|
|
1406
|
+
if (id) byId.set(id, { device, name });
|
|
1407
|
+
});
|
|
1408
|
+
return { interfaces, byId };
|
|
1409
|
+
}
|
|
1410
|
+
function addressText(value) {
|
|
1411
|
+
if (typeof value === "string") return value;
|
|
1412
|
+
if (!isRecord(value)) return "";
|
|
1413
|
+
return textOf(value.address) || textOf(value.display).split(/\s+/)[0] || "";
|
|
1414
|
+
}
|
|
1415
|
+
function assignAddresses2(items, interfaces, byId, warnings) {
|
|
1416
|
+
items.forEach((item, index) => {
|
|
1417
|
+
const pointer = `/ip-addresses/${index}`;
|
|
1418
|
+
if (!isRecord(item)) return;
|
|
1419
|
+
noteUnmapped(warnings, pointer, item, IP_USED2, "address");
|
|
1420
|
+
const cidr = splitCidr(addressText(item.address) || addressText(item.ip_address) || addressText(item));
|
|
1421
|
+
if (!cidr) {
|
|
1422
|
+
if (bareRef(item.ip_address) || bareRef(item.address)) {
|
|
1423
|
+
pushWarning(warnings, pointer, "IP address was not expanded, so it was skipped.");
|
|
1424
|
+
}
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
const targets = [];
|
|
1428
|
+
const iface = isRecord(item.interface) ? item.interface : item.assigned_object;
|
|
1429
|
+
const direct = byId.get(idKey(isRecord(iface) ? iface.id : iface)) ?? byId.get(idKey(item.assigned_object_id));
|
|
1430
|
+
if (direct) targets.push(direct);
|
|
1431
|
+
if (Array.isArray(item.interfaces)) {
|
|
1432
|
+
for (const entry of item.interfaces) {
|
|
1433
|
+
const ref = byId.get(idKey(isRecord(entry) ? entry.id : entry));
|
|
1434
|
+
if (ref) targets.push(ref);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
if (targets.length === 0) {
|
|
1438
|
+
pushWarning(warnings, pointer, "IP address did not name an interface in this export, so it was skipped.");
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
const stored = { address: cidr.address, prefix: cidr.prefix };
|
|
1442
|
+
for (const target of targets) {
|
|
1443
|
+
const row = interfaces.find((entry) => entry.device === target.device && entry.name === target.name);
|
|
1444
|
+
if (!row) continue;
|
|
1445
|
+
const list = cidr.family === "ipv4" ? row.ipv4 : row.ipv6;
|
|
1446
|
+
if (!list.some((entry) => entry.address === stored.address && entry.prefix === stored.prefix)) list.push(stored);
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
function slots(value) {
|
|
1451
|
+
if (value == null) return [];
|
|
1452
|
+
if (Array.isArray(value)) return value.filter((item) => item != null);
|
|
1453
|
+
if (!isRecord(value)) return [value];
|
|
1454
|
+
return Object.values(value).filter((item) => item != null);
|
|
1455
|
+
}
|
|
1456
|
+
function cableSides(row) {
|
|
1457
|
+
if ("a_terminations" in row || "b_terminations" in row) {
|
|
1458
|
+
return { a: slots(row.a_terminations), b: slots(row.b_terminations) };
|
|
1459
|
+
}
|
|
1460
|
+
if (isRecord(row.terminations)) {
|
|
1461
|
+
return { a: slots(row.terminations.a), b: slots(row.terminations.b) };
|
|
1462
|
+
}
|
|
1463
|
+
return { a: slots(row.termination_a), b: slots(row.termination_b) };
|
|
1464
|
+
}
|
|
1465
|
+
function endRef(item, byId) {
|
|
1466
|
+
if (!isRecord(item)) return null;
|
|
1467
|
+
const type = textOf(item.object_type) || textOf(item.termination_type);
|
|
1468
|
+
if (type && type !== "dcim.interface") return "other";
|
|
1469
|
+
const object = isRecord(item.object) ? item.object : isRecord(item.interface) ? item.interface : item;
|
|
1470
|
+
const nested = byId.get(idKey(object.id)) ?? byId.get(idKey(item.object_id)) ?? byId.get(idKey(item.id));
|
|
1471
|
+
if (nested && (type === "dcim.interface" || !type)) return nested;
|
|
1472
|
+
const device = nestedText(isRecord(object.device) ? object.device : item.device, ["name", "display"]);
|
|
1473
|
+
const name = textOf(object.name);
|
|
1474
|
+
if (device && name && (!type || type === "dcim.interface")) return { device, name };
|
|
1475
|
+
if (type && type !== "dcim.interface") return "other";
|
|
1476
|
+
return null;
|
|
1477
|
+
}
|
|
1478
|
+
function mapCables(items, byId, warnings) {
|
|
1479
|
+
const links = [];
|
|
1480
|
+
items.forEach((item, index) => {
|
|
1481
|
+
const pointer = `/cables/${index}`;
|
|
1482
|
+
if (!isRecord(item)) return;
|
|
1483
|
+
noteUnmapped(warnings, pointer, item, CABLE_USED, "cable");
|
|
1484
|
+
const sides = cableSides(item);
|
|
1485
|
+
const ends = [sides.a, sides.b].map((side) => side.map((entry) => endRef(entry, byId)));
|
|
1486
|
+
if (ends.some((side) => side.includes("other"))) return;
|
|
1487
|
+
const [left, right] = ends.map((side) => side.filter((entry) => entry != null && entry !== "other"));
|
|
1488
|
+
if (!left || !right || left.length !== 1 || right.length !== 1) {
|
|
1489
|
+
pushWarning(warnings, pointer, "Cable was skipped because both ends are not a single interface.");
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
const a = left[0];
|
|
1493
|
+
const b = right[0];
|
|
1494
|
+
if (!a || !b) return;
|
|
1495
|
+
links.push(blankLink(a.device, a.name, b.device, b.name, textOf(item.label)));
|
|
1496
|
+
});
|
|
1497
|
+
return dedupeLinks(links);
|
|
1498
|
+
}
|
|
1499
|
+
function mapVlans2(items, warnings) {
|
|
1500
|
+
const vlans = [];
|
|
1501
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1502
|
+
items.forEach((item, index) => {
|
|
1503
|
+
if (!isRecord(item)) return;
|
|
1504
|
+
noteUnmapped(warnings, `/vlans/${index}`, item, VLAN_USED2, "VLAN");
|
|
1505
|
+
const id = vlanId(item.vid);
|
|
1506
|
+
if (id == null || seen.has(id)) return;
|
|
1507
|
+
seen.add(id);
|
|
1508
|
+
vlans.push({ id, name: textOf(item.name) });
|
|
1509
|
+
});
|
|
1510
|
+
return vlans;
|
|
1511
|
+
}
|
|
1512
|
+
function convertNautobot(input) {
|
|
1513
|
+
if (!isRecord(input)) throw translatorFail(400, "A Nautobot export must be a JSON object.");
|
|
1514
|
+
const warnings = [];
|
|
1515
|
+
const root = readRoot(input, warnings);
|
|
1516
|
+
const mapped = mapDevices3(root.devices, warnings);
|
|
1517
|
+
const ports = mapInterfaces2(root.interfaces, mapped.ids, warnings);
|
|
1518
|
+
assignAddresses2(root.ips, ports.interfaces, ports.byId, warnings);
|
|
1519
|
+
const links = mapCables(root.cables, ports.byId, warnings);
|
|
1520
|
+
ensureLinkEnds(mapped.devices, ports.interfaces, links);
|
|
1521
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
1522
|
+
return {
|
|
1523
|
+
document: publishDocument({ devices: mapped.devices, interfaces: ports.interfaces, links, vlans: mapVlans2(root.vlans, warnings) }),
|
|
1524
|
+
warnings: sortWarnings(warnings)
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
var nautobot = {
|
|
1528
|
+
id: "nautobot",
|
|
1529
|
+
name: "Nautobot",
|
|
1530
|
+
formatHint: "Saved Nautobot REST export (devices, interfaces, cables)",
|
|
1531
|
+
placeholder: `{
|
|
1532
|
+
"devices": { "results": [ { "name": "core-rtr", "location": { "name": "hq" } } ] },
|
|
1533
|
+
"interfaces": { "results": [] },
|
|
1534
|
+
"cables": { "results": [] }
|
|
1535
|
+
}`,
|
|
1536
|
+
convert: convertNautobot
|
|
1537
|
+
};
|
|
1538
|
+
var nautobot_default = nautobot;
|
|
1539
|
+
|
|
1540
|
+
// server/src/translators/netbox.ts
|
|
1541
|
+
var netbox_exports = {};
|
|
1542
|
+
__export(netbox_exports, {
|
|
1543
|
+
default: () => netbox_default
|
|
1544
|
+
});
|
|
1545
|
+
var DEVICE_USED5 = /* @__PURE__ */ new Set(["id", "name", "device_type", "platform", "role", "device_role", "site", "primary_ip", "primary_ip4"]);
|
|
1546
|
+
var INTERFACE_USED2 = /* @__PURE__ */ new Set(["id", "device", "name", "description", "enabled", "speed", "mode", "untagged_vlan", "tagged_vlans", "lag", "vrf"]);
|
|
1547
|
+
var CABLE_USED2 = /* @__PURE__ */ new Set([
|
|
1548
|
+
"id",
|
|
1549
|
+
"label",
|
|
1550
|
+
"a_terminations",
|
|
1551
|
+
"b_terminations",
|
|
1552
|
+
"termination_a_type",
|
|
1553
|
+
"termination_a_id",
|
|
1554
|
+
"termination_a",
|
|
1555
|
+
"termination_b_type",
|
|
1556
|
+
"termination_b_id",
|
|
1557
|
+
"termination_b"
|
|
1558
|
+
]);
|
|
1559
|
+
var IP_USED3 = /* @__PURE__ */ new Set(["id", "address", "vrf", "assigned_object_type", "assigned_object_id", "assigned_object", "family"]);
|
|
1560
|
+
var VLAN_USED3 = /* @__PURE__ */ new Set(["id", "vid", "name", "display"]);
|
|
1561
|
+
var RESOURCE_KEYS = ["devices", "interfaces", "cables", "vlans", "ip-addresses", "ip_addresses"];
|
|
1562
|
+
function classifyRow(row) {
|
|
1563
|
+
if ("a_terminations" in row || "b_terminations" in row || "termination_a" in row || "termination_b" in row || "termination_a_type" in row || "termination_b_type" in row) {
|
|
1564
|
+
return "cables";
|
|
1565
|
+
}
|
|
1566
|
+
if (row.assigned_object_type != null || typeof row.address === "string" && "assigned_object_id" in row) return "ips";
|
|
1567
|
+
if ("vid" in row && row.device == null && row.device_type == null) return "vlans";
|
|
1568
|
+
if (row.device != null && row.device_type == null && row.primary_ip == null && row.primary_ip4 == null) return "interfaces";
|
|
1569
|
+
if (row.device_type != null || row.device_role != null || row.role != null || row.primary_ip != null || row.primary_ip4 != null || row.site != null || typeof row.name === "string") {
|
|
1570
|
+
return "devices";
|
|
1571
|
+
}
|
|
1572
|
+
return "unknown";
|
|
1573
|
+
}
|
|
1574
|
+
function takeSection2(warnings, value, label) {
|
|
1575
|
+
const section2 = sectionList(value, ["results", label, "ip_addresses", "ip-addresses"]);
|
|
1576
|
+
if (!section2.present) return null;
|
|
1577
|
+
if (section2.next) pushWarning(warnings, `/${label}`, `Ignored next page URL on ${label}. NerdGram does not fetch it.`);
|
|
1578
|
+
if (section2.bad) {
|
|
1579
|
+
pushWarning(warnings, `/${label}`, `${label} is not a list or a NetBox results envelope.`);
|
|
1580
|
+
return [];
|
|
1581
|
+
}
|
|
1582
|
+
return section2.items;
|
|
1583
|
+
}
|
|
1584
|
+
function readBuckets(input, warnings) {
|
|
1585
|
+
const buckets = { devices: [], interfaces: [], cables: [], vlans: [], ips: [] };
|
|
1586
|
+
if (RESOURCE_KEYS.some((key) => key in input)) {
|
|
1587
|
+
buckets.devices = takeSection2(warnings, input.devices, "devices") ?? [];
|
|
1588
|
+
buckets.interfaces = takeSection2(warnings, input.interfaces, "interfaces") ?? [];
|
|
1589
|
+
buckets.cables = takeSection2(warnings, input.cables, "cables") ?? [];
|
|
1590
|
+
buckets.vlans = takeSection2(warnings, input.vlans, "vlans") ?? [];
|
|
1591
|
+
buckets.ips = takeSection2(warnings, input["ip-addresses"] ?? input.ip_addresses, "ip-addresses") ?? [];
|
|
1592
|
+
if ("results" in input) pushWarning(warnings, "/results", "Top-level results were ignored because the export names its resources.");
|
|
1593
|
+
return buckets;
|
|
1594
|
+
}
|
|
1595
|
+
const section2 = sectionList(input, ["results"]);
|
|
1596
|
+
if (section2.next) pushWarning(warnings, "", "Ignored next page URL. NerdGram does not fetch it.");
|
|
1597
|
+
const first = section2.items.find(isRecord);
|
|
1598
|
+
if (!first) {
|
|
1599
|
+
pushWarning(warnings, "", "This export has no devices, interfaces, or cables.");
|
|
1600
|
+
return buckets;
|
|
1601
|
+
}
|
|
1602
|
+
const kind = classifyRow(first);
|
|
1603
|
+
if (kind === "unknown") {
|
|
1604
|
+
pushWarning(warnings, "/results", "This results list is not devices, interfaces, cables, addresses, or VLANs.");
|
|
1605
|
+
return buckets;
|
|
1606
|
+
}
|
|
1607
|
+
buckets[kind] = section2.items;
|
|
1608
|
+
return buckets;
|
|
1609
|
+
}
|
|
1610
|
+
function managementAddress2(value, warnings, path2, label) {
|
|
1611
|
+
if (value == null) return "";
|
|
1612
|
+
if (collapsedRef(value)) {
|
|
1613
|
+
pushWarning(warnings, path2, `${label} was not expanded, so managementIp was left empty.`);
|
|
1614
|
+
return "";
|
|
1615
|
+
}
|
|
1616
|
+
if (!isRecord(value)) return "";
|
|
1617
|
+
const address = hostAddress(value.address);
|
|
1618
|
+
if (!address && textOf(value.address)) pushWarning(warnings, path2, `${label} address is not an IP, so managementIp was left empty.`);
|
|
1619
|
+
return address;
|
|
1620
|
+
}
|
|
1621
|
+
function mapDevices4(items, warnings) {
|
|
1622
|
+
const devices = [];
|
|
1623
|
+
const ids = /* @__PURE__ */ new Map();
|
|
1624
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1625
|
+
items.forEach((item, index) => {
|
|
1626
|
+
const pointer = `/devices/${index}`;
|
|
1627
|
+
if (!isRecord(item)) {
|
|
1628
|
+
pushWarning(warnings, pointer, "Skipped a device that is not an object.");
|
|
1629
|
+
return;
|
|
1630
|
+
}
|
|
1631
|
+
noteUnmapped(warnings, pointer, item, DEVICE_USED5, "device");
|
|
1632
|
+
const name = textOf(item.name);
|
|
1633
|
+
if (!name) {
|
|
1634
|
+
pushWarning(warnings, pointer, "Skipped a device with no name.");
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
if (seen.has(name.toLowerCase())) {
|
|
1638
|
+
pushWarning(warnings, pointer, `Duplicate device "${name}" was skipped.`);
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
seen.add(name.toLowerCase());
|
|
1642
|
+
if (collapsedRef(item.device_type)) {
|
|
1643
|
+
pushWarning(warnings, `${pointer}/device_type`, `Device ${name} device_type was not expanded, so model was left empty.`);
|
|
1644
|
+
}
|
|
1645
|
+
const roleRecord = isRecord(item.role) ? item.role : isRecord(item.device_role) ? item.device_role : null;
|
|
1646
|
+
if (!roleRecord && (collapsedRef(item.role) || collapsedRef(item.device_role))) {
|
|
1647
|
+
pushWarning(warnings, `${pointer}/role`, `Device ${name} role was not expanded, so role was left empty.`);
|
|
1648
|
+
}
|
|
1649
|
+
const primaryRecord = isRecord(item.primary_ip4) || collapsedRef(item.primary_ip4) ? item.primary_ip4 : item.primary_ip;
|
|
1650
|
+
const primaryLabel = isRecord(item.primary_ip4) || collapsedRef(item.primary_ip4) ? "primary_ip4" : "primary_ip";
|
|
1651
|
+
devices.push(
|
|
1652
|
+
blankDevice(name, {
|
|
1653
|
+
model: nestedText(item.device_type, ["model", "display"]),
|
|
1654
|
+
platform: nestedText(item.platform, ["name", "display"]),
|
|
1655
|
+
role: nestedText(roleRecord, ["name", "display"]),
|
|
1656
|
+
site: nestedText(item.site, ["name", "display"]),
|
|
1657
|
+
managementIp: managementAddress2(primaryRecord, warnings, `${pointer}/${primaryLabel}`, primaryLabel)
|
|
1658
|
+
})
|
|
1659
|
+
);
|
|
1660
|
+
const id = idKey(item.id);
|
|
1661
|
+
if (id) ids.set(id, name);
|
|
1662
|
+
});
|
|
1663
|
+
return { devices, ids };
|
|
1664
|
+
}
|
|
1665
|
+
function resolveDevice2(value, names, ids) {
|
|
1666
|
+
if (isRecord(value)) {
|
|
1667
|
+
const named = textOf(value.name) || textOf(value.display);
|
|
1668
|
+
if (named && names.has(named.toLowerCase())) return names.get(named.toLowerCase()) ?? "";
|
|
1669
|
+
const id2 = idKey(value.id);
|
|
1670
|
+
if (id2 && ids.has(id2)) return ids.get(id2) ?? "";
|
|
1671
|
+
return named;
|
|
1672
|
+
}
|
|
1673
|
+
const id = idKey(value);
|
|
1674
|
+
return id && ids.has(id) ? ids.get(id) ?? "" : "";
|
|
1675
|
+
}
|
|
1676
|
+
function taggedVlans(value, warnings, pointer) {
|
|
1677
|
+
if (value == null) return null;
|
|
1678
|
+
if (!Array.isArray(value)) {
|
|
1679
|
+
pushWarning(warnings, `${pointer}/tagged_vlans`, "tagged_vlans is not a list, so trunk VLANs were left empty.");
|
|
1680
|
+
return null;
|
|
1681
|
+
}
|
|
1682
|
+
const ids = [];
|
|
1683
|
+
let collapsed = false;
|
|
1684
|
+
for (const item of value) {
|
|
1685
|
+
if (collapsedRef(item)) {
|
|
1686
|
+
collapsed = true;
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
const id = vlanId(isRecord(item) ? item.vid : void 0);
|
|
1690
|
+
if (id != null && !ids.includes(id)) ids.push(id);
|
|
1691
|
+
}
|
|
1692
|
+
if (collapsed) pushWarning(warnings, `${pointer}/tagged_vlans`, "A tagged VLAN was not expanded, so that id was skipped.");
|
|
1693
|
+
return ids;
|
|
1694
|
+
}
|
|
1695
|
+
function mapInterfaces3(items, devices, deviceIds, warnings) {
|
|
1696
|
+
const names = new Map(devices.map((device) => [device.name.toLowerCase(), device.name]));
|
|
1697
|
+
const interfaces = [];
|
|
1698
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1699
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1700
|
+
items.forEach((item, index) => {
|
|
1701
|
+
const pointer = `/interfaces/${index}`;
|
|
1702
|
+
if (!isRecord(item)) {
|
|
1703
|
+
pushWarning(warnings, pointer, "Skipped an interface that is not an object.");
|
|
1704
|
+
return;
|
|
1705
|
+
}
|
|
1706
|
+
noteUnmapped(warnings, pointer, item, INTERFACE_USED2, "interface");
|
|
1707
|
+
const name = textOf(item.name);
|
|
1708
|
+
if (collapsedRef(item.device)) {
|
|
1709
|
+
pushWarning(warnings, `${pointer}/device`, `Interface ${name || String(index + 1)} device was not expanded, so the interface was skipped.`);
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const device = resolveDevice2(item.device, names, deviceIds);
|
|
1713
|
+
if (!device || !name || !names.has(device.toLowerCase())) {
|
|
1714
|
+
pushWarning(warnings, pointer, `Skipped interface ${name || String(index + 1)} because its device is not in this export.`);
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
const kept = names.get(device.toLowerCase()) ?? device;
|
|
1718
|
+
const pair = `${kept.toLowerCase()}\0${name}`;
|
|
1719
|
+
if (seen.has(pair)) {
|
|
1720
|
+
pushWarning(warnings, pointer, `Duplicate interface ${kept} ${name} was skipped.`);
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
seen.add(pair);
|
|
1724
|
+
const mode = textOf(item.mode);
|
|
1725
|
+
let switchportMode = "";
|
|
1726
|
+
let accessVlan = null;
|
|
1727
|
+
let nativeVlan = null;
|
|
1728
|
+
let trunkVlans = null;
|
|
1729
|
+
const untagged = vlanId(isRecord(item.untagged_vlan) ? item.untagged_vlan.vid : void 0);
|
|
1730
|
+
if (mode === "access") {
|
|
1731
|
+
switchportMode = "access";
|
|
1732
|
+
accessVlan = untagged;
|
|
1733
|
+
} else if (mode === "tagged" || mode === "tagged-all") {
|
|
1734
|
+
switchportMode = "trunk";
|
|
1735
|
+
nativeVlan = untagged;
|
|
1736
|
+
trunkVlans = taggedVlans(item.tagged_vlans, warnings, pointer);
|
|
1737
|
+
if (mode === "tagged-all" && (trunkVlans == null || trunkVlans.length === 0)) {
|
|
1738
|
+
pushWarning(warnings, pointer, `Interface ${kept} ${name} is tagged-all and lists no VLAN ids, so trunkVlans was left empty.`);
|
|
1739
|
+
trunkVlans = [];
|
|
1740
|
+
}
|
|
1741
|
+
} else if (mode) {
|
|
1742
|
+
pushWarning(warnings, `${pointer}/mode`, `Interface ${kept} ${name} mode "${mode}" is not mapped, so switchport mode was left empty.`);
|
|
1743
|
+
}
|
|
1744
|
+
let speed = "";
|
|
1745
|
+
if (item.speed != null && item.speed !== "") {
|
|
1746
|
+
const parsed = typeof item.speed === "number" ? item.speed : Number(textOf(item.speed));
|
|
1747
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
1748
|
+
pushWarning(warnings, `${pointer}/speed`, `Interface ${kept} ${name} speed is not a number, so speed was left empty.`);
|
|
1749
|
+
} else speed = formatRate(parsed, "kbps");
|
|
1750
|
+
}
|
|
1751
|
+
interfaces.push(
|
|
1752
|
+
blankInterface(kept, name, {
|
|
1753
|
+
description: textOf(item.description),
|
|
1754
|
+
speed,
|
|
1755
|
+
adminStatus: item.enabled === true ? "up" : item.enabled === false ? "down" : "",
|
|
1756
|
+
vrf: nestedText(item.vrf, ["name", "display"]),
|
|
1757
|
+
switchportMode,
|
|
1758
|
+
accessVlan,
|
|
1759
|
+
nativeVlan,
|
|
1760
|
+
trunkVlans,
|
|
1761
|
+
lag: nestedText(item.lag, ["name", "display"])
|
|
1762
|
+
})
|
|
1763
|
+
);
|
|
1764
|
+
const id = idKey(item.id);
|
|
1765
|
+
if (id) byId.set(id, { device: kept, name });
|
|
1766
|
+
});
|
|
1767
|
+
return { interfaces, byId };
|
|
1768
|
+
}
|
|
1769
|
+
function mapVlans3(items, warnings) {
|
|
1770
|
+
const vlans = [];
|
|
1771
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1772
|
+
items.forEach((item, index) => {
|
|
1773
|
+
const pointer = `/vlans/${index}`;
|
|
1774
|
+
if (!isRecord(item)) {
|
|
1775
|
+
pushWarning(warnings, pointer, "Skipped a VLAN that is not an object.");
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
noteUnmapped(warnings, pointer, item, VLAN_USED3, "VLAN");
|
|
1779
|
+
const id = vlanId(item.vid);
|
|
1780
|
+
if (id == null) {
|
|
1781
|
+
pushWarning(warnings, pointer, "Skipped a VLAN with no vid from 1 to 4094.");
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
if (seen.has(id)) {
|
|
1785
|
+
pushWarning(warnings, pointer, `Duplicate VLAN ${id} was skipped.`);
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
seen.add(id);
|
|
1789
|
+
vlans.push({ id, name: textOf(item.name) });
|
|
1790
|
+
});
|
|
1791
|
+
return vlans;
|
|
1792
|
+
}
|
|
1793
|
+
function assignAddresses3(items, interfaces, byId, warnings) {
|
|
1794
|
+
const byPair = new Map(interfaces.map((item) => [`${item.device.toLowerCase()}\0${item.name}`, item]));
|
|
1795
|
+
let skipped = 0;
|
|
1796
|
+
items.forEach((item, index) => {
|
|
1797
|
+
if (!isRecord(item)) {
|
|
1798
|
+
skipped += 1;
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
noteUnmapped(warnings, `/ip-addresses/${index}`, item, IP_USED3, "IP address");
|
|
1802
|
+
const type = textOf(item.assigned_object_type);
|
|
1803
|
+
if (type && type !== "dcim.interface") {
|
|
1804
|
+
skipped += 1;
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
let ref = byId.get(idKey(item.assigned_object_id));
|
|
1808
|
+
if (!ref && isRecord(item.assigned_object)) {
|
|
1809
|
+
const device = nestedText(item.assigned_object.device, ["name", "display"]);
|
|
1810
|
+
const name = textOf(item.assigned_object.name);
|
|
1811
|
+
if (device && name) ref = { device, name };
|
|
1812
|
+
}
|
|
1813
|
+
const iface = ref ? byPair.get(`${ref.device.toLowerCase()}\0${ref.name}`) : void 0;
|
|
1814
|
+
if (!iface) {
|
|
1815
|
+
skipped += 1;
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
const parsed = splitCidr(textOf(item.address));
|
|
1819
|
+
if (!parsed) {
|
|
1820
|
+
if (textOf(item.address)) pushWarning(warnings, `/ip-addresses/${index}`, `IP address "${textOf(item.address)}" is not a CIDR, so it was skipped.`);
|
|
1821
|
+
return;
|
|
1822
|
+
}
|
|
1823
|
+
const list = parsed.family === "ipv4" ? iface.ipv4 : iface.ipv6;
|
|
1824
|
+
if (!list.some((address) => address.address === parsed.address && address.prefix === parsed.prefix)) {
|
|
1825
|
+
list.push({ address: parsed.address, prefix: parsed.prefix });
|
|
1826
|
+
}
|
|
1827
|
+
if (!iface.vrf) {
|
|
1828
|
+
const vrf = nestedText(item.vrf, ["name", "display"]);
|
|
1829
|
+
if (vrf) iface.vrf = vrf;
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
if (skipped > 0) {
|
|
1833
|
+
pushWarning(warnings, "/ip-addresses", `Ignored ${plural(skipped, "IP address")} that ${skipped === 1 ? "is" : "are"} not assigned to an interface in this export.`);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
function endsFrom(value, byId) {
|
|
1837
|
+
if (!Array.isArray(value)) return [];
|
|
1838
|
+
const ends = [];
|
|
1839
|
+
for (const item of value) {
|
|
1840
|
+
if (!isRecord(item)) continue;
|
|
1841
|
+
const type = textOf(item.object_type);
|
|
1842
|
+
if (type && type !== "dcim.interface") continue;
|
|
1843
|
+
const known = byId.get(idKey(item.object_id));
|
|
1844
|
+
if (known) {
|
|
1845
|
+
ends.push(known);
|
|
1846
|
+
continue;
|
|
1847
|
+
}
|
|
1848
|
+
const object = isRecord(item.object) ? item.object : null;
|
|
1849
|
+
const device = object ? nestedText(object.device, ["name", "display"]) : "";
|
|
1850
|
+
const name = object ? textOf(object.name) || textOf(object.display) : "";
|
|
1851
|
+
if (device && name) ends.push({ device, name });
|
|
1852
|
+
}
|
|
1853
|
+
return ends;
|
|
1854
|
+
}
|
|
1855
|
+
function legacyEnd(record, side, byId) {
|
|
1856
|
+
const type = textOf(record[`termination_${side}_type`]);
|
|
1857
|
+
if (type && type !== "dcim.interface") return [];
|
|
1858
|
+
const known = byId.get(idKey(record[`termination_${side}_id`]));
|
|
1859
|
+
if (known) return [known];
|
|
1860
|
+
const nested = record[`termination_${side}`];
|
|
1861
|
+
if (!isRecord(nested)) return [];
|
|
1862
|
+
const device = nestedText(nested.device, ["name", "display"]);
|
|
1863
|
+
const name = textOf(nested.name) || textOf(nested.display);
|
|
1864
|
+
return device && name ? [{ device, name }] : [];
|
|
1865
|
+
}
|
|
1866
|
+
function mapCables2(items, byId, devices, warnings) {
|
|
1867
|
+
const names = new Map(devices.map((device) => [device.name.toLowerCase(), device.name]));
|
|
1868
|
+
const links = [];
|
|
1869
|
+
let ignored = 0;
|
|
1870
|
+
items.forEach((item, index) => {
|
|
1871
|
+
const pointer = `/cables/${index}`;
|
|
1872
|
+
if (!isRecord(item)) {
|
|
1873
|
+
ignored += 1;
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
noteUnmapped(warnings, pointer, item, CABLE_USED2, "cable");
|
|
1877
|
+
const modern = "a_terminations" in item || "b_terminations" in item;
|
|
1878
|
+
const a = modern ? endsFrom(item.a_terminations, byId) : legacyEnd(item, "a", byId);
|
|
1879
|
+
const b = modern ? endsFrom(item.b_terminations, byId) : legacyEnd(item, "b", byId);
|
|
1880
|
+
if (a.length !== 1 || b.length !== 1) {
|
|
1881
|
+
ignored += 1;
|
|
1882
|
+
if (a.length > 1 || b.length > 1) {
|
|
1883
|
+
pushWarning(warnings, pointer, `Cable ${index + 1} has more than one interface on a side, so no link was created.`);
|
|
1884
|
+
}
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const aDevice = names.get(a[0].device.toLowerCase());
|
|
1888
|
+
const bDevice = names.get(b[0].device.toLowerCase());
|
|
1889
|
+
if (!aDevice || !bDevice) {
|
|
1890
|
+
ignored += 1;
|
|
1891
|
+
pushWarning(warnings, pointer, `Cable ${index + 1} was skipped because an end is not a device in this export.`);
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
links.push(blankLink(aDevice, a[0].name, bDevice, b[0].name, textOf(item.label)));
|
|
1895
|
+
});
|
|
1896
|
+
if (ignored > 0) {
|
|
1897
|
+
pushWarning(warnings, "/cables", `Ignored ${plural(ignored, "cable")} that ${ignored === 1 ? "does" : "do"} not connect two interfaces.`);
|
|
1898
|
+
}
|
|
1899
|
+
return dedupeLinks(links);
|
|
1900
|
+
}
|
|
1901
|
+
function convertNetBox(input) {
|
|
1902
|
+
if (!isRecord(input)) throw translatorFail(400, "A NetBox export must be a JSON object.");
|
|
1903
|
+
const warnings = [];
|
|
1904
|
+
const buckets = readBuckets(input, warnings);
|
|
1905
|
+
const mappedDevices = mapDevices4(buckets.devices, warnings);
|
|
1906
|
+
const mapped = mapInterfaces3(buckets.interfaces, mappedDevices.devices, mappedDevices.ids, warnings);
|
|
1907
|
+
assignAddresses3(buckets.ips, mapped.interfaces, mapped.byId, warnings);
|
|
1908
|
+
const links = mapCables2(buckets.cables, mapped.byId, mappedDevices.devices, warnings);
|
|
1909
|
+
if (mappedDevices.devices.length > 0 && mapped.interfaces.length === 0) pushWarning(warnings, "", "No interfaces in this export.");
|
|
1910
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
1911
|
+
return {
|
|
1912
|
+
document: publishDocument({
|
|
1913
|
+
devices: mappedDevices.devices,
|
|
1914
|
+
interfaces: mapped.interfaces,
|
|
1915
|
+
links,
|
|
1916
|
+
vlans: mapVlans3(buckets.vlans, warnings)
|
|
1917
|
+
}),
|
|
1918
|
+
warnings: sortWarnings(warnings)
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
var netbox = {
|
|
1922
|
+
id: "netbox",
|
|
1923
|
+
name: "NetBox",
|
|
1924
|
+
formatHint: "Saved NetBox REST export (devices, interfaces, cables)",
|
|
1925
|
+
placeholder: `{
|
|
1926
|
+
"devices": { "count": 1, "results": [ { "name": "core-rtr" } ] },
|
|
1927
|
+
"interfaces": { "count": 0, "results": [] },
|
|
1928
|
+
"cables": { "count": 0, "results": [] }
|
|
1929
|
+
}`,
|
|
1930
|
+
convert: convertNetBox
|
|
1931
|
+
};
|
|
1932
|
+
var netbox_default = netbox;
|
|
1933
|
+
|
|
1934
|
+
// server/src/translators/netdisco.ts
|
|
1935
|
+
var netdisco_exports = {};
|
|
1936
|
+
__export(netdisco_exports, {
|
|
1937
|
+
default: () => netdisco_default
|
|
1938
|
+
});
|
|
1939
|
+
var DEVICE_USED6 = /* @__PURE__ */ new Set(["ip", "dns", "name", "model", "vendor", "os", "location", "description", "serial"]);
|
|
1940
|
+
var PORT_USED3 = /* @__PURE__ */ new Set([
|
|
1941
|
+
"ip",
|
|
1942
|
+
"port",
|
|
1943
|
+
"descr",
|
|
1944
|
+
"name",
|
|
1945
|
+
"speed",
|
|
1946
|
+
"vlan",
|
|
1947
|
+
"remote_ip",
|
|
1948
|
+
"remote_port",
|
|
1949
|
+
"remote_id",
|
|
1950
|
+
"remote_type",
|
|
1951
|
+
"remote_name",
|
|
1952
|
+
"is_uplink"
|
|
1953
|
+
]);
|
|
1954
|
+
var NEIGHBOR_USED = /* @__PURE__ */ new Set([
|
|
1955
|
+
"ip",
|
|
1956
|
+
"port",
|
|
1957
|
+
"remote_ip",
|
|
1958
|
+
"remote_port",
|
|
1959
|
+
"remote_id",
|
|
1960
|
+
"remote_name",
|
|
1961
|
+
"remote_dns",
|
|
1962
|
+
"remote_type",
|
|
1963
|
+
"local_ip",
|
|
1964
|
+
"local_port"
|
|
1965
|
+
]);
|
|
1966
|
+
function rows2(warnings, value, label) {
|
|
1967
|
+
const section2 = sectionList(value, [label, "results"]);
|
|
1968
|
+
if (!section2.present) return [];
|
|
1969
|
+
if (section2.next) pushWarning(warnings, `/${label}`, `Ignored next page URL on ${label}. NerdGram does not fetch it.`);
|
|
1970
|
+
if (section2.bad) {
|
|
1971
|
+
pushWarning(warnings, `/${label}`, `${label} is not a list.`);
|
|
1972
|
+
return [];
|
|
1973
|
+
}
|
|
1974
|
+
return section2.items;
|
|
1975
|
+
}
|
|
1976
|
+
function deviceName(row) {
|
|
1977
|
+
return textOf(row.dns) || textOf(row.name) || hostAddress(row.ip) || textOf(row.ip);
|
|
1978
|
+
}
|
|
1979
|
+
function mapDevices5(items, warnings) {
|
|
1980
|
+
const devices = [];
|
|
1981
|
+
const byIp = /* @__PURE__ */ new Map();
|
|
1982
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1983
|
+
items.forEach((item, index) => {
|
|
1984
|
+
const pointer = `/devices/${index}`;
|
|
1985
|
+
if (!isRecord(item)) return;
|
|
1986
|
+
noteUnmapped(warnings, pointer, item, DEVICE_USED6, "device");
|
|
1987
|
+
const name = deviceName(item);
|
|
1988
|
+
if (!name || seen.has(name.toLowerCase())) return;
|
|
1989
|
+
seen.add(name.toLowerCase());
|
|
1990
|
+
devices.push(
|
|
1991
|
+
blankDevice(name, {
|
|
1992
|
+
managementIp: hostAddress(item.ip),
|
|
1993
|
+
model: textOf(item.model),
|
|
1994
|
+
platform: textOf(item.vendor) || textOf(item.os),
|
|
1995
|
+
site: textOf(item.location)
|
|
1996
|
+
})
|
|
1997
|
+
);
|
|
1998
|
+
const ip = hostAddress(item.ip) || textOf(item.ip);
|
|
1999
|
+
if (ip) byIp.set(ip, name);
|
|
2000
|
+
});
|
|
2001
|
+
return { devices, byIp };
|
|
2002
|
+
}
|
|
2003
|
+
function mapPorts2(items, byIp, warnings) {
|
|
2004
|
+
const interfaces = [];
|
|
2005
|
+
items.forEach((item, index) => {
|
|
2006
|
+
const pointer = `/ports/${index}`;
|
|
2007
|
+
if (!isRecord(item)) return;
|
|
2008
|
+
noteUnmapped(warnings, pointer, item, PORT_USED3, "port");
|
|
2009
|
+
const ip = hostAddress(item.ip) || textOf(item.ip);
|
|
2010
|
+
const device = byIp.get(ip) ?? "";
|
|
2011
|
+
const name = textOf(item.port) || textOf(item.name);
|
|
2012
|
+
if (!device || !name) {
|
|
2013
|
+
pushWarning(warnings, pointer, "Skipped a port whose device or name could not be resolved.");
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
const speed = numberLike(item.speed);
|
|
2017
|
+
const vlan = vlanId(item.vlan);
|
|
2018
|
+
interfaces.push(
|
|
2019
|
+
blankInterface(device, name, {
|
|
2020
|
+
description: textOf(item.descr),
|
|
2021
|
+
speed: speed == null ? "" : formatRate(speed, "bps"),
|
|
2022
|
+
...vlan != null ? { switchportMode: "access", accessVlan: vlan } : {}
|
|
2023
|
+
})
|
|
2024
|
+
);
|
|
2025
|
+
});
|
|
2026
|
+
return interfaces;
|
|
2027
|
+
}
|
|
2028
|
+
function neighborRows(ports, neighbors) {
|
|
2029
|
+
const fromPorts = ports.filter((item) => isRecord(item) && (textOf(item.remote_port) || textOf(item.remote_ip) || textOf(item.remote_name)));
|
|
2030
|
+
return neighbors.length > 0 ? neighbors : fromPorts;
|
|
2031
|
+
}
|
|
2032
|
+
function mapNeighbors(items, devices, byIp, warnings) {
|
|
2033
|
+
const links = [];
|
|
2034
|
+
items.forEach((item, index) => {
|
|
2035
|
+
const pointer = `/neighbors/${index}`;
|
|
2036
|
+
if (!isRecord(item)) return;
|
|
2037
|
+
noteUnmapped(warnings, pointer, item, NEIGHBOR_USED, "neighbor");
|
|
2038
|
+
const localIp = hostAddress(item.ip) || hostAddress(item.local_ip) || textOf(item.ip) || textOf(item.local_ip);
|
|
2039
|
+
const localDevice = byIp.get(localIp) ?? "";
|
|
2040
|
+
const localPort = textOf(item.port) || textOf(item.local_port);
|
|
2041
|
+
const remoteIp = hostAddress(item.remote_ip) || textOf(item.remote_ip);
|
|
2042
|
+
let remoteDevice = byIp.get(remoteIp) ?? "";
|
|
2043
|
+
const remotePort = textOf(item.remote_port);
|
|
2044
|
+
const remoteLabel = textOf(item.remote_name) || textOf(item.remote_dns);
|
|
2045
|
+
if (!remoteDevice && remoteLabel) remoteDevice = ensureDevice(devices, remoteLabel);
|
|
2046
|
+
else if (!remoteDevice && remoteIp) remoteDevice = ensureDevice(devices, remoteIp);
|
|
2047
|
+
if (!localDevice || !localPort || !remoteDevice || !remotePort) {
|
|
2048
|
+
pushWarning(warnings, pointer, "Skipped a neighbor that does not name both devices and ports.");
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
links.push(blankLink(localDevice, localPort, remoteDevice, remotePort));
|
|
2052
|
+
});
|
|
2053
|
+
return dedupeLinks(links);
|
|
2054
|
+
}
|
|
2055
|
+
function convertNetdisco(input) {
|
|
2056
|
+
if (!isRecord(input)) throw translatorFail(400, "A Netdisco export must be a JSON object.");
|
|
2057
|
+
const warnings = [];
|
|
2058
|
+
if ("nodes" in input) {
|
|
2059
|
+
pushWarning(warnings, "/nodes", "Ignored nodes. A MAC or ARP table is not topology.");
|
|
2060
|
+
}
|
|
2061
|
+
const deviceItems = rows2(warnings, input.devices, "devices");
|
|
2062
|
+
const portItems = rows2(warnings, input.ports, "ports");
|
|
2063
|
+
const neighborItems = rows2(warnings, input.neighbors ?? input.neighbours, "neighbors");
|
|
2064
|
+
const mapped = mapDevices5(deviceItems, warnings);
|
|
2065
|
+
const interfaces = mapPorts2(portItems, mapped.byIp, warnings);
|
|
2066
|
+
const links = mapNeighbors(neighborRows(portItems, neighborItems), mapped.devices, mapped.byIp, warnings);
|
|
2067
|
+
ensureLinkEnds(mapped.devices, interfaces, links);
|
|
2068
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
2069
|
+
return {
|
|
2070
|
+
document: publishDocument({ devices: mapped.devices, interfaces, links, vlans: [] }),
|
|
2071
|
+
warnings: sortWarnings(warnings)
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
var netdisco = {
|
|
2075
|
+
id: "netdisco",
|
|
2076
|
+
name: "Netdisco",
|
|
2077
|
+
formatHint: "Saved Netdisco API export (devices, ports, neighbors)",
|
|
2078
|
+
placeholder: `{
|
|
2079
|
+
"devices": [ { "ip": "192.0.2.1", "dns": "core-rtr" } ],
|
|
2080
|
+
"ports": [ { "ip": "192.0.2.1", "port": "GigabitEthernet1/0/1" } ],
|
|
2081
|
+
"neighbors": []
|
|
2082
|
+
}`,
|
|
2083
|
+
convert: convertNetdisco
|
|
2084
|
+
};
|
|
2085
|
+
var netdisco_default = netdisco;
|
|
2086
|
+
|
|
2087
|
+
// server/src/translators/observium.ts
|
|
2088
|
+
var observium_exports = {};
|
|
2089
|
+
__export(observium_exports, {
|
|
2090
|
+
default: () => observium_default
|
|
2091
|
+
});
|
|
2092
|
+
var DEVICE_USED7 = /* @__PURE__ */ new Set([
|
|
2093
|
+
"device_id",
|
|
2094
|
+
"hostname",
|
|
2095
|
+
"sysName",
|
|
2096
|
+
"hardware",
|
|
2097
|
+
"os",
|
|
2098
|
+
"location",
|
|
2099
|
+
"location_text",
|
|
2100
|
+
"vendor",
|
|
2101
|
+
"version",
|
|
2102
|
+
"type",
|
|
2103
|
+
"ip",
|
|
2104
|
+
"address",
|
|
2105
|
+
"ipv4_address",
|
|
2106
|
+
"sysObjectID",
|
|
2107
|
+
"sysDescr",
|
|
2108
|
+
"features",
|
|
2109
|
+
"status"
|
|
2110
|
+
]);
|
|
2111
|
+
var PORT_USED4 = /* @__PURE__ */ new Set([
|
|
2112
|
+
"port_id",
|
|
2113
|
+
"device_id",
|
|
2114
|
+
"ifName",
|
|
2115
|
+
"port_short_label",
|
|
2116
|
+
"ifDescr",
|
|
2117
|
+
"port_label",
|
|
2118
|
+
"ifAlias",
|
|
2119
|
+
"ifSpeed",
|
|
2120
|
+
"ifVlan",
|
|
2121
|
+
"ifType",
|
|
2122
|
+
"hostname"
|
|
2123
|
+
]);
|
|
2124
|
+
var NEIGHBOUR_USED = /* @__PURE__ */ new Set([
|
|
2125
|
+
"neighbour_id",
|
|
2126
|
+
"neighbor_id",
|
|
2127
|
+
"device_id",
|
|
2128
|
+
"port_id",
|
|
2129
|
+
"device_b",
|
|
2130
|
+
"port_b",
|
|
2131
|
+
"remote_port_id",
|
|
2132
|
+
"remote_hostname",
|
|
2133
|
+
"remote_port",
|
|
2134
|
+
"protocol",
|
|
2135
|
+
"platform",
|
|
2136
|
+
"version",
|
|
2137
|
+
"active"
|
|
2138
|
+
]);
|
|
2139
|
+
var ADDRESS_USED = /* @__PURE__ */ new Set(["address_id", "af", "device_id", "port_id", "vrf", "address", "prefix", "prefixlen"]);
|
|
2140
|
+
function objectRows(value) {
|
|
2141
|
+
if (Array.isArray(value)) return value;
|
|
2142
|
+
if (!isRecord(value)) return [];
|
|
2143
|
+
const values = Object.values(value);
|
|
2144
|
+
if (values.length > 0 && values.every((item) => isRecord(item))) return values;
|
|
2145
|
+
return [];
|
|
2146
|
+
}
|
|
2147
|
+
function rows3(warnings, value, label, keys) {
|
|
2148
|
+
if (value == null) return [];
|
|
2149
|
+
const section2 = sectionList(value, ["results", ...keys]);
|
|
2150
|
+
if (section2.present && !section2.bad) {
|
|
2151
|
+
if (section2.next) pushWarning(warnings, `/${label}`, `Ignored next page URL on ${label}. NerdGram does not fetch it.`);
|
|
2152
|
+
if (section2.items.length > 0) return section2.items;
|
|
2153
|
+
}
|
|
2154
|
+
if (isRecord(value)) {
|
|
2155
|
+
for (const key of keys) {
|
|
2156
|
+
const nested = objectRows(value[key]);
|
|
2157
|
+
if (nested.length > 0) return nested;
|
|
2158
|
+
}
|
|
2159
|
+
const itself = objectRows(value);
|
|
2160
|
+
if (itself.length > 0 && !("status" in value)) return itself;
|
|
2161
|
+
}
|
|
2162
|
+
if (section2.bad) pushWarning(warnings, `/${label}`, `${label} is not a list or an Observium envelope.`);
|
|
2163
|
+
return [];
|
|
2164
|
+
}
|
|
2165
|
+
function inactive(value) {
|
|
2166
|
+
if (value === 0 || value === false) return true;
|
|
2167
|
+
const text = textOf(value).toLowerCase();
|
|
2168
|
+
return text === "0" || text === "false" || text === "no";
|
|
2169
|
+
}
|
|
2170
|
+
function mapDevices6(items, warnings) {
|
|
2171
|
+
const devices = [];
|
|
2172
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2173
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2174
|
+
items.forEach((item, index) => {
|
|
2175
|
+
const pointer = `/devices/${index}`;
|
|
2176
|
+
if (!isRecord(item)) return;
|
|
2177
|
+
noteUnmapped(warnings, pointer, item, DEVICE_USED7, "device");
|
|
2178
|
+
let name = textOf(item.hostname);
|
|
2179
|
+
if (!name) {
|
|
2180
|
+
name = textOf(item.sysName);
|
|
2181
|
+
if (name) pushWarning(warnings, pointer, `Device name fell back to sysName "${name}" because hostname was empty.`);
|
|
2182
|
+
}
|
|
2183
|
+
if (!name || seen.has(name.toLowerCase())) return;
|
|
2184
|
+
seen.add(name.toLowerCase());
|
|
2185
|
+
const address = hostAddress(item.ip) || hostAddress(item.ipv4_address) || hostAddress(item.address);
|
|
2186
|
+
devices.push(
|
|
2187
|
+
blankDevice(name, {
|
|
2188
|
+
model: textOf(item.hardware),
|
|
2189
|
+
platform: textOf(item.os),
|
|
2190
|
+
site: textOf(item.location) || textOf(item.location_text),
|
|
2191
|
+
managementIp: address
|
|
2192
|
+
})
|
|
2193
|
+
);
|
|
2194
|
+
const id = idKey(item.device_id);
|
|
2195
|
+
if (id) ids.set(id, name);
|
|
2196
|
+
});
|
|
2197
|
+
return { devices, ids };
|
|
2198
|
+
}
|
|
2199
|
+
function portName(row) {
|
|
2200
|
+
return textOf(row.ifName) || textOf(row.port_short_label) || textOf(row.ifDescr) || textOf(row.port_label);
|
|
2201
|
+
}
|
|
2202
|
+
function mapPorts3(items, deviceIds, warnings) {
|
|
2203
|
+
const interfaces = [];
|
|
2204
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2205
|
+
items.forEach((item, index) => {
|
|
2206
|
+
const pointer = `/ports/${index}`;
|
|
2207
|
+
if (!isRecord(item)) return;
|
|
2208
|
+
noteUnmapped(warnings, pointer, item, PORT_USED4, "port");
|
|
2209
|
+
const device = deviceIds.get(idKey(item.device_id)) ?? "";
|
|
2210
|
+
const name = portName(item);
|
|
2211
|
+
if (!device || !name) {
|
|
2212
|
+
pushWarning(warnings, pointer, "Skipped a port whose device or name could not be resolved.");
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
const speed = numberLike(item.ifSpeed);
|
|
2216
|
+
const vlan = vlanId(item.ifVlan);
|
|
2217
|
+
interfaces.push(
|
|
2218
|
+
blankInterface(device, name, {
|
|
2219
|
+
description: textOf(item.ifAlias),
|
|
2220
|
+
speed: speed == null ? "" : formatRate(speed, "bps"),
|
|
2221
|
+
...vlan != null ? { switchportMode: "access", accessVlan: vlan } : {}
|
|
2222
|
+
})
|
|
2223
|
+
);
|
|
2224
|
+
const id = idKey(item.port_id);
|
|
2225
|
+
if (id) byId.set(id, { device, name });
|
|
2226
|
+
});
|
|
2227
|
+
return { interfaces, byId };
|
|
2228
|
+
}
|
|
2229
|
+
function assignAddresses4(items, interfaces, ports, warnings) {
|
|
2230
|
+
items.forEach((item, index) => {
|
|
2231
|
+
if (!isRecord(item)) return;
|
|
2232
|
+
noteUnmapped(warnings, `/address/${index}`, item, ADDRESS_USED, "address");
|
|
2233
|
+
const port = ports.get(idKey(item.port_id));
|
|
2234
|
+
if (!port) return;
|
|
2235
|
+
const raw = textOf(item.address);
|
|
2236
|
+
const cidr = splitCidr(raw.includes("/") ? raw : "");
|
|
2237
|
+
const prefix = numberLike(item.prefix) ?? numberLike(item.prefixlen);
|
|
2238
|
+
const host = cidr?.address || hostAddress(raw);
|
|
2239
|
+
const length = cidr?.prefix ?? prefix;
|
|
2240
|
+
if (!host || length == null) return;
|
|
2241
|
+
const family = host.includes(":") || textOf(item.af).toLowerCase() === "ipv6" ? "ipv6" : "ipv4";
|
|
2242
|
+
const row = interfaces.find((entry) => entry.device === port.device && entry.name === port.name);
|
|
2243
|
+
if (!row) return;
|
|
2244
|
+
const stored = { address: host, prefix: length };
|
|
2245
|
+
const list = family === "ipv4" ? row.ipv4 : row.ipv6;
|
|
2246
|
+
list.push(stored);
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
function mapNeighbours(items, devices, deviceIds, ports, warnings) {
|
|
2250
|
+
const links = [];
|
|
2251
|
+
items.forEach((item, index) => {
|
|
2252
|
+
const pointer = `/neighbours/${index}`;
|
|
2253
|
+
if (!isRecord(item)) return;
|
|
2254
|
+
noteUnmapped(warnings, pointer, item, NEIGHBOUR_USED, "neighbour");
|
|
2255
|
+
if (inactive(item.active)) {
|
|
2256
|
+
pushWarning(warnings, pointer, "Skipped an inactive neighbour.");
|
|
2257
|
+
return;
|
|
2258
|
+
}
|
|
2259
|
+
const local = ports.get(idKey(item.port_id));
|
|
2260
|
+
const localDevice = local?.device || deviceIds.get(idKey(item.device_id)) || "";
|
|
2261
|
+
const localName = local?.name || "";
|
|
2262
|
+
if (!localDevice || !localName) {
|
|
2263
|
+
pushWarning(warnings, pointer, "Skipped a neighbour whose local port is not in this export.");
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2266
|
+
const remotePort = ports.get(idKey(item.remote_port_id)) ?? ports.get(idKey(item.port_b));
|
|
2267
|
+
let remoteDevice = remotePort?.device || deviceIds.get(idKey(item.device_b)) || "";
|
|
2268
|
+
let remoteName = remotePort?.name || textOf(item.port_b) || textOf(item.remote_port);
|
|
2269
|
+
const remoteHost = textOf(item.remote_hostname) || textOf(item.device_b);
|
|
2270
|
+
if (!remoteDevice && remoteHost && !/^\d+$/.test(remoteHost)) {
|
|
2271
|
+
remoteDevice = ensureDevice(devices, remoteHost, { platform: textOf(item.platform) });
|
|
2272
|
+
}
|
|
2273
|
+
if (!remoteName && remotePort) remoteName = remotePort.name;
|
|
2274
|
+
if (!remoteDevice || !remoteName) {
|
|
2275
|
+
pushWarning(warnings, pointer, "Skipped a neighbour whose remote device or port could not be resolved.");
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2278
|
+
links.push(blankLink(localDevice, localName, remoteDevice, remoteName));
|
|
2279
|
+
});
|
|
2280
|
+
return dedupeLinks(links);
|
|
2281
|
+
}
|
|
2282
|
+
function convertObservium(input) {
|
|
2283
|
+
if (!isRecord(input)) throw translatorFail(400, "An Observium export must be a JSON object.");
|
|
2284
|
+
const warnings = [];
|
|
2285
|
+
const deviceItems = rows3(warnings, input.devices, "devices", ["devices"]);
|
|
2286
|
+
const portItems = rows3(warnings, input.ports, "ports", ["ports"]);
|
|
2287
|
+
const neighbourItems = rows3(warnings, input.neighbours ?? input.neighbors, "neighbours", ["neighbours", "neighbors"]);
|
|
2288
|
+
const addressItems = rows3(warnings, input.address ?? input.addresses, "address", ["addresses", "address"]);
|
|
2289
|
+
const mapped = mapDevices6(deviceItems, warnings);
|
|
2290
|
+
const ports = mapPorts3(portItems, mapped.ids, warnings);
|
|
2291
|
+
assignAddresses4(addressItems, ports.interfaces, ports.byId, warnings);
|
|
2292
|
+
const links = mapNeighbours(neighbourItems, mapped.devices, mapped.ids, ports.byId, warnings);
|
|
2293
|
+
ensureLinkEnds(mapped.devices, ports.interfaces, links);
|
|
2294
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
2295
|
+
return {
|
|
2296
|
+
document: publishDocument({ devices: mapped.devices, interfaces: ports.interfaces, links, vlans: [] }),
|
|
2297
|
+
warnings: sortWarnings(warnings)
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
var observium = {
|
|
2301
|
+
id: "observium",
|
|
2302
|
+
name: "Observium",
|
|
2303
|
+
formatHint: "Saved Observium API export (devices, ports, neighbours)",
|
|
2304
|
+
placeholder: `{
|
|
2305
|
+
"devices": { "status": "ok", "devices": { "1": { "hostname": "core-rtr", "os": "ios" } } },
|
|
2306
|
+
"ports": { "status": "ok", "ports": [] },
|
|
2307
|
+
"neighbours": { "status": "ok", "neighbours": [] }
|
|
2308
|
+
}`,
|
|
2309
|
+
convert: convertObservium
|
|
2310
|
+
};
|
|
2311
|
+
var observium_default = observium;
|
|
2312
|
+
|
|
2313
|
+
// server/src/translators/orion.ts
|
|
2314
|
+
var orion_exports = {};
|
|
2315
|
+
__export(orion_exports, {
|
|
2316
|
+
default: () => orion_default
|
|
2317
|
+
});
|
|
2318
|
+
var NODE_USED2 = /* @__PURE__ */ new Set([
|
|
2319
|
+
"NodeID",
|
|
2320
|
+
"Caption",
|
|
2321
|
+
"DisplayName",
|
|
2322
|
+
"IPAddress",
|
|
2323
|
+
"IP_Address",
|
|
2324
|
+
"IP",
|
|
2325
|
+
"MachineType",
|
|
2326
|
+
"Vendor",
|
|
2327
|
+
"Location",
|
|
2328
|
+
"Uri"
|
|
2329
|
+
]);
|
|
2330
|
+
var INTERFACE_USED3 = /* @__PURE__ */ new Set([
|
|
2331
|
+
"NodeID",
|
|
2332
|
+
"InterfaceID",
|
|
2333
|
+
"IfName",
|
|
2334
|
+
"InterfaceName",
|
|
2335
|
+
"Caption",
|
|
2336
|
+
"Name",
|
|
2337
|
+
"InterfaceCaption",
|
|
2338
|
+
"Alias",
|
|
2339
|
+
"InterfaceAlias",
|
|
2340
|
+
"Speed",
|
|
2341
|
+
"InterfaceSpeed",
|
|
2342
|
+
"AdminStatus",
|
|
2343
|
+
"OperStatus",
|
|
2344
|
+
"Uri"
|
|
2345
|
+
]);
|
|
2346
|
+
var TOPOLOGY_USED = /* @__PURE__ */ new Set([
|
|
2347
|
+
"SrcNodeID",
|
|
2348
|
+
"SrcInterfaceID",
|
|
2349
|
+
"DestNodeID",
|
|
2350
|
+
"DestInterfaceID",
|
|
2351
|
+
"SrcType",
|
|
2352
|
+
"DestType",
|
|
2353
|
+
"LayerType",
|
|
2354
|
+
"Uri"
|
|
2355
|
+
]);
|
|
2356
|
+
var SHADOW = "orion.shadownodes";
|
|
2357
|
+
function rows4(warnings, value, label) {
|
|
2358
|
+
const section2 = sectionList(value, ["results", label]);
|
|
2359
|
+
if (!section2.present) return [];
|
|
2360
|
+
if (section2.next) pushWarning(warnings, `/${label}`, `Ignored next page URL on ${label}. NerdGram does not fetch it.`);
|
|
2361
|
+
if (section2.bad) {
|
|
2362
|
+
pushWarning(warnings, `/${label}`, `${label} is not a list or a SWIS results envelope.`);
|
|
2363
|
+
return [];
|
|
2364
|
+
}
|
|
2365
|
+
return section2.items;
|
|
2366
|
+
}
|
|
2367
|
+
function snmpStatus(value) {
|
|
2368
|
+
const number = numberLike(value);
|
|
2369
|
+
if (number == null || value === "") return "";
|
|
2370
|
+
if (number === 1) return "up";
|
|
2371
|
+
if (number === 2) return "down";
|
|
2372
|
+
return "other";
|
|
2373
|
+
}
|
|
2374
|
+
function mapNodes2(items, warnings) {
|
|
2375
|
+
const devices = [];
|
|
2376
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2377
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2378
|
+
items.forEach((item, index) => {
|
|
2379
|
+
const pointer = `/nodes/${index}`;
|
|
2380
|
+
if (!isRecord(item)) {
|
|
2381
|
+
pushWarning(warnings, pointer, "Skipped a node that is not an object.");
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2384
|
+
noteUnmapped(warnings, pointer, item, NODE_USED2, "node");
|
|
2385
|
+
const name = textOf(item.Caption) || textOf(item.DisplayName);
|
|
2386
|
+
if (!name) {
|
|
2387
|
+
pushWarning(warnings, pointer, "Skipped a node with no Caption or DisplayName.");
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
2390
|
+
if (seen.has(name.toLowerCase())) {
|
|
2391
|
+
pushWarning(warnings, pointer, `Duplicate node "${name}" was skipped.`);
|
|
2392
|
+
return;
|
|
2393
|
+
}
|
|
2394
|
+
seen.add(name.toLowerCase());
|
|
2395
|
+
const address = hostAddress(item.IPAddress) || hostAddress(item.IP_Address) || hostAddress(item.IP);
|
|
2396
|
+
devices.push(
|
|
2397
|
+
blankDevice(name, {
|
|
2398
|
+
managementIp: address,
|
|
2399
|
+
model: textOf(item.MachineType),
|
|
2400
|
+
platform: textOf(item.Vendor),
|
|
2401
|
+
site: textOf(item.Location)
|
|
2402
|
+
})
|
|
2403
|
+
);
|
|
2404
|
+
const id = idKey(item.NodeID);
|
|
2405
|
+
if (id) byId.set(id, name);
|
|
2406
|
+
});
|
|
2407
|
+
return { devices, byId };
|
|
2408
|
+
}
|
|
2409
|
+
function interfaceName(row) {
|
|
2410
|
+
return textOf(row.IfName) || textOf(row.InterfaceName) || textOf(row.Caption) || textOf(row.InterfaceCaption) || textOf(row.Name);
|
|
2411
|
+
}
|
|
2412
|
+
function mapInterfaces4(items, nodes, warnings) {
|
|
2413
|
+
const interfaces = [];
|
|
2414
|
+
const byId = /* @__PURE__ */ new Map();
|
|
2415
|
+
items.forEach((item, index) => {
|
|
2416
|
+
const pointer = `/interfaces/${index}`;
|
|
2417
|
+
if (!isRecord(item)) return;
|
|
2418
|
+
noteUnmapped(warnings, pointer, item, INTERFACE_USED3, "interface");
|
|
2419
|
+
const device = nodes.get(idKey(item.NodeID)) ?? "";
|
|
2420
|
+
const name = interfaceName(item);
|
|
2421
|
+
if (!device || !name) {
|
|
2422
|
+
pushWarning(warnings, pointer, "Skipped an interface whose node or name could not be resolved.");
|
|
2423
|
+
return;
|
|
2424
|
+
}
|
|
2425
|
+
const admin = snmpStatus(item.AdminStatus);
|
|
2426
|
+
const oper = snmpStatus(item.OperStatus);
|
|
2427
|
+
if (admin === "other") pushWarning(warnings, `${pointer}/AdminStatus`, `AdminStatus ${String(item.AdminStatus)} is not Up (1) or Down (2).`);
|
|
2428
|
+
if (oper === "other") pushWarning(warnings, `${pointer}/OperStatus`, `OperStatus ${String(item.OperStatus)} is not Up (1) or Down (2).`);
|
|
2429
|
+
const speedValue = numberLike(item.Speed) ?? numberLike(item.InterfaceSpeed);
|
|
2430
|
+
interfaces.push(
|
|
2431
|
+
blankInterface(device, name, {
|
|
2432
|
+
description: textOf(item.Alias) || textOf(item.InterfaceAlias),
|
|
2433
|
+
speed: speedValue == null ? "" : formatRate(speedValue, "bps"),
|
|
2434
|
+
adminStatus: admin === "up" || admin === "down" ? admin : "",
|
|
2435
|
+
operStatus: oper === "up" || oper === "down" ? oper : ""
|
|
2436
|
+
})
|
|
2437
|
+
);
|
|
2438
|
+
const id = idKey(item.InterfaceID);
|
|
2439
|
+
if (id) byId.set(id, { device, name });
|
|
2440
|
+
});
|
|
2441
|
+
return { interfaces, byId };
|
|
2442
|
+
}
|
|
2443
|
+
function mapTopology(items, nodes, ports, warnings) {
|
|
2444
|
+
const links = [];
|
|
2445
|
+
items.forEach((item, index) => {
|
|
2446
|
+
const pointer = `/topology/${index}`;
|
|
2447
|
+
if (!isRecord(item)) return;
|
|
2448
|
+
noteUnmapped(warnings, pointer, item, TOPOLOGY_USED, "topology");
|
|
2449
|
+
const srcType = textOf(item.SrcType).toLowerCase();
|
|
2450
|
+
const destType = textOf(item.DestType).toLowerCase();
|
|
2451
|
+
if (srcType === SHADOW || destType === SHADOW) {
|
|
2452
|
+
pushWarning(warnings, pointer, "Skipped a topology row that ends on Orion.ShadowNodes.");
|
|
2453
|
+
return;
|
|
2454
|
+
}
|
|
2455
|
+
const src = ports.get(idKey(item.SrcInterfaceID));
|
|
2456
|
+
const dest = ports.get(idKey(item.DestInterfaceID));
|
|
2457
|
+
const srcDevice = src?.device || nodes.get(idKey(item.SrcNodeID)) || "";
|
|
2458
|
+
const destDevice = dest?.device || nodes.get(idKey(item.DestNodeID)) || "";
|
|
2459
|
+
if (!src || !dest || !srcDevice || !destDevice) {
|
|
2460
|
+
pushWarning(warnings, pointer, "Skipped a topology row whose nodes or interfaces are not in this export.");
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
links.push(blankLink(srcDevice, src.name, destDevice, dest.name));
|
|
2464
|
+
});
|
|
2465
|
+
return dedupeLinks(links);
|
|
2466
|
+
}
|
|
2467
|
+
function convertOrion(input) {
|
|
2468
|
+
if (!isRecord(input)) throw translatorFail(400, "An Orion export must be a JSON object.");
|
|
2469
|
+
const warnings = [];
|
|
2470
|
+
const nodeItems = rows4(warnings, input.nodes ?? input["Orion.Nodes"], "nodes");
|
|
2471
|
+
const interfaceItems = rows4(warnings, input.interfaces ?? input["Orion.NPM.Interfaces"], "interfaces");
|
|
2472
|
+
const topologyItems = rows4(
|
|
2473
|
+
warnings,
|
|
2474
|
+
input.topology ?? input.topologyConnections ?? input["Orion.TopologyConnections"],
|
|
2475
|
+
"topology"
|
|
2476
|
+
);
|
|
2477
|
+
const nodes = mapNodes2(nodeItems, warnings);
|
|
2478
|
+
const ports = mapInterfaces4(interfaceItems, nodes.byId, warnings);
|
|
2479
|
+
const links = mapTopology(topologyItems, nodes.byId, ports.byId, warnings);
|
|
2480
|
+
ensureLinkEnds(nodes.devices, ports.interfaces, links);
|
|
2481
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
2482
|
+
return {
|
|
2483
|
+
document: publishDocument({ devices: nodes.devices, interfaces: ports.interfaces, links, vlans: [] }),
|
|
2484
|
+
warnings: sortWarnings(warnings)
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
var orion = {
|
|
2488
|
+
id: "orion",
|
|
2489
|
+
name: "SolarWinds Orion",
|
|
2490
|
+
formatHint: "Saved SWIS Query JSON (nodes, interfaces, topology connections)",
|
|
2491
|
+
placeholder: `{
|
|
2492
|
+
"nodes": { "results": [ { "NodeID": 1, "Caption": "core-rtr", "IPAddress": "192.0.2.1" } ] },
|
|
2493
|
+
"interfaces": { "results": [] },
|
|
2494
|
+
"topology": { "results": [] }
|
|
2495
|
+
}`,
|
|
2496
|
+
convert: convertOrion
|
|
2497
|
+
};
|
|
2498
|
+
var orion_default = orion;
|
|
2499
|
+
|
|
2500
|
+
// server/src/translators/prtg.ts
|
|
2501
|
+
var prtg_exports = {};
|
|
2502
|
+
__export(prtg_exports, {
|
|
2503
|
+
default: () => prtg_default
|
|
2504
|
+
});
|
|
2505
|
+
var DEVICE_USED8 = /* @__PURE__ */ new Set(["objid", "probe", "group", "device", "host", "name", "status"]);
|
|
2506
|
+
var SENSOR_USED = /* @__PURE__ */ new Set(["objid", "group", "device", "sensor", "status", "lastvalue", "interface", "port"]);
|
|
2507
|
+
var LINK_USED3 = /* @__PURE__ */ new Set(["a", "b", "source", "target", "device", "interface", "label"]);
|
|
2508
|
+
function rows5(warnings, value, label) {
|
|
2509
|
+
const section2 = sectionList(value, [label, "devices", "sensors"]);
|
|
2510
|
+
if (!section2.present) return [];
|
|
2511
|
+
if (section2.bad) {
|
|
2512
|
+
pushWarning(warnings, `/${label}`, `${label} is not a PRTG table.`);
|
|
2513
|
+
return [];
|
|
2514
|
+
}
|
|
2515
|
+
return section2.items;
|
|
2516
|
+
}
|
|
2517
|
+
function mapDevices7(items, warnings) {
|
|
2518
|
+
const devices = [];
|
|
2519
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2520
|
+
items.forEach((item, index) => {
|
|
2521
|
+
const pointer = `/devices/${index}`;
|
|
2522
|
+
if (!isRecord(item)) return;
|
|
2523
|
+
noteUnmapped(warnings, pointer, item, DEVICE_USED8, "device");
|
|
2524
|
+
const name = textOf(item.device) || textOf(item.name);
|
|
2525
|
+
if (!name || seen.has(name.toLowerCase())) return;
|
|
2526
|
+
seen.add(name.toLowerCase());
|
|
2527
|
+
devices.push(
|
|
2528
|
+
blankDevice(name, {
|
|
2529
|
+
managementIp: hostAddress(item.host),
|
|
2530
|
+
site: textOf(item.group)
|
|
2531
|
+
})
|
|
2532
|
+
);
|
|
2533
|
+
});
|
|
2534
|
+
return devices;
|
|
2535
|
+
}
|
|
2536
|
+
function mapSensors(items, devices, warnings) {
|
|
2537
|
+
const known = new Set(devices.map((device) => device.name.toLowerCase()));
|
|
2538
|
+
const interfaces = [];
|
|
2539
|
+
let ignored = 0;
|
|
2540
|
+
items.forEach((item, index) => {
|
|
2541
|
+
if (!isRecord(item)) return;
|
|
2542
|
+
noteUnmapped(warnings, `/sensors/${index}`, item, SENSOR_USED, "sensor");
|
|
2543
|
+
const device = textOf(item.device);
|
|
2544
|
+
const port = textOf(item.interface) || textOf(item.port);
|
|
2545
|
+
if (!port || !device || !known.has(device.toLowerCase())) {
|
|
2546
|
+
ignored += 1;
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
interfaces.push(blankInterface(device, port, { description: textOf(item.sensor) }));
|
|
2550
|
+
});
|
|
2551
|
+
if (ignored > 0) {
|
|
2552
|
+
pushWarning(warnings, "/sensors", "Sensors without an interface or port column were not turned into interfaces.");
|
|
2553
|
+
}
|
|
2554
|
+
return interfaces;
|
|
2555
|
+
}
|
|
2556
|
+
function endpoint(value) {
|
|
2557
|
+
if (!isRecord(value)) return null;
|
|
2558
|
+
const device = textOf(value.device) || textOf(value.name);
|
|
2559
|
+
const iface = textOf(value.interface) || textOf(value.port);
|
|
2560
|
+
if (!device || !iface) return null;
|
|
2561
|
+
return { device, interface: iface };
|
|
2562
|
+
}
|
|
2563
|
+
function mapLinks3(items, warnings) {
|
|
2564
|
+
const links = [];
|
|
2565
|
+
items.forEach((item, index) => {
|
|
2566
|
+
const pointer = `/links/${index}`;
|
|
2567
|
+
if (!isRecord(item)) return;
|
|
2568
|
+
noteUnmapped(warnings, pointer, item, LINK_USED3, "link");
|
|
2569
|
+
const a = endpoint(item.a) ?? endpoint({ device: item.source ?? item.device, interface: item.interface });
|
|
2570
|
+
const b = endpoint(item.b) ?? endpoint(isRecord(item.target) ? item.target : { device: item.target, interface: item.port });
|
|
2571
|
+
if (!a || !b) {
|
|
2572
|
+
pushWarning(warnings, pointer, "Skipped a link that does not name both devices and ports.");
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2575
|
+
links.push(blankLink(a.device, a.interface, b.device, b.interface, textOf(item.label)));
|
|
2576
|
+
});
|
|
2577
|
+
return dedupeLinks(links);
|
|
2578
|
+
}
|
|
2579
|
+
function convertPrtg(input) {
|
|
2580
|
+
if (!isRecord(input)) throw translatorFail(400, "A PRTG export must be a JSON object.");
|
|
2581
|
+
const warnings = [];
|
|
2582
|
+
const deviceItems = rows5(warnings, input.devices ?? input, "devices");
|
|
2583
|
+
const sensorItems = rows5(warnings, input.sensors, "sensors");
|
|
2584
|
+
const devices = mapDevices7(deviceItems, warnings);
|
|
2585
|
+
const interfaces = mapSensors(sensorItems, devices, warnings);
|
|
2586
|
+
const links = mapLinks3(rows5(warnings, input.links, "links"), warnings);
|
|
2587
|
+
ensureLinkEnds(devices, interfaces, links);
|
|
2588
|
+
if (interfaces.length === 0 && devices.length > 0) {
|
|
2589
|
+
pushWarning(warnings, "", "This PRTG export is inventory only. No switch ports were created.");
|
|
2590
|
+
}
|
|
2591
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
2592
|
+
return {
|
|
2593
|
+
document: publishDocument({ devices, interfaces, links, vlans: [] }),
|
|
2594
|
+
warnings: sortWarnings(warnings)
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
var prtg = {
|
|
2598
|
+
id: "prtg",
|
|
2599
|
+
name: "PRTG",
|
|
2600
|
+
formatHint: "Saved PRTG table.json devices export",
|
|
2601
|
+
placeholder: `{
|
|
2602
|
+
"prtg-version": "24.0.0",
|
|
2603
|
+
"devices": [ { "objid": 1, "group": "HQ", "device": "core-rtr", "host": "192.0.2.1" } ]
|
|
2604
|
+
}`,
|
|
2605
|
+
convert: convertPrtg
|
|
2606
|
+
};
|
|
2607
|
+
var prtg_default = prtg;
|
|
2608
|
+
|
|
2609
|
+
// server/src/translators/pyats.ts
|
|
2610
|
+
var pyats_exports = {};
|
|
2611
|
+
__export(pyats_exports, {
|
|
2612
|
+
default: () => pyats_default
|
|
2613
|
+
});
|
|
2614
|
+
var DEVICE_USED9 = /* @__PURE__ */ new Set(["os", "type", "alias", "connections", "credentials", "custom", "platform"]);
|
|
2615
|
+
var INTERFACE_USED4 = /* @__PURE__ */ new Set([
|
|
2616
|
+
"oper_status",
|
|
2617
|
+
"enabled",
|
|
2618
|
+
"description",
|
|
2619
|
+
"bandwidth",
|
|
2620
|
+
"ipv4",
|
|
2621
|
+
"ipv6",
|
|
2622
|
+
"vrf",
|
|
2623
|
+
"switchport_mode",
|
|
2624
|
+
"access_vlan",
|
|
2625
|
+
"trunk_vlans",
|
|
2626
|
+
"native_vlan",
|
|
2627
|
+
"mtu",
|
|
2628
|
+
"port_channel"
|
|
2629
|
+
]);
|
|
2630
|
+
function connectionIp(connections) {
|
|
2631
|
+
if (!isRecord(connections)) return "";
|
|
2632
|
+
for (const value of Object.values(connections)) {
|
|
2633
|
+
if (!isRecord(value)) continue;
|
|
2634
|
+
const address = hostAddress(value.ip) || hostAddress(value.host);
|
|
2635
|
+
if (address) return address;
|
|
2636
|
+
const protocol = isRecord(value.protocol) ? value.protocol : null;
|
|
2637
|
+
const nested = protocol ? hostAddress(protocol.ip) || hostAddress(protocol.host) : "";
|
|
2638
|
+
if (nested) return nested;
|
|
2639
|
+
}
|
|
2640
|
+
return "";
|
|
2641
|
+
}
|
|
2642
|
+
function addressesOf(value, family) {
|
|
2643
|
+
if (!isRecord(value)) return [];
|
|
2644
|
+
const out = [];
|
|
2645
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
2646
|
+
const cidr = splitCidr(key);
|
|
2647
|
+
if (cidr && cidr.family === family) {
|
|
2648
|
+
out.push({ address: cidr.address, prefix: cidr.prefix });
|
|
2649
|
+
continue;
|
|
2650
|
+
}
|
|
2651
|
+
if (!isRecord(raw)) continue;
|
|
2652
|
+
const address = hostAddress(raw.ip) || hostAddress(raw.address);
|
|
2653
|
+
const prefix = numberLike(raw.prefix_length) ?? numberLike(raw.prefix);
|
|
2654
|
+
if (address && prefix != null) out.push({ address, prefix });
|
|
2655
|
+
}
|
|
2656
|
+
return out;
|
|
2657
|
+
}
|
|
2658
|
+
function mapInterface(device, name, row, warnings, pointer) {
|
|
2659
|
+
noteUnmapped(warnings, pointer, row, INTERFACE_USED4, "interface");
|
|
2660
|
+
const admin = statusUpDown(row.enabled);
|
|
2661
|
+
const oper = statusUpDown(row.oper_status);
|
|
2662
|
+
const mode = textOf(row.switchport_mode).toLowerCase();
|
|
2663
|
+
const switchportMode = mode === "access" || mode === "trunk" ? mode : "";
|
|
2664
|
+
const bandwidth = numberLike(row.bandwidth);
|
|
2665
|
+
const vrf = textOf(row.vrf);
|
|
2666
|
+
return blankInterface(device, name, {
|
|
2667
|
+
description: textOf(row.description),
|
|
2668
|
+
adminStatus: admin === "up" || admin === "down" ? admin : "",
|
|
2669
|
+
operStatus: oper === "up" || oper === "down" ? oper : "",
|
|
2670
|
+
speed: bandwidth == null ? "" : formatRate(bandwidth, "kbps"),
|
|
2671
|
+
vrf: vrf && vrf.toLowerCase() !== "default" ? vrf : "",
|
|
2672
|
+
ipv4: addressesOf(row.ipv4, "ipv4"),
|
|
2673
|
+
ipv6: addressesOf(row.ipv6, "ipv6"),
|
|
2674
|
+
switchportMode,
|
|
2675
|
+
accessVlan: switchportMode === "access" ? vlanId(row.access_vlan) : null,
|
|
2676
|
+
nativeVlan: switchportMode === "trunk" ? vlanId(row.native_vlan) : null,
|
|
2677
|
+
trunkVlans: Array.isArray(row.trunk_vlans) ? row.trunk_vlans.map((item) => vlanId(item)).filter((item) => item != null) : null
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
function learnInfo(value) {
|
|
2681
|
+
if (!isRecord(value)) return null;
|
|
2682
|
+
if (isRecord(value.info)) return value.info;
|
|
2683
|
+
return value;
|
|
2684
|
+
}
|
|
2685
|
+
function addNeighbors(feature, localDevice, devices, links, warnings, pointer) {
|
|
2686
|
+
const info = learnInfo(feature);
|
|
2687
|
+
const interfaces = info && isRecord(info.interfaces) ? info.interfaces : null;
|
|
2688
|
+
if (!interfaces) {
|
|
2689
|
+
if (feature != null) pushWarning(warnings, pointer, "Neighbor learn output has no interfaces object.");
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
for (const [localName, raw] of Object.entries(interfaces)) {
|
|
2693
|
+
if (!isRecord(raw) || localName === "total_entries") continue;
|
|
2694
|
+
if (isRecord(raw.port_id)) {
|
|
2695
|
+
for (const [remotePort, portRaw] of Object.entries(raw.port_id)) {
|
|
2696
|
+
if (!isRecord(portRaw) || !isRecord(portRaw.neighbors)) continue;
|
|
2697
|
+
for (const remoteName of Object.keys(portRaw.neighbors)) {
|
|
2698
|
+
const remote = remoteName.trim();
|
|
2699
|
+
const port = remotePort.trim();
|
|
2700
|
+
if (!remote || !port) continue;
|
|
2701
|
+
links.push(blankLink(localDevice, localName, ensureDevice(devices, remote), port));
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
continue;
|
|
2705
|
+
}
|
|
2706
|
+
if (!isRecord(raw.neighbors)) continue;
|
|
2707
|
+
for (const [remoteName, neighbor] of Object.entries(raw.neighbors)) {
|
|
2708
|
+
const port = isRecord(neighbor) ? textOf(neighbor.port_id) || textOf(neighbor.port) : "";
|
|
2709
|
+
const remote = remoteName.trim();
|
|
2710
|
+
if (!remote || !port) {
|
|
2711
|
+
pushWarning(warnings, pointer, `Skipped a neighbor on ${localName} with no remote port.`);
|
|
2712
|
+
continue;
|
|
2713
|
+
}
|
|
2714
|
+
links.push(blankLink(localDevice, localName, ensureDevice(devices, remote), port));
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
function mapTestbed(devicesMap, warnings) {
|
|
2719
|
+
const devices = [];
|
|
2720
|
+
let sawCredentials = false;
|
|
2721
|
+
for (const [name, raw] of Object.entries(devicesMap)) {
|
|
2722
|
+
if (!isRecord(raw)) continue;
|
|
2723
|
+
noteUnmapped(warnings, `/devices/${name}`, raw, DEVICE_USED9, "testbed device");
|
|
2724
|
+
if ("credentials" in raw) sawCredentials = true;
|
|
2725
|
+
devices.push(
|
|
2726
|
+
blankDevice(name, {
|
|
2727
|
+
platform: textOf(raw.os) || textOf(raw.type),
|
|
2728
|
+
managementIp: connectionIp(raw.connections)
|
|
2729
|
+
})
|
|
2730
|
+
);
|
|
2731
|
+
}
|
|
2732
|
+
return { devices, sawCredentials };
|
|
2733
|
+
}
|
|
2734
|
+
function looksLikeTestbed(devices) {
|
|
2735
|
+
return Object.values(devices).some((item) => isRecord(item) && ("connections" in item || "os" in item || "credentials" in item));
|
|
2736
|
+
}
|
|
2737
|
+
function looksLikeLearn(devices) {
|
|
2738
|
+
return Object.values(devices).some(
|
|
2739
|
+
(item) => isRecord(item) && ("interface" in item || "lldp" in item || "cdp" in item || "info" in item)
|
|
2740
|
+
);
|
|
2741
|
+
}
|
|
2742
|
+
function convertPyats(input) {
|
|
2743
|
+
if (!isRecord(input)) throw translatorFail(400, "A pyATS export must be a JSON object.");
|
|
2744
|
+
const warnings = [];
|
|
2745
|
+
const devices = [];
|
|
2746
|
+
const interfaces = [];
|
|
2747
|
+
const links = [];
|
|
2748
|
+
let sawCredentials = "credentials" in input || isRecord(input.testbed) && "credentials" in input.testbed;
|
|
2749
|
+
const nestedTestbed = isRecord(input.testbed) && isRecord(input.testbed.devices) ? input.testbed.devices : null;
|
|
2750
|
+
const topDevices = isRecord(input.devices) ? input.devices : null;
|
|
2751
|
+
const testbed = nestedTestbed ?? (topDevices && looksLikeTestbed(topDevices) ? topDevices : null);
|
|
2752
|
+
const learnRoot = isRecord(input.learn) ? input.learn : topDevices && looksLikeLearn(topDevices) && !looksLikeTestbed(topDevices) ? topDevices : null;
|
|
2753
|
+
const singleInfo = isRecord(input.info) ? input : null;
|
|
2754
|
+
if (testbed) {
|
|
2755
|
+
const mapped = mapTestbed(testbed, warnings);
|
|
2756
|
+
devices.push(...mapped.devices);
|
|
2757
|
+
sawCredentials = sawCredentials || mapped.sawCredentials;
|
|
2758
|
+
}
|
|
2759
|
+
const learnDevices = learnRoot && isRecord(learnRoot.devices) ? learnRoot.devices : learnRoot;
|
|
2760
|
+
if (isRecord(learnDevices)) {
|
|
2761
|
+
for (const [name, raw] of Object.entries(learnDevices)) {
|
|
2762
|
+
if (!isRecord(raw)) continue;
|
|
2763
|
+
if (!devices.some((device) => device.name.toLowerCase() === name.toLowerCase())) devices.push(blankDevice(name));
|
|
2764
|
+
const info = isRecord(raw.interface) ? learnInfo(raw.interface) : isRecord(raw.info) ? raw.info : null;
|
|
2765
|
+
if (info) {
|
|
2766
|
+
for (const [iface, row] of Object.entries(info)) {
|
|
2767
|
+
if (!isRecord(row)) continue;
|
|
2768
|
+
interfaces.push(mapInterface(name, iface, row, warnings, `/learn/${name}/${iface}`));
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
addNeighbors(raw.lldp, name, devices, links, warnings, `/learn/${name}/lldp`);
|
|
2772
|
+
addNeighbors(raw.cdp, name, devices, links, warnings, `/learn/${name}/cdp`);
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
if (singleInfo && devices.length === 0) {
|
|
2776
|
+
const name = textOf(input.device) || textOf(input.name) || "device";
|
|
2777
|
+
devices.push(blankDevice(name));
|
|
2778
|
+
const info = learnInfo(input);
|
|
2779
|
+
if (info) {
|
|
2780
|
+
for (const [iface, row] of Object.entries(info)) {
|
|
2781
|
+
if (!isRecord(row) || iface === "device") continue;
|
|
2782
|
+
interfaces.push(mapInterface(name, iface, row, warnings, `/info/${iface}`));
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
if (sawCredentials) pushWarning(warnings, "", "Ignored credentials in this export. They were not copied.");
|
|
2787
|
+
const unique = dedupeLinks(links);
|
|
2788
|
+
ensureLinkEnds(devices, interfaces, unique);
|
|
2789
|
+
if (unique.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
2790
|
+
return {
|
|
2791
|
+
document: publishDocument({ devices, interfaces, links: unique, vlans: [] }),
|
|
2792
|
+
warnings: sortWarnings(warnings)
|
|
2793
|
+
};
|
|
2794
|
+
}
|
|
2795
|
+
var pyats = {
|
|
2796
|
+
id: "pyats",
|
|
2797
|
+
name: "Cisco pyATS",
|
|
2798
|
+
formatHint: "Saved pyATS testbed or Genie learn JSON",
|
|
2799
|
+
placeholder: `{
|
|
2800
|
+
"devices": {
|
|
2801
|
+
"core-rtr": { "os": "iosxe", "type": "router", "connections": { "cli": { "ip": "192.0.2.1" } } }
|
|
2802
|
+
}
|
|
2803
|
+
}`,
|
|
2804
|
+
convert: convertPyats
|
|
2805
|
+
};
|
|
2806
|
+
var pyats_default = pyats;
|
|
2807
|
+
|
|
2808
|
+
// server/src/translators/terraform.ts
|
|
2809
|
+
var terraform_exports = {};
|
|
2810
|
+
__export(terraform_exports, {
|
|
2811
|
+
default: () => terraform_default
|
|
2812
|
+
});
|
|
2813
|
+
var DEVICE_KEYS = /* @__PURE__ */ new Set(["name", "hostname", "management_ip", "management_address", "model", "platform", "os", "role", "site", "location"]);
|
|
2814
|
+
var INTERFACE_KEYS = /* @__PURE__ */ new Set(["device", "device_name", "name", "description", "enabled", "shutdown", "speed", "ipv4", "vrf"]);
|
|
2815
|
+
var LINK_KEYS = /* @__PURE__ */ new Set(["a_device", "a_interface", "b_device", "b_interface", "label"]);
|
|
2816
|
+
var VLAN_KEYS = /* @__PURE__ */ new Set(["id", "vid", "name"]);
|
|
2817
|
+
var SUPPORTED = {
|
|
2818
|
+
network_device: "device",
|
|
2819
|
+
network_interface: "interface",
|
|
2820
|
+
network_link: "link",
|
|
2821
|
+
network_vlan: "vlan"
|
|
2822
|
+
};
|
|
2823
|
+
function majorSupported(value, warnings) {
|
|
2824
|
+
if (value == null) return true;
|
|
2825
|
+
const text = textOf(value);
|
|
2826
|
+
const major = Number(text.split(".")[0]);
|
|
2827
|
+
if (major === 1) return true;
|
|
2828
|
+
pushWarning(warnings, "/format_version", `Unsupported Terraform JSON major version "${text || String(value)}". No resources were mapped.`);
|
|
2829
|
+
return false;
|
|
2830
|
+
}
|
|
2831
|
+
function valuesOf(input, warnings) {
|
|
2832
|
+
if (isRecord(input.planned_values)) return input.planned_values;
|
|
2833
|
+
if (isRecord(input.prior_state) && isRecord(input.prior_state.values)) {
|
|
2834
|
+
pushWarning(warnings, "", "This plan has no planned_values. prior_state.values was used.");
|
|
2835
|
+
return input.prior_state.values;
|
|
2836
|
+
}
|
|
2837
|
+
if (isRecord(input.values)) return input.values;
|
|
2838
|
+
return null;
|
|
2839
|
+
}
|
|
2840
|
+
function scrub(values, sensitive, warnings, pointer) {
|
|
2841
|
+
if (sensitive === true) {
|
|
2842
|
+
pushWarning(warnings, pointer, "Skipped a sensitive value.");
|
|
2843
|
+
return {};
|
|
2844
|
+
}
|
|
2845
|
+
if (!isRecord(sensitive)) return values;
|
|
2846
|
+
const copy = { ...values };
|
|
2847
|
+
for (const [key, flag] of Object.entries(sensitive)) {
|
|
2848
|
+
if (flag === true) {
|
|
2849
|
+
delete copy[key];
|
|
2850
|
+
pushWarning(warnings, `${pointer}/${key}`, `Skipped sensitive attribute "${key}".`);
|
|
2851
|
+
} else if (isRecord(flag) && isRecord(copy[key])) {
|
|
2852
|
+
copy[key] = scrub(copy[key], flag, warnings, `${pointer}/${key}`);
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
return copy;
|
|
2856
|
+
}
|
|
2857
|
+
function cidrs(value) {
|
|
2858
|
+
const texts = Array.isArray(value) ? value.map(textOf) : [textOf(value)];
|
|
2859
|
+
const out = [];
|
|
2860
|
+
for (const text of texts) {
|
|
2861
|
+
const cidr = splitCidr(text);
|
|
2862
|
+
if (cidr) out.push({ address: cidr.address, prefix: cidr.prefix });
|
|
2863
|
+
}
|
|
2864
|
+
return out;
|
|
2865
|
+
}
|
|
2866
|
+
function takeDevice(values, warnings, pointer, bucket) {
|
|
2867
|
+
noteUnmapped(warnings, pointer, values, DEVICE_KEYS, "resource");
|
|
2868
|
+
const name = textOf(values.name) || textOf(values.hostname);
|
|
2869
|
+
if (!name) {
|
|
2870
|
+
pushWarning(warnings, pointer, "Skipped a device resource with no name.");
|
|
2871
|
+
return;
|
|
2872
|
+
}
|
|
2873
|
+
bucket.devices.push(
|
|
2874
|
+
blankDevice(name, {
|
|
2875
|
+
managementIp: hostAddress(values.management_ip) || hostAddress(values.management_address),
|
|
2876
|
+
model: textOf(values.model),
|
|
2877
|
+
platform: textOf(values.platform) || textOf(values.os),
|
|
2878
|
+
role: textOf(values.role),
|
|
2879
|
+
site: textOf(values.site) || textOf(values.location)
|
|
2880
|
+
})
|
|
2881
|
+
);
|
|
2882
|
+
}
|
|
2883
|
+
function takeInterface(values, warnings, pointer, bucket) {
|
|
2884
|
+
noteUnmapped(warnings, pointer, values, INTERFACE_KEYS, "resource");
|
|
2885
|
+
const device = textOf(values.device) || textOf(values.device_name);
|
|
2886
|
+
const name = textOf(values.name);
|
|
2887
|
+
if (!device || !name) {
|
|
2888
|
+
pushWarning(warnings, pointer, "Skipped an interface resource with no device or name.");
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
ensureDevice(bucket.devices, device);
|
|
2892
|
+
const admin = values.shutdown != null ? statusUpDown(values.shutdown === true ? false : values.shutdown === false ? true : values.enabled) : statusUpDown(values.enabled);
|
|
2893
|
+
const speedNumber = numberLike(values.speed);
|
|
2894
|
+
bucket.interfaces.push(
|
|
2895
|
+
blankInterface(device, name, {
|
|
2896
|
+
description: textOf(values.description),
|
|
2897
|
+
adminStatus: admin === "up" || admin === "down" ? admin : "",
|
|
2898
|
+
speed: speedNumber != null ? formatRate(speedNumber, "bps") : textOf(values.speed),
|
|
2899
|
+
ipv4: cidrs(values.ipv4).filter((item) => !item.address.includes(":")),
|
|
2900
|
+
vrf: textOf(values.vrf)
|
|
2901
|
+
})
|
|
2902
|
+
);
|
|
2903
|
+
}
|
|
2904
|
+
function takeLink(values, warnings, pointer, bucket) {
|
|
2905
|
+
noteUnmapped(warnings, pointer, values, LINK_KEYS, "resource");
|
|
2906
|
+
const aDevice = textOf(values.a_device);
|
|
2907
|
+
const bDevice = textOf(values.b_device);
|
|
2908
|
+
const aInterface = textOf(values.a_interface);
|
|
2909
|
+
const bInterface = textOf(values.b_interface);
|
|
2910
|
+
if (!aDevice || !bDevice || !aInterface || !bInterface) {
|
|
2911
|
+
pushWarning(warnings, pointer, "Skipped a link resource that does not name both ends.");
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
ensureDevice(bucket.devices, aDevice);
|
|
2915
|
+
ensureDevice(bucket.devices, bDevice);
|
|
2916
|
+
bucket.links.push(blankLink(aDevice, aInterface, bDevice, bInterface, textOf(values.label)));
|
|
2917
|
+
}
|
|
2918
|
+
function takeVlan(values, warnings, pointer, bucket) {
|
|
2919
|
+
noteUnmapped(warnings, pointer, values, VLAN_KEYS, "resource");
|
|
2920
|
+
const id = vlanId(values.id ?? values.vid);
|
|
2921
|
+
if (id == null) return;
|
|
2922
|
+
bucket.vlans.push({ id, name: textOf(values.name) });
|
|
2923
|
+
}
|
|
2924
|
+
function walk(module, warnings, pointer, bucket, skipped) {
|
|
2925
|
+
const resources = Array.isArray(module.resources) ? module.resources : [];
|
|
2926
|
+
resources.forEach((resource, index) => {
|
|
2927
|
+
if (!isRecord(resource)) return;
|
|
2928
|
+
const path2 = `${pointer}/resources/${index}`;
|
|
2929
|
+
if (textOf(resource.mode) === "data") {
|
|
2930
|
+
pushWarning(warnings, path2, "Skipped a data source.");
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
if ("depends_on" in resource) pushWarning(warnings, path2, "depends_on is not a link.");
|
|
2934
|
+
const type = textOf(resource.type);
|
|
2935
|
+
const kind = SUPPORTED[type];
|
|
2936
|
+
if (!kind) {
|
|
2937
|
+
if (type && !skipped.has(type)) {
|
|
2938
|
+
skipped.add(type);
|
|
2939
|
+
pushWarning(warnings, path2, `Skipped unrecognized resource type "${type}".`);
|
|
2940
|
+
}
|
|
2941
|
+
return;
|
|
2942
|
+
}
|
|
2943
|
+
const raw = isRecord(resource.values) ? resource.values : {};
|
|
2944
|
+
const values = scrub(raw, resource.sensitive_values, warnings, path2);
|
|
2945
|
+
if (kind === "device") takeDevice(values, warnings, path2, bucket);
|
|
2946
|
+
if (kind === "interface") takeInterface(values, warnings, path2, bucket);
|
|
2947
|
+
if (kind === "link") takeLink(values, warnings, path2, bucket);
|
|
2948
|
+
if (kind === "vlan") takeVlan(values, warnings, path2, bucket);
|
|
2949
|
+
});
|
|
2950
|
+
const children = Array.isArray(module.child_modules) ? module.child_modules : [];
|
|
2951
|
+
children.forEach((child, index) => {
|
|
2952
|
+
if (isRecord(child)) walk(child, warnings, `${pointer}/child_modules/${index}`, bucket, skipped);
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2955
|
+
function convertTerraform(input) {
|
|
2956
|
+
if (!isRecord(input)) throw translatorFail(400, "A Terraform export must be a JSON object.");
|
|
2957
|
+
const warnings = [];
|
|
2958
|
+
if (!majorSupported(input.format_version, warnings)) {
|
|
2959
|
+
return {
|
|
2960
|
+
document: publishDocument({ devices: [], interfaces: [], links: [], vlans: [] }),
|
|
2961
|
+
warnings: sortWarnings(warnings)
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
const values = valuesOf(input, warnings);
|
|
2965
|
+
const root = values && isRecord(values.root_module) ? values.root_module : null;
|
|
2966
|
+
const bucket = { devices: [], interfaces: [], links: [], vlans: [] };
|
|
2967
|
+
if (!root) pushWarning(warnings, "", "This export has no root_module.");
|
|
2968
|
+
else walk(root, warnings, "/root_module", bucket, /* @__PURE__ */ new Set());
|
|
2969
|
+
const links = dedupeLinks(bucket.links);
|
|
2970
|
+
ensureLinkEnds(bucket.devices, bucket.interfaces, links);
|
|
2971
|
+
if (bucket.devices.length === 0) pushWarning(warnings, "", "No network devices were found in this export.");
|
|
2972
|
+
if (links.length === 0) pushWarning(warnings, "", "No links in this export. No links were created.");
|
|
2973
|
+
return {
|
|
2974
|
+
document: publishDocument({ devices: bucket.devices, interfaces: bucket.interfaces, links, vlans: bucket.vlans }),
|
|
2975
|
+
warnings: sortWarnings(warnings)
|
|
2976
|
+
};
|
|
2977
|
+
}
|
|
2978
|
+
var terraform = {
|
|
2979
|
+
id: "terraform",
|
|
2980
|
+
name: "Terraform",
|
|
2981
|
+
formatHint: "Saved terraform show -json state or plan",
|
|
2982
|
+
placeholder: `{
|
|
2983
|
+
"format_version": "1.0",
|
|
2984
|
+
"terraform_version": "1.9.0",
|
|
2985
|
+
"values": { "root_module": { "resources": [] } }
|
|
2986
|
+
}`,
|
|
2987
|
+
convert: convertTerraform
|
|
2988
|
+
};
|
|
2989
|
+
var terraform_default = terraform;
|
|
2990
|
+
|
|
2991
|
+
// server/src/translators/zabbix.ts
|
|
2992
|
+
var zabbix_exports = {};
|
|
2993
|
+
__export(zabbix_exports, {
|
|
2994
|
+
default: () => zabbix_default
|
|
2995
|
+
});
|
|
2996
|
+
var HOST_USED = /* @__PURE__ */ new Set(["hostid", "host", "name", "interfaces", "inventory", "status"]);
|
|
2997
|
+
var INTERFACE_USED5 = /* @__PURE__ */ new Set(["interfaceid", "hostid", "ip", "dns", "port", "main", "type", "useip"]);
|
|
2998
|
+
var INVENTORY_USED = /* @__PURE__ */ new Set(["os", "model", "type", "location", "site_city", "name", "vendor"]);
|
|
2999
|
+
var MAP_USED = /* @__PURE__ */ new Set(["sysmapid", "name", "selements", "links"]);
|
|
3000
|
+
var ELEMENT_USED = /* @__PURE__ */ new Set(["selementid", "elementtype", "elementid", "elements", "label"]);
|
|
3001
|
+
var LINK_USED4 = /* @__PURE__ */ new Set(["linkid", "selementid1", "selementid2", "label"]);
|
|
3002
|
+
var TYPE_LABEL = { "1": "agent", "2": "snmp", "3": "ipmi", "4": "jmx" };
|
|
3003
|
+
function code(value) {
|
|
3004
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
3005
|
+
return textOf(value);
|
|
3006
|
+
}
|
|
3007
|
+
function unwrap(value) {
|
|
3008
|
+
if (!isRecord(value)) return value;
|
|
3009
|
+
if ("result" in value && ("jsonrpc" in value || "id" in value)) return value.result;
|
|
3010
|
+
return value;
|
|
3011
|
+
}
|
|
3012
|
+
function listOf(value, keys) {
|
|
3013
|
+
const inner = unwrap(value);
|
|
3014
|
+
const section2 = sectionList(inner, [...keys, "result"]);
|
|
3015
|
+
if (section2.present && !section2.bad) return section2.items;
|
|
3016
|
+
if (Array.isArray(inner)) return inner;
|
|
3017
|
+
return [];
|
|
3018
|
+
}
|
|
3019
|
+
function interfaceLabel(row) {
|
|
3020
|
+
const kind = TYPE_LABEL[code(row.type)] ?? "interface";
|
|
3021
|
+
const address = textOf(row.ip) || textOf(row.dns) || "unknown";
|
|
3022
|
+
const port = textOf(row.port);
|
|
3023
|
+
return port ? `${kind} ${address}:${port}` : `${kind} ${address}`;
|
|
3024
|
+
}
|
|
3025
|
+
function mainScore(row) {
|
|
3026
|
+
const main = code(row.main) === "1" ? 10 : 0;
|
|
3027
|
+
const type = code(row.type);
|
|
3028
|
+
const preference = type === "2" ? 3 : type === "1" ? 2 : 1;
|
|
3029
|
+
return main + preference;
|
|
3030
|
+
}
|
|
3031
|
+
function mapHosts(items, warnings) {
|
|
3032
|
+
const devices = [];
|
|
3033
|
+
const interfaces = [];
|
|
3034
|
+
const byId = /* @__PURE__ */ new Map();
|
|
3035
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3036
|
+
items.forEach((item, index) => {
|
|
3037
|
+
const pointer = `/hosts/${index}`;
|
|
3038
|
+
if (!isRecord(item)) return;
|
|
3039
|
+
noteUnmapped(warnings, pointer, item, HOST_USED, "host");
|
|
3040
|
+
const visible = textOf(item.name);
|
|
3041
|
+
const technical = textOf(item.host);
|
|
3042
|
+
const name = visible || technical;
|
|
3043
|
+
if (!name || seen.has(name.toLowerCase())) return;
|
|
3044
|
+
seen.add(name.toLowerCase());
|
|
3045
|
+
const inventory = isRecord(item.inventory) ? item.inventory : null;
|
|
3046
|
+
if (inventory) noteUnmapped(warnings, `${pointer}/inventory`, inventory, INVENTORY_USED, "inventory");
|
|
3047
|
+
const hostInterfaces = Array.isArray(item.interfaces) ? item.interfaces.filter(isRecord) : [];
|
|
3048
|
+
const ranked = [...hostInterfaces].sort((a, b) => mainScore(b) - mainScore(a));
|
|
3049
|
+
const primary = ranked[0];
|
|
3050
|
+
devices.push(
|
|
3051
|
+
blankDevice(name, {
|
|
3052
|
+
managementIp: primary ? hostAddress(primary.ip) : "",
|
|
3053
|
+
platform: inventory ? textOf(inventory.os) : "",
|
|
3054
|
+
model: inventory ? textOf(inventory.model) : "",
|
|
3055
|
+
role: inventory ? textOf(inventory.type) : "",
|
|
3056
|
+
site: inventory ? textOf(inventory.location) || textOf(inventory.site_city) : ""
|
|
3057
|
+
})
|
|
3058
|
+
);
|
|
3059
|
+
let primaryName = "";
|
|
3060
|
+
hostInterfaces.forEach((row) => {
|
|
3061
|
+
noteUnmapped(warnings, `${pointer}/interfaces`, row, INTERFACE_USED5, "host interface");
|
|
3062
|
+
const label = interfaceLabel(row);
|
|
3063
|
+
interfaces.push(blankInterface(name, label));
|
|
3064
|
+
if (!primaryName && primary && row === primary) primaryName = label;
|
|
3065
|
+
});
|
|
3066
|
+
if (!primaryName) {
|
|
3067
|
+
primaryName = "zabbix";
|
|
3068
|
+
interfaces.push(blankInterface(name, primaryName));
|
|
3069
|
+
pushWarning(warnings, pointer, `Host ${name} has no Zabbix interface, so map links use the name "zabbix".`);
|
|
3070
|
+
}
|
|
3071
|
+
const id = idKey(item.hostid);
|
|
3072
|
+
if (id) byId.set(id, { name, iface: primaryName });
|
|
3073
|
+
});
|
|
3074
|
+
return { devices, interfaces, byId };
|
|
3075
|
+
}
|
|
3076
|
+
function hostFromElement(element, hosts) {
|
|
3077
|
+
const type = code(element.elementtype);
|
|
3078
|
+
if (type && type !== "0") return null;
|
|
3079
|
+
const direct = hosts.get(idKey(element.elementid));
|
|
3080
|
+
if (direct) return direct;
|
|
3081
|
+
if (Array.isArray(element.elements)) {
|
|
3082
|
+
for (const entry of element.elements) {
|
|
3083
|
+
if (!isRecord(entry)) continue;
|
|
3084
|
+
const found = hosts.get(idKey(entry.hostid));
|
|
3085
|
+
if (found) return found;
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
return null;
|
|
3089
|
+
}
|
|
3090
|
+
function mapLinks4(maps, hosts, warnings) {
|
|
3091
|
+
const links = [];
|
|
3092
|
+
maps.forEach((map, mapIndex) => {
|
|
3093
|
+
if (!isRecord(map)) return;
|
|
3094
|
+
noteUnmapped(warnings, `/maps/${mapIndex}`, map, MAP_USED, "map");
|
|
3095
|
+
const elements = /* @__PURE__ */ new Map();
|
|
3096
|
+
const selements = Array.isArray(map.selements) ? map.selements : [];
|
|
3097
|
+
selements.forEach((element, index) => {
|
|
3098
|
+
if (!isRecord(element)) return;
|
|
3099
|
+
noteUnmapped(warnings, `/maps/${mapIndex}/selements/${index}`, element, ELEMENT_USED, "map element");
|
|
3100
|
+
const host = hostFromElement(element, hosts);
|
|
3101
|
+
const id = idKey(element.selementid);
|
|
3102
|
+
if (host && id) elements.set(id, host);
|
|
3103
|
+
});
|
|
3104
|
+
const rows6 = Array.isArray(map.links) ? map.links : [];
|
|
3105
|
+
rows6.forEach((row, index) => {
|
|
3106
|
+
const pointer = `/maps/${mapIndex}/links/${index}`;
|
|
3107
|
+
if (!isRecord(row)) return;
|
|
3108
|
+
noteUnmapped(warnings, pointer, row, LINK_USED4, "map link");
|
|
3109
|
+
const a = elements.get(idKey(row.selementid1));
|
|
3110
|
+
const b = elements.get(idKey(row.selementid2));
|
|
3111
|
+
if (!a || !b) {
|
|
3112
|
+
pushWarning(warnings, pointer, "Skipped a map link that does not join two hosts in this export.");
|
|
3113
|
+
return;
|
|
3114
|
+
}
|
|
3115
|
+
links.push(blankLink(a.name, a.iface, b.name, b.iface, textOf(row.label)));
|
|
3116
|
+
});
|
|
3117
|
+
});
|
|
3118
|
+
return dedupeLinks(links);
|
|
3119
|
+
}
|
|
3120
|
+
function convertZabbix(input) {
|
|
3121
|
+
if (!isRecord(input) && !Array.isArray(input)) throw translatorFail(400, "A Zabbix export must be a JSON object or array.");
|
|
3122
|
+
const warnings = [];
|
|
3123
|
+
const root = isRecord(input) ? input : { hosts: input };
|
|
3124
|
+
const hostItems = listOf(root.hosts ?? root.result ?? (Array.isArray(input) ? input : root), ["hosts"]);
|
|
3125
|
+
const extraInterfaces = listOf(root.interfaces, ["interfaces"]);
|
|
3126
|
+
const hosts = mapHosts(hostItems, warnings);
|
|
3127
|
+
if (extraInterfaces.length > 0 && hosts.interfaces.length === 0) {
|
|
3128
|
+
pushWarning(warnings, "/interfaces", "Host interfaces were separate from hosts, so they were not joined.");
|
|
3129
|
+
}
|
|
3130
|
+
const maps = listOf(root.maps ?? root.map, ["maps", "map"]);
|
|
3131
|
+
const links = mapLinks4(maps, hosts.byId, warnings);
|
|
3132
|
+
ensureLinkEnds(hosts.devices, hosts.interfaces, links);
|
|
3133
|
+
if (links.length === 0) {
|
|
3134
|
+
pushWarning(
|
|
3135
|
+
warnings,
|
|
3136
|
+
"",
|
|
3137
|
+
"No links in this export. No links were created. Zabbix host inventory is not a topology."
|
|
3138
|
+
);
|
|
3139
|
+
}
|
|
3140
|
+
return {
|
|
3141
|
+
document: publishDocument({ devices: hosts.devices, interfaces: hosts.interfaces, links, vlans: [] }),
|
|
3142
|
+
warnings: sortWarnings(warnings)
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
var zabbix = {
|
|
3146
|
+
id: "zabbix",
|
|
3147
|
+
name: "Zabbix",
|
|
3148
|
+
formatHint: "Saved Zabbix host.get JSON, with an optional map.get topology",
|
|
3149
|
+
placeholder: `{
|
|
3150
|
+
"jsonrpc": "2.0",
|
|
3151
|
+
"result": [ { "hostid": "1", "host": "core-rtr", "name": "core-rtr", "interfaces": [], "inventory": {} } ],
|
|
3152
|
+
"id": 1
|
|
3153
|
+
}`,
|
|
3154
|
+
convert: convertZabbix
|
|
3155
|
+
};
|
|
3156
|
+
var zabbix_default = zabbix;
|
|
3157
|
+
|
|
3158
|
+
// server/src/translators/bundled.ts
|
|
3159
|
+
function take(mod, file) {
|
|
3160
|
+
const value = mod.default;
|
|
3161
|
+
if (!value || typeof value !== "object" || !(typeof value.convert === "function") || typeof value.id !== "string") {
|
|
3162
|
+
throw new Error(file + " must default-export a module.");
|
|
3163
|
+
}
|
|
3164
|
+
return value;
|
|
3165
|
+
}
|
|
3166
|
+
var bundledTranslators = [take(batfish_exports, "batfish.ts"), take(catalyst_center_exports, "catalyst-center.ts"), take(librenms_exports, "librenms.ts"), take(meraki_exports, "meraki.ts"), take(nautobot_exports, "nautobot.ts"), take(netbox_exports, "netbox.ts"), take(netdisco_exports, "netdisco.ts"), take(observium_exports, "observium.ts"), take(orion_exports, "orion.ts"), take(prtg_exports, "prtg.ts"), take(pyats_exports, "pyats.ts"), take(terraform_exports, "terraform.ts"), take(zabbix_exports, "zabbix.ts")];
|
|
3167
|
+
|
|
3168
|
+
// server/src/translators/registry.ts
|
|
3169
|
+
var INFRA = new Set(TRANSLATOR_INFRA);
|
|
3170
|
+
var ID_RE = /^[a-z][a-z0-9-]*$/;
|
|
3171
|
+
var here = path.dirname(fileURLToPath(import.meta.url));
|
|
3172
|
+
function translatorBasenames(fileNames) {
|
|
3173
|
+
const bases = /* @__PURE__ */ new Set();
|
|
3174
|
+
for (const name of fileNames) {
|
|
3175
|
+
const baseName = name.split(/[\\/]/).pop() ?? name;
|
|
3176
|
+
if (!baseName || baseName.endsWith(".d.ts")) continue;
|
|
3177
|
+
const match = /^(.*)\.(?:ts|js|mjs|cjs)$/.exec(baseName);
|
|
3178
|
+
if (!match) continue;
|
|
3179
|
+
const base = match[1] ?? "";
|
|
3180
|
+
if (!base || base.endsWith(".test") || INFRA.has(base)) continue;
|
|
3181
|
+
bases.add(base);
|
|
3182
|
+
}
|
|
3183
|
+
return [...bases].sort();
|
|
3184
|
+
}
|
|
3185
|
+
function assertTranslatorModule(value, label) {
|
|
3186
|
+
if (!value || typeof value !== "object") throw new Error(`${label} must default-export a translator.`);
|
|
3187
|
+
const item = value;
|
|
3188
|
+
if (typeof item.id !== "string" || !ID_RE.test(item.id)) {
|
|
3189
|
+
throw new Error(`${label} needs an id of lowercase letters, numbers, and hyphens.`);
|
|
3190
|
+
}
|
|
3191
|
+
if (typeof item.name !== "string" || !item.name.trim()) throw new Error(`${label} needs a display name.`);
|
|
3192
|
+
if (typeof item.formatHint !== "string" || !item.formatHint.trim()) throw new Error(`${label} needs a formatHint.`);
|
|
3193
|
+
if (typeof item.placeholder !== "string" || !item.placeholder.trim()) throw new Error(`${label} needs a placeholder.`);
|
|
3194
|
+
if (typeof item.convert !== "function") throw new Error(`${label} needs a convert function.`);
|
|
3195
|
+
return {
|
|
3196
|
+
id: item.id,
|
|
3197
|
+
name: item.name.trim(),
|
|
3198
|
+
formatHint: item.formatHint.trim(),
|
|
3199
|
+
placeholder: item.placeholder,
|
|
3200
|
+
convert: item.convert
|
|
3201
|
+
};
|
|
3202
|
+
}
|
|
3203
|
+
function sortModules(modules) {
|
|
3204
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3205
|
+
const sorted = [...modules].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
3206
|
+
for (const item of sorted) {
|
|
3207
|
+
if (seen.has(item.id)) throw new Error(`Translator id "${item.id}" is registered more than once.`);
|
|
3208
|
+
seen.add(item.id);
|
|
3209
|
+
}
|
|
3210
|
+
return sorted;
|
|
3211
|
+
}
|
|
3212
|
+
async function loadFromDirectory() {
|
|
3213
|
+
let loaders = null;
|
|
3214
|
+
try {
|
|
3215
|
+
loaders = import.meta.glob("./*.ts");
|
|
3216
|
+
} catch {
|
|
3217
|
+
loaders = null;
|
|
3218
|
+
}
|
|
3219
|
+
const modules = [];
|
|
3220
|
+
if (loaders && typeof loaders === "object") {
|
|
3221
|
+
for (const [key, load2] of Object.entries(loaders)) {
|
|
3222
|
+
if (translatorBasenames([key]).length === 0) continue;
|
|
3223
|
+
const loaded = await load2();
|
|
3224
|
+
modules.push(assertTranslatorModule(loaded.default, key));
|
|
3225
|
+
}
|
|
3226
|
+
if (modules.length > 0 || Object.keys(loaders).length > 0) return sortModules(modules);
|
|
3227
|
+
}
|
|
3228
|
+
const names = await readdir(here);
|
|
3229
|
+
const load = new Function("specifier", "return import(specifier)");
|
|
3230
|
+
for (const base of translatorBasenames(names)) {
|
|
3231
|
+
const specifier = new URL(`./${base}.js`, import.meta.url).href;
|
|
3232
|
+
const loaded = await load(specifier);
|
|
3233
|
+
modules.push(assertTranslatorModule(loaded.default, `${base}.js`));
|
|
3234
|
+
}
|
|
3235
|
+
return sortModules(modules);
|
|
3236
|
+
}
|
|
3237
|
+
var cache = null;
|
|
3238
|
+
var pending = null;
|
|
3239
|
+
function loadedTranslatorIds() {
|
|
3240
|
+
return cache ? cache.map((item) => item.id) : [];
|
|
3241
|
+
}
|
|
3242
|
+
function loadTranslators() {
|
|
3243
|
+
if (cache) return Promise.resolve(cache);
|
|
3244
|
+
if (bundledTranslators) {
|
|
3245
|
+
cache = sortModules(bundledTranslators.map((item) => assertTranslatorModule(item, item.id)));
|
|
3246
|
+
return Promise.resolve(cache);
|
|
3247
|
+
}
|
|
3248
|
+
pending ??= loadFromDirectory().then((modules) => {
|
|
3249
|
+
cache = modules;
|
|
3250
|
+
return modules;
|
|
3251
|
+
});
|
|
3252
|
+
return pending;
|
|
3253
|
+
}
|
|
3254
|
+
async function translatorById(id) {
|
|
3255
|
+
const modules = await loadTranslators();
|
|
3256
|
+
return modules.find((item) => item.id === id);
|
|
3257
|
+
}
|
|
3258
|
+
async function listTranslatorInfo() {
|
|
3259
|
+
const modules = await loadTranslators();
|
|
3260
|
+
return modules.map((item) => ({
|
|
3261
|
+
id: item.id,
|
|
3262
|
+
name: item.name,
|
|
3263
|
+
formatHint: item.formatHint,
|
|
3264
|
+
placeholder: item.placeholder
|
|
3265
|
+
}));
|
|
3266
|
+
}
|
|
3267
|
+
function translatorDirectory() {
|
|
3268
|
+
return here;
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
// server/src/translators/run.ts
|
|
3272
|
+
function parseExport(text) {
|
|
3273
|
+
const trimmed = text.replace(/^\uFEFF/, "").trim();
|
|
3274
|
+
if (!trimmed) throw translatorFail(400, "The export is empty.");
|
|
3275
|
+
try {
|
|
3276
|
+
return JSON.parse(trimmed);
|
|
3277
|
+
} catch {
|
|
3278
|
+
}
|
|
3279
|
+
try {
|
|
3280
|
+
const parsed = parseYaml(trimmed);
|
|
3281
|
+
if (parsed && typeof parsed === "object") return parsed;
|
|
3282
|
+
} catch {
|
|
3283
|
+
}
|
|
3284
|
+
throw translatorFail(400, "The export is not valid JSON.");
|
|
3285
|
+
}
|
|
3286
|
+
async function convertExport(id, input) {
|
|
3287
|
+
const source = id.trim().toLowerCase();
|
|
3288
|
+
const translator = await translatorById(source);
|
|
3289
|
+
if (!translator) {
|
|
3290
|
+
const installed = (await loadTranslators()).map((item) => item.id);
|
|
3291
|
+
const known = installed.length > 0 ? installed.join(", ") : "(none)";
|
|
3292
|
+
throw translatorFail(404, `Unknown translator "${source}". Installed translators: ${known}.`, "not_found");
|
|
3293
|
+
}
|
|
3294
|
+
let result;
|
|
3295
|
+
try {
|
|
3296
|
+
result = translator.convert(input);
|
|
3297
|
+
} catch (err) {
|
|
3298
|
+
if (err && typeof err === "object" && "status" in err) throw err;
|
|
3299
|
+
const message = err instanceof Error ? err.message : "Convert failed.";
|
|
3300
|
+
throw translatorFail(400, message);
|
|
3301
|
+
}
|
|
3302
|
+
if (!result || typeof result !== "object" || !Array.isArray(result.warnings)) {
|
|
3303
|
+
throw translatorFail(500, `Translator "${translator.id}" did not return a document.`);
|
|
3304
|
+
}
|
|
3305
|
+
const validated = validateNetwork(result.document);
|
|
3306
|
+
if (!validated.document) {
|
|
3307
|
+
throw translatorFail(500, `Translator "${translator.id}" produced a document that does not match the network schema.`, "invalid");
|
|
3308
|
+
}
|
|
3309
|
+
return {
|
|
3310
|
+
source: translator.id,
|
|
3311
|
+
document: publishDocument(validated.document),
|
|
3312
|
+
warnings: sortWarnings(result.warnings)
|
|
3313
|
+
};
|
|
3314
|
+
}
|
|
3315
|
+
async function installedTranslators() {
|
|
3316
|
+
return listTranslatorInfo();
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3319
|
+
// server/src/translators/request.ts
|
|
3320
|
+
var UPSERT_KEYS = ["path", "view", "includeDown", "vlan", "groupBy", "direction", "title", "storeData", "dataName", "grouping"];
|
|
3321
|
+
function queryString(value) {
|
|
3322
|
+
if (typeof value === "string") return value;
|
|
3323
|
+
if (Array.isArray(value) && typeof value[0] === "string") return value[0];
|
|
3324
|
+
return void 0;
|
|
3325
|
+
}
|
|
3326
|
+
function hasOwn(record, key) {
|
|
3327
|
+
return Object.prototype.hasOwnProperty.call(record, key);
|
|
3328
|
+
}
|
|
3329
|
+
async function prepareConvert(options) {
|
|
3330
|
+
assertConvertInputSize(options.bytes);
|
|
3331
|
+
const query = options.query ?? {};
|
|
3332
|
+
const queryPath = queryString(query.path)?.trim();
|
|
3333
|
+
const queryView = queryString(query.view)?.trim();
|
|
3334
|
+
const record = isRecord(options.body) ? options.body : null;
|
|
3335
|
+
const bodySignal = record != null && UPSERT_KEYS.some((key) => hasOwn(record, key) && record[key] != null);
|
|
3336
|
+
const signal = Boolean(queryPath || queryView || bodySignal);
|
|
3337
|
+
let input = options.body;
|
|
3338
|
+
let fields = {};
|
|
3339
|
+
if (record && signal && hasOwn(record, "input")) {
|
|
3340
|
+
input = record.input;
|
|
3341
|
+
fields = record;
|
|
3342
|
+
} else if (record && signal && typeof record.text === "string") {
|
|
3343
|
+
input = parseExport(record.text);
|
|
3344
|
+
fields = record;
|
|
3345
|
+
}
|
|
3346
|
+
const pathValue = queryPath || (typeof fields.path === "string" ? fields.path.trim() : "");
|
|
3347
|
+
const view = queryView || (typeof fields.view === "string" ? fields.view.trim() : "");
|
|
3348
|
+
if ((pathValue || view) && !options.canWrite) {
|
|
3349
|
+
throw translatorFail(403, "This token cannot write.", "forbidden");
|
|
3350
|
+
}
|
|
3351
|
+
if (pathValue || view) {
|
|
3352
|
+
if (!pathValue) throw translatorFail(400, "path is required.");
|
|
3353
|
+
if (view !== "l3" && view !== "l2") throw translatorFail(400, "view must be l3 or l2.");
|
|
3354
|
+
}
|
|
3355
|
+
const converted = await convertExport(options.source, input);
|
|
3356
|
+
if (!pathValue) return { body: converted };
|
|
3357
|
+
const includeDown = fields.includeDown;
|
|
3358
|
+
const vlan = fields.vlan;
|
|
3359
|
+
const groupBy = typeof fields.groupBy === "string" ? fields.groupBy : queryString(query.groupBy);
|
|
3360
|
+
const direction = typeof fields.direction === "string" ? fields.direction : void 0;
|
|
3361
|
+
const title = typeof fields.title === "string" ? fields.title : void 0;
|
|
3362
|
+
const storeData = typeof fields.storeData === "boolean" ? fields.storeData : void 0;
|
|
3363
|
+
const dataName = typeof fields.dataName === "string" ? fields.dataName : void 0;
|
|
3364
|
+
const grouping = typeof fields.grouping === "boolean" ? fields.grouping : void 0;
|
|
3365
|
+
const imported = importInputFromBody({
|
|
3366
|
+
text: JSON.stringify(converted.document),
|
|
3367
|
+
format: "network",
|
|
3368
|
+
view,
|
|
3369
|
+
...includeDown != null ? { includeDown } : {},
|
|
3370
|
+
...vlan != null ? { vlan } : {},
|
|
3371
|
+
...groupBy ? { groupBy } : {},
|
|
3372
|
+
...direction ? { direction } : {},
|
|
3373
|
+
...title ? { title } : {},
|
|
3374
|
+
...grouping != null ? { grouping } : {}
|
|
3375
|
+
});
|
|
3376
|
+
const upsert = { ...imported, path: pathValue };
|
|
3377
|
+
if (storeData != null) upsert.storeData = storeData;
|
|
3378
|
+
if (dataName != null) upsert.dataName = dataName;
|
|
3379
|
+
return { body: converted, upsert };
|
|
3380
|
+
}
|
|
3381
|
+
export {
|
|
3382
|
+
CONVERT_MAX_INPUT_BYTES,
|
|
3383
|
+
TRANSLATOR_INFRA,
|
|
3384
|
+
assertConvertInputSize,
|
|
3385
|
+
assertTranslatorModule,
|
|
3386
|
+
convertExport,
|
|
3387
|
+
installedTranslators,
|
|
3388
|
+
listTranslatorInfo,
|
|
3389
|
+
loadTranslators,
|
|
3390
|
+
loadedTranslatorIds,
|
|
3391
|
+
parseExport,
|
|
3392
|
+
prepareConvert,
|
|
3393
|
+
translatorBasenames,
|
|
3394
|
+
translatorById,
|
|
3395
|
+
translatorDirectory
|
|
3396
|
+
};
|