-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
feat(snmp): add SNMPv3 noAuthNoPriv support with backend test #6552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
16990ed
feat(snmp): add SNMPv3 noAuthNoPriv support with backend test
dipok-1 47c3783
chore: revert unrelated dependency changes
dipok-1 6fcb541
db: add migration for snmp_v3_username
dipok-1 8dc048f
chore: revert unrelated bootstrap scss change
dipok-1 be441f0
Update src/pages/EditMonitor.vue
querysmith-sys e21719c
i18n: add SNMPv3 username label
dipok-1 e411097
docs(snmp): clarify SNMPv3 security level scoping
dipok-1 50a2483
chore: fix lint issues
dipok-1 c6d1289
fix(i18n): chnaged snmpV3Username to match language file format
dipok-1 b6a36f6
test(snmp): remove brittle SNMPv3 unit test
dipok-1 59b0b4b
test(snmp): cover SNMPv3 noAuthNoPriv via unit test and SNMPv2c via i…
dipok-1 5a7c1c3
Merge branch 'master' into feat/snmp-v3
CommanderStorm 5a4017f
fix: address review feedback
dipok-1 0adda0b
chore: remove old SNMP tests after consolidation
dipok-1 35cd96d
Merge branch 'master' into feat/snmp-v3
CommanderStorm 523f6f4
[autofix.ci] apply automated fixes
autofix-ci[bot] f549378
Merge branch 'master' into feat/snmp-v3
CommanderStorm 4929fbb
Merge branch 'master' into feat/snmp-v3
CommanderStorm 317f71c
fix(snmp): stabilize SNMP test and require testcontainers 11.5.0
dipok-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
db/knex_migrations/2025-12-31-2143-add-snmp-v3-username.js
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| exports.up = async function (knex) { | ||
| await knex.schema.alterTable("monitor", (table) => { | ||
| table.string("snmp_v3_username", 255); | ||
| }); | ||
| }; | ||
|
|
||
| exports.down = async function (knex) { | ||
| await knex.schema.alterTable("monitor", (table) => { | ||
| table.dropColumn("snmp_v3_username"); | ||
| }); | ||
| }; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| const { describe, test } = require("node:test"); | ||
| const assert = require("node:assert/strict"); | ||
| const { GenericContainer } = require("testcontainers"); | ||
| const { SNMPMonitorType } = require("../../server/monitor-types/snmp"); | ||
| const { UP } = require("../../src/util"); | ||
| const snmp = require("net-snmp"); | ||
|
|
||
| describe("SNMPMonitorType", () => { | ||
| test( | ||
| "check() sets heartbeat to UP when SNMP agent responds", | ||
| { | ||
| skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"), | ||
| }, | ||
| async () => { | ||
| // Expose SNMP port via Testcontainers | ||
| const container = await new GenericContainer("polinux/snmpd").withExposedPorts("161/udp").start(); | ||
|
|
||
| try { | ||
| // Dynamically retrieve the assigned host port and IP | ||
| const hostPort = container.getMappedPort(161); | ||
| const hostIp = container.getHost(); | ||
|
|
||
| // UDP service small wait to ensure snmpd is ready inside container | ||
| await new Promise((r) => setTimeout(r, 1500)); | ||
|
|
||
| const monitor = { | ||
| type: "snmp", | ||
| hostname: hostIp, | ||
| port: hostPort, | ||
| snmpVersion: "2c", | ||
| radiusPassword: "public", | ||
| snmpOid: "1.3.6.1.2.1.1.1.0", | ||
| timeout: 5, | ||
| maxretries: 1, | ||
| jsonPath: "$", | ||
| jsonPathOperator: "exists", | ||
| expectedValue: null, | ||
| }; | ||
|
|
||
| const snmpMonitor = new SNMPMonitorType(); | ||
| const heartbeat = {}; | ||
|
|
||
| await snmpMonitor.check(monitor, heartbeat); | ||
|
|
||
| assert.strictEqual(heartbeat.status, UP); | ||
| assert.match(heartbeat.msg, /JSON query passes/); | ||
| } finally { | ||
| await container.stop(); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| test( | ||
| "check() throws when SNMP agent does not respond", | ||
| { | ||
| skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"), | ||
| }, | ||
| async () => { | ||
| const monitor = { | ||
| type: "snmp", | ||
| hostname: "127.0.0.1", | ||
| port: 65530, // Assuming no SNMP agent is running here | ||
| snmpVersion: "2c", | ||
| radiusPassword: "public", | ||
| snmpOid: "1.3.6.1.2.1.1.1.0", | ||
| timeout: 1, | ||
| maxretries: 1, | ||
| }; | ||
|
|
||
| const snmpMonitor = new SNMPMonitorType(); | ||
| const heartbeat = {}; | ||
|
|
||
| await assert.rejects(() => snmpMonitor.check(monitor, heartbeat), /timeout|RequestTimedOutError/i); | ||
| } | ||
| ); | ||
|
|
||
| test("check() uses SNMPv3 noAuthNoPriv session when version is 3", async () => { | ||
| const originalCreateV3Session = snmp.createV3Session; | ||
| const originalCreateSession = snmp.createSession; | ||
|
|
||
| let createV3Called = false; | ||
| let createSessionCalled = false; | ||
| let receivedOptions = null; | ||
|
|
||
| // Stub createV3Session | ||
| snmp.createV3Session = function (_host, _username, options) { | ||
| createV3Called = true; | ||
| receivedOptions = options; | ||
|
|
||
| return { | ||
| on: () => {}, | ||
| close: () => {}, | ||
| // Stop execution after session creation to avoid real network I/O. | ||
| get: (_oids, cb) => cb(new Error("stop test here")), | ||
| }; | ||
| }; | ||
|
|
||
| // Stub createSession | ||
| snmp.createSession = function () { | ||
| createSessionCalled = true; | ||
| return {}; | ||
| }; | ||
|
|
||
| const monitor = { | ||
| type: "snmp", | ||
| hostname: "127.0.0.1", | ||
| port: 161, | ||
| timeout: 5, | ||
| maxretries: 1, | ||
| snmpVersion: "3", | ||
| snmp_v3_username: "testuser", | ||
| snmpOid: "1.3.6.1.2.1.1.1.0", | ||
| }; | ||
|
|
||
| const snmpMonitor = new SNMPMonitorType(); | ||
| const heartbeat = {}; | ||
|
|
||
| await assert.rejects(() => snmpMonitor.check(monitor, heartbeat), /stop test here/); | ||
|
|
||
| // Assertions | ||
| assert.strictEqual(createV3Called, true); | ||
| assert.strictEqual(createSessionCalled, false); | ||
| assert.strictEqual(receivedOptions.securityLevel, snmp.SecurityLevel.noAuthNoPriv); | ||
|
|
||
| // Restore originals | ||
| snmp.createV3Session = originalCreateV3Session; | ||
| snmp.createSession = originalCreateSession; | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.