From 6254da701a59d4a54aa3a3b2ddf0d66ab7816b2a Mon Sep 17 00:00:00 2001 From: Geoff House Date: Fri, 8 Mar 2024 18:29:56 +0000 Subject: [PATCH] arista-switch: add check for power supply --- .../container/services/status-checkpower.js | 23 +++++++++++++++++++ .../container/services/status-get.js | 4 +++- .../container/workers/worker-system.js | 15 ++++++++++-- src/modules/arista-switch/module.json | 2 +- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/modules/arista-switch/container/services/status-checkpower.js diff --git a/src/modules/arista-switch/container/services/status-checkpower.js b/src/modules/arista-switch/container/services/status-checkpower.js new file mode 100644 index 000000000..995e17c2c --- /dev/null +++ b/src/modules/arista-switch/container/services/status-checkpower.js @@ -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; +}; diff --git a/src/modules/arista-switch/container/services/status-get.js b/src/modules/arista-switch/container/services/status-get.js index c9f3957ee..5660a69e7 100644 --- a/src/modules/arista-switch/container/services/status-get.js +++ b/src/modules/arista-switch/container/services/status-get.js @@ -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( @@ -28,6 +29,7 @@ module.exports = async () => { }), await statusCheckPending(), await statusCheckInterfaceStatus(), - await statusCheckSfps() + await statusCheckSfps(), + await statusCheckPower() ); }; diff --git a/src/modules/arista-switch/container/workers/worker-system.js b/src/modules/arista-switch/container/workers/worker-system.js index a00c61a29..6963c3da5 100644 --- a/src/modules/arista-switch/container/workers/worker-system.js +++ b/src/modules/arista-switch/container/workers/worker-system.js @@ -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, @@ -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); } diff --git a/src/modules/arista-switch/module.json b/src/modules/arista-switch/module.json index 7743853af..45b177ea0 100644 --- a/src/modules/arista-switch/module.json +++ b/src/modules/arista-switch/module.json @@ -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",