diff --git a/db/knex_migrations/2024-04-26-0000-snmp-monitor.js b/db/knex_migrations/2024-04-26-0000-snmp-monitor.js index 8e553de7..988828c0 100644 --- a/db/knex_migrations/2024-04-26-0000-snmp-monitor.js +++ b/db/knex_migrations/2024-04-26-0000-snmp-monitor.js @@ -1,11 +1,11 @@ exports.up = function (knex) { return knex.schema .alterTable("monitor", function (table) { - table.string("snmp_community_string", 255).defaultTo("public"); // Add snmp_community_string column - table.string("snmp_oid").defaultTo(null); // Add oid column - table.enum("snmp_version", [ "0", "1", "3" ]).defaultTo("1"); // Add snmp_version column with enum values (0: SNMPv1, 1: SNMPv2c, 3: SNMPv3) - table.float("snmp_control_value").defaultTo(null); // Add control_value column as float - table.string("snmp_condition").defaultTo(null); // Add oid column + table.string("snmp_community_string", 255).defaultTo("public"); + table.string("snmp_oid").defaultTo(null); + table.enum("snmp_version", [ "1", "2c", "3" ]).defaultTo("2c"); + table.float("snmp_control_value").defaultTo(null); + table.string("snmp_condition").defaultTo(null); }); }; diff --git a/server/monitor-types/snmp.js b/server/monitor-types/snmp.js index ab14bb07..920e1fe2 100644 --- a/server/monitor-types/snmp.js +++ b/server/monitor-types/snmp.js @@ -14,7 +14,7 @@ class SNMPMonitorType extends MonitorType { port: monitor.port || "161", retries: monitor.maxretries, timeout: monitor.timeout * 1000, - version: parseInt(monitor.snmpVersion), + version: snmp.Version[monitor.snmpVersion], }; let session; @@ -37,14 +37,12 @@ class SNMPMonitorType extends MonitorType { }); log.debug("monitor", `SNMP: Received varbinds (Type: ${snmp.ObjectType[varbinds[0].type]} Value: ${varbinds[0].value}`); - // Verify if any varbinds were returned from the SNMP session. if (varbinds.length === 0) { throw new Error(`No varbinds returned from SNMP session (OID: ${monitor.snmpOid})`); } - // Check if the varbind type indicates a non-existent instance. if (varbinds[0].type === snmp.ObjectType.NoSuchInstance) { - throw new Error(`The SNMP query was successful but no varbinds returned for OID: ${monitor.snmpOid}`); + throw new Error(`The SNMP query returned that no instance exists for OID ${monitor.snmpOid}`); } // We restrict querying to one OID per monitor, therefore `varbinds[0]` will always contain the value we're interested in. diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index b8b79324..83e38356 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -265,18 +265,18 @@