Exemplo n.º 1
0
 private int getSnmpVersion() {
   switch (configuration.getVersion()) {
     case VERSION_1:
       return SnmpConstants.version1;
     case VERSION_2:
     case VERSION_2_C:
       return SnmpConstants.version2c;
     default:
       return SnmpConstants.version1;
   }
 }
Exemplo n.º 2
0
 private void createSession() throws IOException {
   if (snmp == null) {
     Address address = GenericAddress.parse(deviceAddress);
     AbstractTransportMapping transport;
     if (address instanceof TlsAddress) {
       transport = new TLSTM();
     } else if (address instanceof TcpAddress) {
       transport = new DefaultTcpTransportMapping();
     } else {
       transport = new DefaultUdpTransportMapping();
     }
     // Could save some CPU cycles:
     transport.setAsyncMsgProcessingSupported(false);
     snmp = new Snmp(transport);
     snmp.listen();
     if (getSnmpVersion() == SnmpConstants.version3) {
       snmp.getUSM()
           .addUser(
               new OctetString("user"),
               new UsmUser(
                   new OctetString("user"),
                   AuthMD5.ID,
                   new OctetString("user"),
                   AuthMD5.ID,
                   null));
       // create the target
       target = new UserTarget();
       target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
       target.setSecurityName(new OctetString("user"));
     } else {
       // create the target
       target = new CommunityTarget();
       ((CommunityTarget) target).setCommunity(new OctetString(configuration.getReadCommunity()));
     }
     target.setAddress(address);
     target.setVersion(getSnmpVersion());
     target.setRetries(retries);
     target.setTimeout(timeout);
   }
 }