[SNMP4J] SNMP4J newbie

Marco.Bresciani at alcatel.it Marco.Bresciani at alcatel.it
Thu Dec 15 10:51:19 CET 2005


Hi all,
  I'm just trying to learn and use SNMP4J to replace a "home-made" (and 
too complex) SNMP corporate API. I'm trying to follow JavaDoc (Snmp class) 
example(s) but it seems the first line is wrong... :-/

I'm working in an existing class, I've  created an "init" method that 
would prepare SNMP connection because all other methods would be static (I 
have to keep the same methods signatures...). Anyway, init method calls 
is: init("10.0.1.2", 161, false, "initial", "initialing"); while the 
"init" method is as follow:

    /**
     * New init method for SNMP4J usage and new communication 
infrastructure.
     *
     * @param pIPAddress <acronym title="InterNet Protocol">IP</acronym> 
address
     * for remote device
     * @param pPort network port for device communication
     * @param pTCP {@code true} if
     * <acronym title="Transmission Control Protocol">TCP</acronym> 
protocol
     * chose else <acronym title="User Datagram Protocol">UDP</acronym>
     */
    public static void init(String pIPAddress, int pPort, boolean pTCP,
                            String pUserName, String pPassword) {

        /* variables declaration */
        Address targetURL;
        TransportMapping transport;
        MPv3 processor;
        USM userModel;
        String address;
        UsmUser user;

        /* IP address setting up */
        if (pTCP == true) {

            /* TCP protocol selected */
            address = new String("tcp");
        } else {

            /* UDP protocol selected */
            address = new String("udp");
        }
        targetURL = IpAddress.parse(address + ":" + pIPAddress + "/"
                                         + pPort);


/* I HAVE AN EXCEPTION ON PREVIOUS ROW: java.lang.NoSuchMethodError
        at org.snmp4j.smi.IpAddress.createAnyAddress(IpAddress.java:178)
        at org.snmp4j.smi.IpAddress.<clinit>(IpAddress.java:42)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:115)
        at org.snmp4j.smi.GenericAddress.class$(GenericAddress.java:51)
        at 
org.snmp4j.smi.GenericAddress.registerAddressTypes(GenericAddress.java:158)
        at org.snmp4j.smi.GenericAddress.parse(GenericAddress.java:185)
        at 
com.alcatel.wtd.common.mibquery.Converter.init(Converter.java:196)
        at 
com.alcatel.wtd.common.mibquery.Converter.init(Converter.java:111)
        at 
com.alcatel.wtd.common.mainview.CommonView.<init>(CommonView.java:294)
        at 
com.alcatel.wtd.common.mainview.CommonView.<init>(CommonView.java:190)
        at 
com.alcatel.wtd.uls.JUSMWtdMainView.<init>(JUSMWtdMainView.java:168)
        at 
com.alcatel.wtd.uls.JUSMWtdMainView.main(JUSMWtdMainView.java:157)
BUT I DON'T UNDERSTAND THE PROBLEM... */

        /* transport level selection */
        transport = null;
        try {
            if (pTCP == true) {
                transport = new DefaultTcpTransportMapping();
            } else {
                transport = new DefaultUdpTransportMapping();
            }
        } catch (Exception e) {
            System.err.println("Converter.init(String, int, boolean) 1: " 
+ e);
            ConverterInitialized = false;
            e.printStackTrace();
        }

        /* SNMP activation */
        if (transport != null) {
            snmp = new Snmp(transport);
        } else {
            ConverterInitialized = false;
            return;
        }

/* FOLLOWING PART IS VERY EARLY DRAFT... */

        /* SNMP v3 message processor */
        processor = (MPv3)snmp.getMessageProcessingModel(
                MessageProcessingModel.MPv3);

        /* SNMP v3 security model */
        userModel = new USM(SecurityProtocols.getInstance(),
                            new 
OctetString(processor.createLocalEngineID()),
                            0);
        SecurityProtocols.getInstance().addDefaultProtocols();
        SecurityModels.getInstance().addSecurityModel(userModel);

        try {
            transport.listen();
        } catch (Exception e) {
            System.err.println("Converter.init(String, int, boolean) 2: " 
+ e);
            ConverterInitialized = false;
            e.printStackTrace();
        }

        /* target device preparation */
        device = new UserTarget();
        if (pUserName != null) {
            if (pPassword != null) {

                /* username and password are available */
                device.setSecurityLevel(SecurityLevel.AUTH_PRIV);
            } else {

                /* username available only */
                device.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
            }
        } else {

            /* neither username nor password present */
            device.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
        }
        device.setSecurityName(new OctetString("SECURITY_NAME"));

        /* user management */
        user = new UsmUser(new OctetString(pUserName),
                           new OID("AUTENTHICATION_PROTOCOL"),
                           new OctetString(pPassword),
                           (OID) null,
                           (OctetString) null);
        snmp.getUSM().addUser(device.getSecurityName(), user);

/* END OF VERY EARLY DRAFT PART... */


        ConverterInitialized = true;
    }

Thank you in advance for any help anyone could give me.

Dott. Ing. Marco Bresciani

-- 
Alcatel - WTD R&D SW Lab. [Stage]
Via Trento, 30
20059 Vimercate (Mi) Italia

E-Mail: Marco.Bresciani at Alcatel.It



More information about the SNMP4J mailing list