mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 23:04:04 +00:00
Remove unnecessary func getKey
Addresses: - https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1589856311 - https://github.com/louislam/uptime-kuma/pull/4717#discussion_r1589862733
This commit is contained in:
parent
86b997c664
commit
0384b34007
4 changed files with 5 additions and 23 deletions
|
@ -14,10 +14,7 @@ class SNMPMonitorType extends MonitorType {
|
||||||
port: monitor.port || "161",
|
port: monitor.port || "161",
|
||||||
retries: monitor.maxretries,
|
retries: monitor.maxretries,
|
||||||
timeout: monitor.timeout * 1000,
|
timeout: monitor.timeout * 1000,
|
||||||
|
version: monitor.snmpVersion,
|
||||||
// Resolve the net-snmp version identifier from monitor.snmpVersion using the `getKey` method (see utils.ts).
|
|
||||||
// If the specified version exists, use it; otherwise, default to SNMP version 2c.
|
|
||||||
version: getKey(snmp.Version, monitor.snmpVersion) || snmp.Version2c,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -40,8 +37,7 @@ class SNMPMonitorType extends MonitorType {
|
||||||
log.debug("monitor", `SNMP: Received varbinds (Type=${getKey(snmp.ObjectType, varbinds[0].type)}): ${varbinds[0].value}`);
|
log.debug("monitor", `SNMP: Received varbinds (Type=${getKey(snmp.ObjectType, varbinds[0].type)}): ${varbinds[0].value}`);
|
||||||
|
|
||||||
// Verify if any varbinds were returned from the SNMP session or if the varbind type indicates a non-existent instance.
|
// Verify if any varbinds were returned from the SNMP session or if the varbind type indicates a non-existent instance.
|
||||||
// The `getKey` method retrieves the key associated with the varbind type from the snmp.ObjectType object.
|
if (varbinds.length === 0 || varbinds[0].type === snmp.ObjectType.NoSuchInstance) {
|
||||||
if (varbinds.length === 0 || getKey(snmp.ObjectType, varbinds[0].type) === "NoSuchInstance") {
|
|
||||||
throw new Error(`No varbinds returned from SNMP session (OID: ${monitor.snmpOid})`);
|
throw new Error(`No varbinds returned from SNMP session (OID: ${monitor.snmpOid})`);
|
||||||
|
|
||||||
// Varbinds succesfully returned
|
// Varbinds succesfully returned
|
||||||
|
|
|
@ -297,10 +297,10 @@
|
||||||
<div v-if="monitor.type === 'snmp'" class="my-3">
|
<div v-if="monitor.type === 'snmp'" class="my-3">
|
||||||
<label for="snmp_version" class="form-label">{{ $t("SNMP Version") }}</label>
|
<label for="snmp_version" class="form-label">{{ $t("SNMP Version") }}</label>
|
||||||
<select id="snmp_version" v-model="monitor.snmpVersion" class="form-select">
|
<select id="snmp_version" v-model="monitor.snmpVersion" class="form-select">
|
||||||
<option value="1">
|
<option value="0">
|
||||||
SNMPv1
|
SNMPv1
|
||||||
</option>
|
</option>
|
||||||
<option value="2c">
|
<option value="1">
|
||||||
SNMPv2c
|
SNMPv2c
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
var _a;
|
var _a;
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.sleep = exports.flipStatus = exports.badgeConstants = exports.CONSOLE_STYLE_BgGray = exports.CONSOLE_STYLE_BgWhite = exports.CONSOLE_STYLE_BgCyan = exports.CONSOLE_STYLE_BgMagenta = exports.CONSOLE_STYLE_BgBlue = exports.CONSOLE_STYLE_BgYellow = exports.CONSOLE_STYLE_BgGreen = exports.CONSOLE_STYLE_BgRed = exports.CONSOLE_STYLE_BgBlack = exports.CONSOLE_STYLE_FgPink = exports.CONSOLE_STYLE_FgBrown = exports.CONSOLE_STYLE_FgViolet = exports.CONSOLE_STYLE_FgLightBlue = exports.CONSOLE_STYLE_FgLightGreen = exports.CONSOLE_STYLE_FgOrange = exports.CONSOLE_STYLE_FgGray = exports.CONSOLE_STYLE_FgWhite = exports.CONSOLE_STYLE_FgCyan = exports.CONSOLE_STYLE_FgMagenta = exports.CONSOLE_STYLE_FgBlue = exports.CONSOLE_STYLE_FgYellow = exports.CONSOLE_STYLE_FgGreen = exports.CONSOLE_STYLE_FgRed = exports.CONSOLE_STYLE_FgBlack = exports.CONSOLE_STYLE_Hidden = exports.CONSOLE_STYLE_Reverse = exports.CONSOLE_STYLE_Blink = exports.CONSOLE_STYLE_Underscore = exports.CONSOLE_STYLE_Dim = exports.CONSOLE_STYLE_Bright = exports.CONSOLE_STYLE_Reset = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isNode = exports.isDev = void 0;
|
exports.sleep = exports.flipStatus = exports.badgeConstants = exports.CONSOLE_STYLE_BgGray = exports.CONSOLE_STYLE_BgWhite = exports.CONSOLE_STYLE_BgCyan = exports.CONSOLE_STYLE_BgMagenta = exports.CONSOLE_STYLE_BgBlue = exports.CONSOLE_STYLE_BgYellow = exports.CONSOLE_STYLE_BgGreen = exports.CONSOLE_STYLE_BgRed = exports.CONSOLE_STYLE_BgBlack = exports.CONSOLE_STYLE_FgPink = exports.CONSOLE_STYLE_FgBrown = exports.CONSOLE_STYLE_FgViolet = exports.CONSOLE_STYLE_FgLightBlue = exports.CONSOLE_STYLE_FgLightGreen = exports.CONSOLE_STYLE_FgOrange = exports.CONSOLE_STYLE_FgGray = exports.CONSOLE_STYLE_FgWhite = exports.CONSOLE_STYLE_FgCyan = exports.CONSOLE_STYLE_FgMagenta = exports.CONSOLE_STYLE_FgBlue = exports.CONSOLE_STYLE_FgYellow = exports.CONSOLE_STYLE_FgGreen = exports.CONSOLE_STYLE_FgRed = exports.CONSOLE_STYLE_FgBlack = exports.CONSOLE_STYLE_Hidden = exports.CONSOLE_STYLE_Reverse = exports.CONSOLE_STYLE_Blink = exports.CONSOLE_STYLE_Underscore = exports.CONSOLE_STYLE_Dim = exports.CONSOLE_STYLE_Bright = exports.CONSOLE_STYLE_Reset = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isNode = exports.isDev = void 0;
|
||||||
exports.getKey = exports.intHash = exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = void 0;
|
exports.intHash = exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = void 0;
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
exports.isDev = process.env.NODE_ENV === "development";
|
exports.isDev = process.env.NODE_ENV === "development";
|
||||||
exports.isNode = typeof process !== "undefined" && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
exports.isNode = typeof process !== "undefined" && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
||||||
|
@ -396,7 +396,3 @@ function intHash(str, length = 10) {
|
||||||
return (hash % length + length) % length;
|
return (hash % length + length) % length;
|
||||||
}
|
}
|
||||||
exports.intHash = intHash;
|
exports.intHash = intHash;
|
||||||
function getKey(obj, value) {
|
|
||||||
return Object.keys(obj).find(key => obj[key] === value) || null;
|
|
||||||
}
|
|
||||||
exports.getKey = getKey;
|
|
||||||
|
|
10
src/util.ts
10
src/util.ts
|
@ -642,13 +642,3 @@ export function intHash(str : string, length = 10) : number {
|
||||||
// Normalize the hash to the range [0, 10]
|
// Normalize the hash to the range [0, 10]
|
||||||
return (hash % length + length) % length; // Ensure the result is non-negative
|
return (hash % length + length) % length; // Ensure the result is non-negative
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
export function getKey(obj: any, value: string) {
|
|
||||||
return Object.keys(obj).find(key => obj[key] === value) || null;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue