Skip to content

Commit 2b3482b

Browse files
robbaveyedmocosta
andauthored
Add support for SNMPv3 context engine ID and context name to snmptrap (#76)
This commits adds support for ContextEngineId and ContextName to the `snmptrap` input. Co-authored-by: Edmo Vamerlatti Costa <[email protected]>
1 parent 8d863fb commit 2b3482b

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

.ci/docker-compose-integration.override.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '2.4'
2-
31
services:
42
logstash:
53
container_name: snmp_ls

.ci/docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# docker ipv6 only support in version 2.x
2-
version: '2.4'
3-
41
# run tests: cd ci/unit; docker-compose up --build --force-recreate
52
# manual: cd ci/unit; docker-compose run logstash bash
63
services:

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.1.0
2+
- Add support for SNMPv3 `context engine ID` and `context name` to the `snmptrap` input [#76](https://github.com/logstash-plugins/logstash-integration-snmp/pull/76)
3+
14
## 4.0.7
25
- FIX: The `snmptrap` input now correctly enforces the user security level set by `security_level` config, and drops received events that do not match the configured value [#75](https://github.com/logstash-plugins/logstash-integration-snmp/pull/75)
36

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.7
1+
4.1.0

docs/input-snmptrap.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ The value is stored in the `@metadata` where it can be used by other plugins in
6060
|ECS disabled, v1, v8 |Availability|Description
6161
|[@metadata][input][snmptrap][pdu][agent_addr]|`SNMPv1`|Network address of the object generating the trap
6262
|[@metadata][input][snmptrap][pdu][community]|`SNMPv1` `SNMPv2c`|SNMP community
63+
|[@metadata][input][snmptrap][pdu][context_engine_id]|`SNMPv3`|SNMP context engine ID
64+
|[@metadata][input][snmptrap][pdu][context_name]|`SNMPv3`|SNMP context name
6365
|[@metadata][input][snmptrap][pdu][enterprise]|`SNMPv1`|Type of object generating the trap
6466
|[@metadata][input][snmptrap][pdu][error_index]|`SNMPv2c` `SNMPv3`|Provides additional information by identifying
6567
which variable binding in the list caused the error

src/main/java/org/logstash/snmp/SnmpClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ public <A extends Address> void processPdu(final CommandResponderEvent<A> event)
246246
if (!validateTrapMessage(version, securityName, event.getSecurityLevel(), allowedCommunities)) {
247247
return;
248248
}
249-
250249
final Map<String, Object> trapEvent = createTrapEvent(version, securityName, event.getPDU());
251250
final Map<String, Object> formattedVarBindings = new HashMap<>(event.getPDU().getVariableBindings().size());
252251
for (VariableBinding binding : event.getPDU().getVariableBindings()) {
@@ -306,6 +305,11 @@ private Map<String, Object> createTrapEvent(int version, final String securityNa
306305
trapEvent.put("error_status", pdu.getErrorStatus());
307306
trapEvent.put("error_status_text", pdu.getErrorStatusText());
308307
trapEvent.put("error_index", pdu.getErrorIndex());
308+
if (pdu instanceof ScopedPDU) {
309+
final ScopedPDU scopedPDU = (ScopedPDU) pdu;
310+
trapEvent.put("context_engine_id", String.valueOf(scopedPDU.getContextEngineID()));
311+
trapEvent.put("context_name", String.valueOf(scopedPDU.getContextName()));
312+
}
309313
} else if (pdu instanceof PDUv1) {
310314
final PDUv1 pdUv1 = (PDUv1) pdu;
311315
trapEvent.put("enterprise", String.valueOf(pdUv1.getEnterprise()));

src/test/java/org/logstash/snmp/SnmpClientTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,10 +1083,14 @@ void trapShouldProperlyCreateV2cTrapMessage() throws IOException {
10831083

10841084
@Test
10851085
void trapShouldProperlyCreateV3TrapMessage() throws IOException {
1086-
final PDU scopedPDU = new PDU(PDU.TRAP, List.of(
1086+
final ScopedPDU scopedPDU = new ScopedPDU();
1087+
scopedPDU.setVariableBindings(List.of(
10871088
new VariableBinding(new OID("1.1"), new OctetString("foo")),
10881089
new VariableBinding(new OID("1.2"), new OctetString("bar"))
10891090
));
1091+
scopedPDU.setContextEngineID(OctetString.fromString("666f6f", 16));
1092+
scopedPDU.setContextName(OctetString.fromString("626172", 16));
1093+
scopedPDU.setType(ScopedPDU.TRAP);
10901094
scopedPDU.setRequestID(new Integer32(123));
10911095

10921096
when(mibManager.map(any(OID.class)))
@@ -1105,6 +1109,8 @@ void trapShouldProperlyCreateV3TrapMessage() throws IOException {
11051109
assertEquals(scopedPDU.getErrorStatus(), trapEvent.remove("error_status"));
11061110
assertEquals(scopedPDU.getErrorStatusText(), trapEvent.remove("error_status_text"));
11071111
assertEquals(scopedPDU.getErrorIndex(), trapEvent.remove("error_index"));
1112+
assertEquals(scopedPDU.getContextEngineID().toString(), trapEvent.remove("context_engine_id"));
1113+
assertEquals(scopedPDU.getContextName().toString(), trapEvent.remove("context_name"));
11081114

11091115
@SuppressWarnings("unchecked") final Map<String, Object> variableBindings = (Map<String, Object>) trapEvent.remove("variable_bindings");
11101116
scopedPDU.getVariableBindings().forEach(binding -> assertEquals(

0 commit comments

Comments
 (0)