Move getKey() to util.ts

This commit is contained in:
Matt Visnovsky
2024-05-03 11:39:14 -06:00
parent 8e56a81ef1
commit c87ac2f043
3 changed files with 15 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
const { MonitorType } = require("./monitor-type");
const { UP, DOWN, log } = require("../../src/util");
const { UP, DOWN, log, getKey } = require("../../src/util");
const snmp = require("net-snmp");
class SNMPMonitorType extends MonitorType {
@@ -17,16 +17,6 @@ class SNMPMonitorType extends MonitorType {
version: getKey(snmp.Version, monitor.snmpVersion) || snmp.Version2c,
};
/**
* Retrieves the key from the provided object corresponding to the given value.
* @param {object} obj - The object to search.
* @param {*} value - The value to search for.
* @returns {string|null} - The key associated with the value, or null if not found.
*/
function getKey(obj, value) {
return Object.keys(obj).find(key => obj[key] === value) || null;
}
try {
const session = snmp.createSession(monitor.hostname, monitor.snmpCommunityString, options);