-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rui Liu
authored
Jul 30, 2024
1 parent
32cd3de
commit fe35fa4
Showing
7 changed files
with
168 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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,24 @@ | ||
host.system: snmp_host | ||
|
||
instances: | ||
- snmp.host: udp:9.30.78.59/161 | ||
poll.interval: 25 | ||
callback.interval: 30 | ||
otel.backend.url: http://127.0.0.1:4317 | ||
#otel.backend.using.http: true | ||
#otel.backend.url: http://9.112.252.66:4318/v1/metrics | ||
#host.name: stantest0.fyre.ibm.com | ||
#os.type: linux | ||
#community: public | ||
#retries: 3 | ||
#timeout: 1000 | ||
version: 3 | ||
securityLevel: 3 | ||
securityName: linuser | ||
authPassword: linuserpass | ||
privacyPassword: linprivpass | ||
#AuthSHA: 1.3.6.1.6.3.10.1.1.3 | ||
authType: 1.3.6.1.6.3.10.1.1.3 | ||
#PrivDES: 1.3.6.1.6.3.10.1.2.2 | ||
privacyType: 1.3.6.1.6.3.10.1.2.2 | ||
|
Binary file not shown.
This file contains 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 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 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
59 changes: 59 additions & 0 deletions
59
internal/simp-snmp/src/main/java/com/instana/simpsnmp/SimpSnmpTst.java
This file contains 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,59 @@ | ||
package com.instana.simpsnmp; | ||
|
||
import org.snmp4j.PDU; | ||
import org.snmp4j.Snmp; | ||
import org.snmp4j.Target; | ||
import org.snmp4j.fluent.SnmpBuilder; | ||
import org.snmp4j.fluent.SnmpCompletableFuture; | ||
import org.snmp4j.fluent.TargetBuilder; | ||
import org.snmp4j.mp.SnmpConstants; | ||
import org.snmp4j.security.SecurityLevel; | ||
import org.snmp4j.security.SecurityProtocols; | ||
import org.snmp4j.smi.Address; | ||
import org.snmp4j.smi.GenericAddress; | ||
import org.snmp4j.smi.OID; | ||
import org.snmp4j.smi.VariableBinding; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class SimpSnmpTst { | ||
public static void main(String[] args) throws IOException, ExecutionException { | ||
SnmpBuilder snmpBuilder = new SnmpBuilder(); | ||
Snmp snmp = snmpBuilder.udp().securityProtocols( | ||
SecurityProtocols.SecurityProtocolSet.maxCompatibility).v3().usm().build(); | ||
|
||
Address targetAddress = GenericAddress.parse("udp:9.30.78.59/161"); | ||
byte[] targetEngineID = snmp.discoverAuthoritativeEngineID(targetAddress, 1000); | ||
|
||
if (targetEngineID != null) { | ||
TargetBuilder<?> targetBuilder = snmpBuilder.target(targetAddress); | ||
|
||
Target<?> target = targetBuilder | ||
.user("linuser", targetEngineID) | ||
.auth(TargetBuilder.AuthProtocol.sha1).authPassphrase("linuserpass") | ||
.priv(TargetBuilder.PrivProtocol.des).privPassphrase("linprivpass") | ||
.done() | ||
.timeout(1500).retries(2) | ||
.build(); | ||
target.setVersion(SnmpConstants.version3); | ||
target.setSecurityLevel(SecurityLevel.AUTH_PRIV); | ||
|
||
PDU pdu = targetBuilder.pdu().type(PDU.GET).contextName("").build(); | ||
pdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.1.0"))); | ||
|
||
SnmpCompletableFuture snmpRequestFuture = SnmpCompletableFuture.send(snmp, target, pdu); | ||
try { | ||
List<VariableBinding> vbs = snmpRequestFuture.get().getAll(); | ||
System.out.println("Received: " + snmpRequestFuture.getResponseEvent().getResponse()); | ||
} catch (ExecutionException | InterruptedException ex) { | ||
System.err.println("Request failed: " + ex.getCause().getMessage()); | ||
} | ||
} else { | ||
System.err.println("Timeout on engine ID discovery for " + targetAddress + ", GET not sent."); | ||
} | ||
snmp.close(); | ||
|
||
} | ||
} |
This file contains 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