Skip to content

Commit

Permalink
Merge pull request #205 from bbc/arista-power-fix
Browse files Browse the repository at this point in the history
arista-switch: add check for power supply
  • Loading branch information
geoffhouse authored Mar 8, 2024
2 parents 9a439cf + 6254da7 commit 1fe7c27
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/modules/arista-switch/container/services/status-checkpower.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

const StatusItem = require("@core/StatusItem");
const mongoSingle = require("@core/mongo-single");

module.exports = async () => {
const power = await mongoSingle.get("power");
const statusItems = [];

for (const [key, value] of Object.entries(power)) {
if (value.state === "powerLoss") {
statusItems.push(
new StatusItem({
key: `power${key}`,
message: [`Power supply ${key} has failed`],
type: "warning",
})
);
}
}

return statusItems;
};
4 changes: 3 additions & 1 deletion src/modules/arista-switch/container/services/status-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const statusCheckCollection = require("@core/status-checkcollection");
const statusCheckPending = require("@services/status-checkpending");
const statusCheckInterfaceStatus = require("@services/status-checkinterfacestatus");
const statusCheckSfps = require("@services/status-checksfps");
const statusCheckPower = require("@services/status-checkpower");

module.exports = async () => {
return [].concat(
Expand All @@ -28,6 +29,7 @@ module.exports = async () => {
}),
await statusCheckPending(),
await statusCheckInterfaceStatus(),
await statusCheckSfps()
await statusCheckSfps(),
await statusCheckPower()
);
};
15 changes: 13 additions & 2 deletions src/modules/arista-switch/container/workers/worker-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const main = async () => {

while (true) {
try {
const result = await aristaApi({
const systemResult = await aristaApi({
host: workerData.address,
protocol: "https",
port: 443,
Expand All @@ -31,7 +31,18 @@ const main = async () => {
commands: ["show version"],
});

await mongoSingle.set("system", result, 120);
await mongoSingle.set("system", systemResult, 120);

const powerResult = await aristaApi({
host: workerData.address,
protocol: "https",
port: 443,
username: workerData.username,
password: workerData.password,
commands: ["show system environment power"],
});

await mongoSingle.set("power", powerResult?.["powerSupplies"], 120);
} catch (error) {}
await delay(10000);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/arista-switch/module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "arista-switch",
"longname": "Arista Switch",
"version": "1.0.3",
"version": "1.1.0",
"description": "Monitoring and control of Arista switches",
"capabilities": ["network-switch"],
"icon": "SettingsEthernet",
Expand Down

0 comments on commit 1fe7c27

Please sign in to comment.