Skip to content

Commit 4197f2f

Browse files
committed
[arista-switch] improve logging
1 parent 1117a26 commit 4197f2f

24 files changed

Lines changed: 59 additions & 59 deletions

src/modules/arista-switch/TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
- use bulkwrite in workers to improve db performance
2-
- remove filename from all log actions......
31
- add heartbeat status check and worker task

src/modules/arista-switch/container/services/device-save.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = async () => {
1111
throw new Error("failed to load config");
1212
}
1313

14-
logger.info("device-save: saving device config ...");
14+
logger.info("saving device config ...");
1515

1616
await aristaApi({
1717
host: config.address,
@@ -22,10 +22,10 @@ module.exports = async () => {
2222
commands: ["enable", "write memory"],
2323
});
2424

25-
logger.info("device-save: success");
25+
logger.info("success");
2626

2727
} catch (err) {
28-
err.message = `device-save: ${err.stack || err.message}`;
28+
err.message = `${err.stack || err.message}`;
2929
logger.error(err.message);
3030
throw err;
3131
}

src/modules/arista-switch/container/services/interface-disable.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = async (interfaceId) => {
1313
throw new Error("failed to load config");
1414
}
1515

16-
logger.info(`interface-disable: disabling interface ${interfaceId} ...`);
16+
logger.info(`disabling interface ${interfaceId} ...`);
1717

1818
// disable the interface on the device
1919
await aristaApi({
@@ -25,7 +25,7 @@ module.exports = async (interfaceId) => {
2525
commands: ["enable", "configure", `interface ${interfaceId}`, "shutdown"],
2626
});
2727

28-
logger.info(`interface-disable: success - updating DB`);
28+
logger.info(`success - updating DB`);
2929

3030
// update the DB to reflect disabled interface
3131
const interfacesCollection = await mongoCollection("interfaces");
@@ -34,7 +34,7 @@ module.exports = async (interfaceId) => {
3434
{ $set: { linkStatus: "disabled" } }
3535
);
3636

37-
logger.info(`interface-disable: ${JSON.stringify(dbResult.result)}`);
37+
logger.info(`${JSON.stringify(dbResult.result)}`);
3838
await deviceSetPending(false);
3939
return true;
4040

src/modules/arista-switch/container/services/interface-enable.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = async (interfaceId) => {
1313
throw new Error("failed to load config");
1414
}
1515

16-
logger.info(`interface-enable: enabling interface ${interfaceId} ...`);
16+
logger.info(`enabling interface ${interfaceId} ...`);
1717

1818
// enable the interface on the device
1919
await aristaApi({
@@ -25,7 +25,7 @@ module.exports = async (interfaceId) => {
2525
commands: ["enable", "configure", `interface ${interfaceId}`, "no shutdown"],
2626
});
2727

28-
logger.info(`interface-enable: success - updating DB`);
28+
logger.info(`success - updating DB`);
2929

3030
// update the DB to reflect enabled interface
3131
const interfacesCollection = await mongoCollection("interfaces");
@@ -43,7 +43,7 @@ module.exports = async (interfaceId) => {
4343
{ $set: { linkStatus } }
4444
);
4545

46-
logger.info(`interface-enable: ${JSON.stringify(dbResult.result)}`);
46+
logger.info(`${JSON.stringify(dbResult.result)}`);
4747
await deviceSetPending(false);
4848
return true;
4949

src/modules/arista-switch/container/services/interface-poe.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = async (interfaceId, action) => {
2222
}
2323

2424
const actionText = action === "enable" ? "enabling" : "disabling";
25-
logger.info(`interface-poe: ${actionText} POE on interface ${interfaceId} ...`);
25+
logger.info(`${actionText} POE on interface ${interfaceId} ...`);
2626

2727
await aristaApi({
2828
host: config.address,
@@ -38,15 +38,15 @@ module.exports = async (interfaceId, action) => {
3838
],
3939
});
4040

41-
logger.info(`interface-poe: success - updating DB`);
41+
logger.info(`success - updating DB`);
4242

4343
const interfacesCollection = await mongoCollection("interfaces");
4444
const dbResult = await interfacesCollection.updateOne(
4545
{ interfaceId },
4646
{ $set: { "poe.enabled": action === "enable" } }
4747
);
4848

49-
logger.info(`interface-poe: ${JSON.stringify(dbResult.result)}`);
49+
logger.info(`${JSON.stringify(dbResult.result)}`);
5050

5151
if (dbResult.matchedCount !== 1) {
5252
throw new Error(`expected to update 1 interface in DB, matched ${dbResult.matchedCount}`);

src/modules/arista-switch/container/services/interface-protect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = async (interfaceId) => {
1717
throw new Error(`interface ${interfaceId} already protected`);
1818
}
1919

20-
logger.info(`interface-protect: protecting interface ${interfaceId}`);
20+
logger.info(`protecting interface ${interfaceId}`);
2121
config.protectedInterfaces.push(interfaceId);
2222

2323
return await configPutViaCore(config);

src/modules/arista-switch/container/services/interface-rename.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = async (interfaceId, newName) => {
1313
throw new Error("failed to load config");
1414
}
1515

16-
logger.info(`interface-rename: renaming interface ${interfaceId} to '${newName}' ...`);
16+
logger.info(`renaming interface ${interfaceId} to '${newName}' ...`);
1717

1818
const descriptionCommand = newName ? `description ${newName}` : "no description";
1919

@@ -27,7 +27,7 @@ module.exports = async (interfaceId, newName) => {
2727
commands: ["enable", "configure", `interface ${interfaceId}`, descriptionCommand],
2828
});
2929

30-
logger.info(`interface-rename: success - updating DB`);
30+
logger.info(`success - updating DB`);
3131

3232
// update DB
3333
const interfacesCollection = await mongoCollection("interfaces");
@@ -36,12 +36,12 @@ module.exports = async (interfaceId, newName) => {
3636
{ $set: { description: newName } }
3737
);
3838

39-
logger.info(`interface-rename: ${JSON.stringify(dbResult.result)}`);
39+
logger.info(`${JSON.stringify(dbResult.result)}`);
4040
await deviceSetPending(false);
4141
return true;
4242

4343
} catch (err) {
44-
err.message = `interface-rename: ${err.stack || err.message}`;
44+
err.message = `${err.stack || err.message}`;
4545
logger.error(err.message);
4646
throw err;
4747
}

src/modules/arista-switch/container/services/interface-setvlanaccess.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = async (interfaceId, untaggedVlan = "1") => {
1313
throw new Error("failed to load config");
1414
}
1515

16-
logger.info(`interface-setvlanaccess: setting vlan ${untaggedVlan} on interface ${interfaceId}`);
16+
logger.info(`setting vlan ${untaggedVlan} on interface ${interfaceId}`);
1717

1818
const interfaceCollection = await mongoCollection("interfaces");
1919
const iface = await interfaceCollection.findOne({ interfaceId: interfaceId });
@@ -25,7 +25,7 @@ module.exports = async (interfaceId, untaggedVlan = "1") => {
2525

2626
// if the interface is currently in trunk mode, change it
2727
if (iface.mode === "trunk") {
28-
logger.info(`interface-setvlanaccess: interface ${interfaceId} is in trunk mode, changing to access`);
28+
logger.info(`interface ${interfaceId} is in trunk mode, changing to access`);
2929
commands.push("no switchport trunk native vlan");
3030
commands.push("switchport mode access");
3131
}
@@ -42,14 +42,14 @@ module.exports = async (interfaceId, untaggedVlan = "1") => {
4242
commands: commands,
4343
});
4444

45-
logger.info(`interface-setvlanaccess: success - updating DB`);
45+
logger.info(`success - updating DB`);
4646

4747
// update db
4848
const dbResult = await interfaceCollection.updateOne(
4949
{ interfaceId: interfaceId },
5050
{ $set: { mode: "access", accessVlanId: parseInt(untaggedVlan) } }
5151
);
52-
logger.info(`interface-setvlanaccess: ${JSON.stringify(dbResult.result)}`);
52+
logger.info(`${JSON.stringify(dbResult.result)}`);
5353
await deviceSetPending(false);
5454
return true;
5555
} catch (error) {

src/modules/arista-switch/container/services/interface-setvlantrunk.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = async (interfaceId, untaggedVlan = 1, taggedVlans = []) => {
1919
if (!iface) {
2020
throw new Error(`interface ${interfaceId} not found`);
2121
}
22-
logger.info(`interface-setvlantrunk: interface ${interfaceId} found in db`);
22+
logger.info(`interface ${interfaceId} found in db`);
2323

2424
// so ... arista uses the word 'ALL' whereas the bug UI controls deliver '1-4094'
2525
// we need to convert
@@ -36,7 +36,7 @@ module.exports = async (interfaceId, untaggedVlan = 1, taggedVlans = []) => {
3636
`switchport trunk native vlan ${untaggedVlan}`,
3737
];
3838

39-
logger.info(`interface-setvlantrunk: setting vlan ${untaggedVlan} on interface ${interfaceId}`);
39+
logger.info(`setting vlan ${untaggedVlan} on interface ${interfaceId}`);
4040

4141
if (taggedVlans !== "ALL") {
4242
commands.push(`switchport trunk allowed vlan ${taggedVlans.join(",")}`);
@@ -52,7 +52,7 @@ module.exports = async (interfaceId, untaggedVlan = 1, taggedVlans = []) => {
5252
commands: commands,
5353
});
5454

55-
logger.info(`interface-setvlantrunk: success - updating DB`);
55+
logger.info(`success - updating DB`);
5656

5757
// we're going to break out any ranges or 'ALL's into an array of desired vlans
5858
const dataToSet = {
@@ -63,7 +63,7 @@ module.exports = async (interfaceId, untaggedVlan = 1, taggedVlans = []) => {
6363
logger.info("dataToSet", dataToSet);
6464
// update db
6565
const dbResult = await interfaceCollection.updateOne({ interfaceId: interfaceId }, { $set: dataToSet });
66-
logger.info(`interface-setvlantrunk: ${JSON.stringify(dbResult.result)}`);
66+
logger.info(`${JSON.stringify(dbResult.result)}`);
6767
await deviceSetPending(false);
6868
return true;
6969
} catch (error) {

src/modules/arista-switch/container/services/interface-unprotect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = async (interfaceId) => {
1717
throw new Error(`cannot find interface ${interfaceId}`);
1818
}
1919

20-
logger.info(`interface-unprotect: unprotecting interface ${interfaceId}`);
20+
logger.info(`unprotecting interface ${interfaceId}`);
2121
config.protectedInterfaces = config.protectedInterfaces.filter(item => item !== interfaceId);
2222

2323
return await configPutViaCore(config);

0 commit comments

Comments
 (0)