Created
April 27, 2023 20:28
-
-
Save WietseWind/3b7809142b9c6ad9aee52e511ed0e981 to your computer and use it in GitHub Desktop.
SNMP APC Netbotz 200 - Get temp & Switch Relay with NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var snmp = require ("net-snmp"); | |
var session = snmp.createSession("10.2.1.151", "private") | |
const relayOid = '1.3.6.1.4.1.318.1.1.10.4.4.4.1.5.0.1' | |
const outletOid = '1.3.6.1.4.1.318.1.1.10.4.5.4.1.5.0.1' | |
var oids = [ | |
"1.3.6.1.4.1.318.1.1.10.4.2.3.1.5.0.1", // temp 1 | |
"1.3.6.1.4.1.318.1.1.10.4.2.3.1.5.0.4", // temp 4 | |
"1.3.6.1.4.1.318.1.1.10.4.2.3.1.6.0.4", // humid 4 | |
relayOid, | |
outletOid, | |
] | |
session.get(oids, function (error, varbinds) { | |
if (error) { | |
console.error(error.toString()) | |
} else { | |
for (var i = 0; i < varbinds.length; i++) { | |
if (snmp.isVarbindError (varbinds[i])) { | |
console.error (snmp.varbindError (varbinds[i])) | |
} else { | |
console.log (varbinds[i].oid + " = " + varbinds[i].value) | |
} | |
} | |
} | |
// session.close() | |
}) | |
var varbinds = [ | |
{ | |
oid: relayOid, | |
type: snmp.ObjectType.Integer, | |
value: 1 | |
}, | |
{ | |
oid: outletOid, | |
type: snmp.ObjectType.Integer, | |
value: 1 | |
} | |
] | |
session.set(varbinds, function (error, varbinds) { | |
console.log('--------') | |
if (error) { | |
console.error(error.toString()); | |
} else { | |
for (var i = 0; i < varbinds.length; i++) { | |
// for version 1 we can assume all OIDs were successful | |
console.log (varbinds[i].oid + " = " + varbinds[i].value) // Relay, Outlet | |
// // for version 2c we must check each OID for an error condition | |
// if (snmp.isVarbindError(varbinds[i])) { | |
// console.error (snmp.varbindError (varbinds[i])) | |
// } else { | |
// console.log (varbinds[i].oid + "|" + varbinds[i].value) | |
// } | |
} | |
} | |
}) | |
setTimeout(function () { | |
session.close() | |
}, 1500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment