Pregunta

He estado haciendo una programación SNMP4J muy básica. Todo lo que quiero hacer es enviar una solicitud simple de "obtener", pero hasta ahora mis respuestas han sido nulas. Abrí Wireshark y descubrí que en el protocolo de gestión de redes Simple, mi nombre de msguserN está en blanco y necesito que se complete.

Pensé que lo había configurado usando el siguiente código:

Snmp snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();

UsmUser user = new UsmUser(new OctetString("SNMPManager"), AuthSHA.ID,new OctetString("password"),null,null);
// add user to the USM
snmp.getUSM().addUser(user.getSecurityName(), user);

¿Lo estoy haciendo de la manera incorrecta? Si no es así, ¿cómo configuré el nombre de msguserNer como se ve en mi vertedero de Wireshark de Get-Request? Soy muy nuevo en SNMP, así que esencialmente estoy huyendo de ejemplos.

¿Fue útil?

Solución

Este es un snmpset en funcionamiento que puede escribir SNMP Get de la misma manera. SNMP4J V2 y V3 no usan las mismas clases de API.

 private void snmpSetV3(VariableBinding[] bindings) throws TimeOutException, OperationFailed {
        Snmp snmp = null;
        try {
            PDU pdu = new ScopedPDU();
            USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
            SecurityModels.getInstance().addSecurityModel(usm);
            snmp = new Snmp(new DefaultUdpTransportMapping());
            snmp.getUSM().addUser(new OctetString(Username), new UsmUser(new OctetString(Username), AuthMD5.ID, new OctetString(Password), AuthMD5.ID, null));


            ScopedPDU scopedPDU = (ScopedPDU) pdu;
            scopedPDU.setType(PDU.SET);
            scopedPDU.addAll(bindings);
            UserTarget target = new UserTarget();
            target.setAddress(new UdpAddress(IPAddress + "/" + Port));
            target.setVersion(version); //SnmpConstants.version3
            target.setRetries(retries);
            target.setTimeout(timeout);
            target.setSecurityLevel(securityLevel); //SecurityLevel.AUTH_NOPRIV
            target.setSecurityName(new OctetString(Username));
            snmp.listen();
            ResponseEvent response = snmp.send(pdu, target);
            if (response.getResponse() != null) {
                PDU responsePDU = response.getResponse();
                if (responsePDU != null) {
                    if (responsePDU.getErrorStatus() == PDU.noError) {
                        return;
                    }
                    throw new OperationFailed("Error: Request Failed, "
                            + "Error Status = " + responsePDU.getErrorStatus()
                            + ", Error Index = " + responsePDU.getErrorIndex()
                            + ", Error Status Text = " + responsePDU.getErrorStatusText());
                }
            }
            throw new TimeOutException("Error: Agent Timeout... ");
        } catch (IOException e) {
            throw new OperationFailed(e.getMessage(), e);

        } finally {
            if (snmp != null) {
                try {
                    snmp.close();
                } catch (IOException ex) {
                    _logger.error(ex.getMessage(), ex);
                }
            }
        }


    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top