fix(core): fix lint/type issues and small refactors
This commit is contained in:
@@ -94,7 +94,8 @@ export class NupstSnmp {
|
||||
public snmpGet(
|
||||
oid: string,
|
||||
config = this.DEFAULT_CONFIG,
|
||||
retryCount = 0,
|
||||
_retryCount = 0,
|
||||
// deno-lint-ignore no-explicit-any
|
||||
): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.debug) {
|
||||
@@ -105,6 +106,7 @@ export class NupstSnmp {
|
||||
}
|
||||
|
||||
// Create SNMP options based on configuration
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const options: any = {
|
||||
port: config.port,
|
||||
retries: SNMP.RETRIES, // Number of retries
|
||||
@@ -132,6 +134,7 @@ export class NupstSnmp {
|
||||
const securityLevel = config.securityLevel || 'noAuthNoPriv';
|
||||
|
||||
// Create the user object with required structure for net-snmp
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const user: any = {
|
||||
name: config.username || '',
|
||||
};
|
||||
@@ -214,7 +217,8 @@ export class NupstSnmp {
|
||||
const oids = [oid];
|
||||
|
||||
// Send the GET request
|
||||
session.get(oids, (error: any, varbinds: any[]) => {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
session.get(oids, (error: Error | null, varbinds: any[]) => {
|
||||
// Close the session to release resources
|
||||
session.close();
|
||||
|
||||
@@ -428,6 +432,7 @@ export class NupstSnmp {
|
||||
oid: string,
|
||||
description: string,
|
||||
config: ISnmpConfig,
|
||||
// deno-lint-ignore no-explicit-any
|
||||
): Promise<any> {
|
||||
if (oid === '') {
|
||||
if (this.debug) {
|
||||
@@ -482,6 +487,7 @@ export class NupstSnmp {
|
||||
oid: string,
|
||||
description: string,
|
||||
config: ISnmpConfig,
|
||||
// deno-lint-ignore no-explicit-any
|
||||
): Promise<any> {
|
||||
if (this.debug) {
|
||||
logger.dim(`Retrying ${description} with fallback security level...`);
|
||||
@@ -489,7 +495,7 @@ export class NupstSnmp {
|
||||
|
||||
// Try with authNoPriv if current level is authPriv
|
||||
if (config.securityLevel === 'authPriv') {
|
||||
const retryConfig = { ...config, securityLevel: 'authNoPriv' as 'authNoPriv' };
|
||||
const retryConfig = { ...config, securityLevel: 'authNoPriv' as const };
|
||||
try {
|
||||
if (this.debug) {
|
||||
logger.dim(`Retrying with authNoPriv security level`);
|
||||
@@ -512,7 +518,7 @@ export class NupstSnmp {
|
||||
|
||||
// Try with noAuthNoPriv as a last resort
|
||||
if (config.securityLevel === 'authPriv' || config.securityLevel === 'authNoPriv') {
|
||||
const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as 'noAuthNoPriv' };
|
||||
const retryConfig = { ...config, securityLevel: 'noAuthNoPriv' as const };
|
||||
try {
|
||||
if (this.debug) {
|
||||
logger.dim(`Retrying with noAuthNoPriv security level`);
|
||||
@@ -538,15 +544,16 @@ export class NupstSnmp {
|
||||
|
||||
/**
|
||||
* Try standard OIDs as fallback
|
||||
* @param oid OID to query
|
||||
* @param _oid Original OID (unused, kept for method signature consistency)
|
||||
* @param description Description of the value for logging
|
||||
* @param config SNMP configuration
|
||||
* @returns Promise resolving to the SNMP value
|
||||
*/
|
||||
private async tryStandardOids(
|
||||
oid: string,
|
||||
_oid: string,
|
||||
description: string,
|
||||
config: ISnmpConfig,
|
||||
// deno-lint-ignore no-explicit-any
|
||||
): Promise<any> {
|
||||
try {
|
||||
// Try RFC 1628 standard UPS MIB OIDs
|
||||
|
||||
Reference in New Issue
Block a user