-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-lldp-variants.mjs
More file actions
34 lines (28 loc) · 1.31 KB
/
fix-lldp-variants.mjs
File metadata and controls
34 lines (28 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from 'fs';
const file = 'server.js';
let content = fs.readFileSync(file, 'utf8');
const oldCode = ` } else {
// Porta access - check LLDP
const lldpOut = await runSwitchCommand(currentIp, sshCreds, coreFallback, \`display lldp neighbor interface \${ifName}\`, sshCredsAlt);
const lldpInfo = parseLldpFullInfo(lldpOut);
if (lldpInfo && isLldpManagedSwitch(lldpInfo)) {`;
const newCode = ` } else {
// Porta access - check LLDP con varianti nome interfaccia
let lldpOut = '';
let lldpInfo = null;
const variants = interfaceCommandVariants(ifName);
for (const v of variants) {
lldpOut = await runSwitchCommand(currentIp, sshCreds, coreFallback, \`display lldp neighbor interface \${v}\`, sshCredsAlt);
if (lldpOut && lldpOut.length > 100) {
lldpInfo = parseLldpFullInfo(lldpOut);
if (lldpInfo && (lldpInfo.name || lldpInfo.ip)) break;
}
}
if (lldpInfo && isLldpManagedSwitch(lldpInfo)) {`;
if (content.includes(oldCode)) {
content = content.replace(oldCode, newCode);
fs.writeFileSync(file, content);
console.log('✓ Fix LLDP variants applicato');
} else {
console.log('⚠ Pattern non trovato');
}