Re: [SNMP4J] Sending an object identifier
Hi Yeah, I've solved that problem but now I'm not sure I'm going in the right direction. In fact my code is: private PDU pdu; private Snmp snmp; private VariableBinding oid; private VariableBinding mib_method; private VariableBinding object; private VariableBinding status; oid = new VariableBinding(); oid.setOid(SnmpConstants.snmpTrapOID); oid.setVariable(new OID()); mib_method = new VariableBinding(); mib_method.setOid(new OID(0)); mib_method.setVariable(new OctetString(UCD-NOTIFICATION-TEST-MIB::demoNotif)); object = new VariableBinding(); object.setOid(new OID(0)); object.setVariable(new OctetString(SNMPv2-MIB::sysLocation.0)); status = new VariableBinding(); status.setOid(new OID(0)); status.setVariable(new OctetString(Test da codice)); pdu = new PDU(); pdu.setType(PDU.TRAP); pdu.add(oid); pdu.add(mib_method); pdu.add(object); pdu.add(status); The server log shows this: Jun 30 09:50:13 qa1 snmptrapd[10477]: 2010-06-30 09:50:13 luna.elaide.com [UDP: [192.168.5.19]:58057]: SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::zeroDotZero SNMPv2-SMI::zeroDotZero = STRING: UCD-NOTIFICATION-TEST-MIB::demoNotifSNMPv2-SMI::zeroDotZero = STRING: SNMPv2-MIB::sysLocation.0 SNMPv2-SMI::zeroDotZero = STRING: Test da codice Now I'm thinking that with the code I'm not able to 'hit' the right mib... Thanks in advance Il 29/06/2010 19:12, Frank Fock ha scritto: Hi, Object identifiers are specified in dotted notation: each sub-identifier separated by a dot ('.'). For example: 1.3.6.1.4.1 Best regards, Frank On 29.06.2010 12:39, Gian Marco Gallo wrote: Good day I'm trying to send a notification with snmp4j and to add informations in my pdu (so the mib in the server can print the right message in the server log). So I've tried this: pdu = new PDU(); pdu.setType(PDU.TRAP); pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OctetString(UCD-NOTIFICATION-TEST-MIB::demoNotif))); But in the server log appears this: Jun 29 12:30:14 qa1 snmptrapd[6166]: 2010-06-29 12:30:14 luna.elaide.com [UDP: [192.168.5.19]:48917]: SNMPv2-MIB::snmpTrapOID.0 = Wrong Type (should be OBJECT IDENTIFIER): STRING: UCD-NOTIFICATION-TEST-MIB::demoNotif Any idea on how send an object identifier? This is the mib on the server: UCD-NOTIFICATION-TEST-MIB DEFINITIONS ::= BEGIN IMPORTS ucdExperimental FROM UCD-SNMP-MIB; ucdNotificationTestMib MODULE-IDENTITY demotraps OBJECT IDENTIFIER ::= { ucdExperimental 990 } demonotifs OBJECT IDENTIFIER ::= { demotraps 0 } *demoNotif* NOTIFICATION-TYPE OBJECTS { sysLocation } STATUS current DESCRIPTION An example of an SMIv2 notification *::= { demonotifs 18 }* ucdNotificationGroup NOTIFICATION-GROUP END Thanks in advance -- Gian Marco Gallo Elaide SRL Email: gianmarco.ga...@elaide.com Phone: +39 049 4102390 ___ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j
[SNMP4J] Sending an object identifier
Good day I'm trying to send a notification with snmp4j and to add informations in my pdu (so the mib in the server can print the right message in the server log). So I've tried this: pdu = new PDU(); pdu.setType(PDU.TRAP); pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OctetString(UCD-NOTIFICATION-TEST-MIB::demoNotif))); But in the server log appears this: Jun 29 12:30:14 qa1 snmptrapd[6166]: 2010-06-29 12:30:14 luna.elaide.com [UDP: [192.168.5.19]:48917]: SNMPv2-MIB::snmpTrapOID.0 = Wrong Type (should be OBJECT IDENTIFIER): STRING: UCD-NOTIFICATION-TEST-MIB::demoNotif Any idea on how send an object identifier? This is the mib on the server: UCD-NOTIFICATION-TEST-MIB DEFINITIONS ::= BEGIN IMPORTS ucdExperimental FROM UCD-SNMP-MIB; ucdNotificationTestMib MODULE-IDENTITY demotraps OBJECT IDENTIFIER ::= { ucdExperimental 990 } demonotifs OBJECT IDENTIFIER ::= { demotraps 0 } *demoNotif* NOTIFICATION-TYPE OBJECTS { sysLocation } STATUS current DESCRIPTION An example of an SMIv2 notification *::= { demonotifs 18 }* ucdNotificationGroup NOTIFICATION-GROUP END Thanks in advance -- Gian Marco Gallo Elaide SRL Email: gianmarco.ga...@elaide.com Phone: +39 049 4102390 ___ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j
[SNMP4J] How to create a trap pdu
Hello guys Here I am with another noob question. I want to send a trap message to a snmp server that contains the following structure values in his .mib file: alarm OBJECT IDENTIFIER ::= {nms 1} alarmData OBJECT IDENTIFIER ::= {alarm 1} alarmTrap OBJECT IDENTIFIER ::= {alarm 2} alarmId OBJECT-TYPE SYNTAX Integer32 MAX-ACCESS read-only STATUS current DESCRIPTION Alarm's identifier. ::= {alarmData 1} alarmValue OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION Alarm's value. ::= {alarmData 2} openTrap NOTIFICATION-TYPE OBJECTS {alarmId, alarmValue} STATUS current DESCRIPTION New alarm opened. ::= {alarmTrap 1} So I've created my PDU with this code: pdu = new ScopedPDU(); pdu.setType(ScopedPDU.TRAP); pdu.setContextName(new OctetString(CryptoExtWeb problem)); But now I don't understand how I can insert the values required by the .mib file. Should I create and construct a new object or what? Thanks for your help -- Gian Marco Gallo Elaide SRL Email: gianmarco.ga...@elaide.com Phone: +39 049 4102390 ___ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j
Re: [SNMP4J] Unsupported security model
I've done this: UserTarget target = new UserTarget(); target.setSecurityName(new OctetString(CryptoExtWeb)); Then I've done this: UsmUser user = new UsmUser(new OctetString(CryptoExtWeb), null, null, null, null); In this way the code works fine and the trap is sent but if I use different OctetStrings this runtime exception is returned. 11:39:14,575 ERROR [STDERR] org.snmp4j.MessageException: Message processing model 3 returned error: Unknown security name 11:39:14,575 ERROR [STDERR] at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:465) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.sendMessage(Snmp.java:1067) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:882) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:875) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:840) 11:39:14,575 ERROR [STDERR] at com.elaide.crypto.ext.web.snmp.TrapSnmp.sendTrap(TrapSnmp.java:123) 11:39:14,575 ERROR [STDERR] at com.elaide.crypto.ext.web.snmp.TrapSnmp.createAndSend(TrapSnmp.java:50) 11:39:14,575 ERROR [STDERR] at com.elaide.crypto.ext.web.listeners.IndexListener.loadUserManager(IndexListener.java:47) 11:39:14,575 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 11:39:14,576 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 11:39:14,576 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 11:39:14,576 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597) 11:39:14,576 ERROR [STDERR] at bsh.Reflect.invokeMethod(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Reflect.invokeObjectMethod(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Name.invokeMethod(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.BSHMethodInvocation.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.BSHPrimaryExpression.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.BSHPrimaryExpression.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Interpreter.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Interpreter.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:134) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:341) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:840) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:175) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:140) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(EventProcessingThreadImpl.java:517) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.run(EventProcessingThreadImpl.java:444) So I've deduced that the two OctetStrings must be equal. Il 23/06/2010 11:30, Kazantsev, Andrey V. ha scritto: I'm glad to hear that I helped you. What user name do you mean? In fact there is only security name, which is first argument to UsmUser constructor. You use it later for adding this user to USM instance (usm.addUser(user.getSecurityName(), user)). I just called security name with username, but it could be arbitrary string. -Original Message- From: Gian Marco Gallo [mailto:gianmarco.ga...@elaide.com] Sent: Wednesday, June 23, 2010 16:12 To: Kazantsev, Andrey V. Subject: Re: [SNMP4J] Unsupported security model Hello Thanks for your quick reply. I've tried your code and after five tries it now works. In fact I didn't understand that the username and the security name have to be equals (confirm?). But now it works fine. Thanks again for your help Have a nice day Il 23/06/2010 04:28, Kazantsev, Andrey V. ha scritto: Hello. I think you should create USM (User Security Model) and add it to your SNMP session. Consider following example: USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); Also you maybe want to add user (noAuthNoPriv): user = new UsmUser(new OctetString(username), null, null, null, null); usm.addUser(user.getSecurityName(), user); This example code from http://www.snmp4j.org/doc/org/snmp4j/Snmp.html Also you can look at SnmpRequest.java from snmp4j-1.11.zip\snmp4j-1.11\src\org\snmp4j\tools\console\ -Original Message- From: snmp4j-boun...@agentpp.org [mailto:snmp4j-boun...@agentpp.org] On Behalf Of Gian Marco Gallo Sent: Tuesday, June 22, 2010 21:41 To: snmp4j@agentpp.org Subject: [SNMP4J] Unsupported security model Good afternoon I am trying to send a trap message to a server listening for snmp messages but when I try to send
Re: [SNMP4J] Unsupported security model
I'm trying to fully understand the pros of the snmp but for now I'm still moving the first steps :D Anyway...thanks again for your help Il 23/06/2010 11:55, Kazantsev, Andrey V. ha scritto: Yes, you right - in UserTarget you should use security name that is exist in USM - i.e., that you created with UsmUser. This tells what security settings to use when sending traps (you can create more than one UsmUser with different settings and use any of them in UserTarget). -Original Message- From: Gian Marco Gallo [mailto:gianmarco.ga...@elaide.com] Sent: Wednesday, June 23, 2010 16:47 To: Kazantsev, Andrey V. Cc: snmp4j@agentpp.org Subject: Re: [SNMP4J] Unsupported security model I've done this: UserTarget target = new UserTarget(); target.setSecurityName(new OctetString(CryptoExtWeb)); Then I've done this: UsmUser user = new UsmUser(new OctetString(CryptoExtWeb), null, null, null, null); In this way the code works fine and the trap is sent but if I use different OctetStrings this runtime exception is returned. 11:39:14,575 ERROR [STDERR] org.snmp4j.MessageException: Message processing model 3 returned error: Unknown security name 11:39:14,575 ERROR [STDERR] at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:465) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.sendMessage(Snmp.java:1067) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:882) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:875) 11:39:14,575 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:840) 11:39:14,575 ERROR [STDERR] at com.elaide.crypto.ext.web.snmp.TrapSnmp.sendTrap(TrapSnmp.java:123) 11:39:14,575 ERROR [STDERR] at com.elaide.crypto.ext.web.snmp.TrapSnmp.createAndSend(TrapSnmp.java:50) 11:39:14,575 ERROR [STDERR] at com.elaide.crypto.ext.web.listeners.IndexListener.loadUserManager(IndexListener.java:47) 11:39:14,575 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 11:39:14,576 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 11:39:14,576 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 11:39:14,576 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597) 11:39:14,576 ERROR [STDERR] at bsh.Reflect.invokeMethod(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Reflect.invokeObjectMethod(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Name.invokeMethod(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.BSHMethodInvocation.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.BSHPrimaryExpression.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.BSHPrimaryExpression.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Interpreter.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at bsh.Interpreter.eval(Unknown Source) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:134) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:341) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:840) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:175) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:140) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(EventProcessingThreadImpl.java:517) 11:39:14,576 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.run(EventProcessingThreadImpl.java:444) So I've deduced that the two OctetStrings must be equal. Il 23/06/2010 11:30, Kazantsev, Andrey V. ha scritto: I'm glad to hear that I helped you. What user name do you mean? In fact there is only security name, which is first argument to UsmUser constructor. You use it later for adding this user to USM instance (usm.addUser(user.getSecurityName(), user)). I just called security name with username, but it could be arbitrary string. -Original Message- From: Gian Marco Gallo [mailto:gianmarco.ga...@elaide.com] Sent: Wednesday, June 23, 2010 16:12 To: Kazantsev, Andrey V. Subject: Re: [SNMP4J] Unsupported security model Hello Thanks for your quick reply. I've tried your code and after five tries it now works. In fact I didn't understand that the username and the security name have to be equals (confirm?). But now it works fine. Thanks again for your help Have a nice day Il 23/06/2010 04:28, Kazantsev, Andrey V. ha scritto: Hello. I think you should create USM (User Security Model) and add it to your SNMP session. Consider following example: USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0
[SNMP4J] Unsupported security model
Good afternoon I am trying to send a trap message to a server listening for snmp messages but when I try to send the trap an exception is throwed: 16:20:12,817 ERROR [STDERR] org.snmp4j.MessageException: Message processing model 3 returned error: Unsupported security model 16:20:12,817 ERROR [STDERR] at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:465) 16:20:12,818 ERROR [STDERR] at org.snmp4j.Snmp.sendMessage(Snmp.java:1067) 16:20:12,818 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:882) 16:20:12,818 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:875) 16:20:12,818 ERROR [STDERR] at org.snmp4j.Snmp.send(Snmp.java:840) 16:20:12,818 ERROR [STDERR] at com.elaide.crypto.ext.web.snmp.TrapSnmp.sendTrap(TrapSnmp.java:94) 16:20:12,818 ERROR [STDERR] at com.elaide.crypto.ext.web.snmp.TrapSnmp.createAndSend(TrapSnmp.java:42) 16:20:12,818 ERROR [STDERR] at com.elaide.crypto.ext.web.listeners.IndexListener.loadUserManager(IndexListener.java:47) 16:20:12,818 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 16:20:12,818 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 16:20:12,818 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 16:20:12,818 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597) 16:20:12,818 ERROR [STDERR] at bsh.Reflect.invokeMethod(Unknown Source) 16:20:12,818 ERROR [STDERR] at bsh.Reflect.invokeObjectMethod(Unknown Source) 16:20:12,818 ERROR [STDERR] at bsh.Name.invokeMethod(Unknown Source) 16:20:12,818 ERROR [STDERR] at bsh.BSHMethodInvocation.eval(Unknown Source) 16:20:12,818 ERROR [STDERR] at bsh.BSHPrimaryExpression.eval(Unknown Source) 16:20:12,819 ERROR [STDERR] at bsh.BSHPrimaryExpression.eval(Unknown Source) 16:20:12,819 ERROR [STDERR] at bsh.Interpreter.eval(Unknown Source) 16:20:12,819 ERROR [STDERR] at bsh.Interpreter.eval(Unknown Source) 16:20:12,819 ERROR [STDERR] at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:134) 16:20:12,819 ERROR [STDERR] at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:341) 16:20:12,819 ERROR [STDERR] at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:840) 16:20:12,819 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:175) 16:20:12,819 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:140) 16:20:12,819 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(EventProcessingThreadImpl.java:517) 16:20:12,819 ERROR [STDERR] at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.run(EventProcessingThreadImpl.java:444) I've searched for two days a solution in the snmp4j documentation and over internet but no luck. Do you have an idea? I'm attaching my simple snmp class. Thanks in advance -- Gian Marco Gallo Elaide SRL Email: gianmarco.ga...@elaide.com Phone: +39 049 4102390 package com.elaide.crypto.ext.web.snmp; import java.io.IOException; import org.apache.log4j.Logger; import org.snmp4j.ScopedPDU; import org.snmp4j.Snmp; import org.snmp4j.UserTarget; import org.snmp4j.mp.SnmpConstants; import org.snmp4j.security.SecurityLevel; import org.snmp4j.security.SecurityModel; import org.snmp4j.smi.Address; import org.snmp4j.smi.GenericAddress; import org.snmp4j.smi.OctetString; import org.snmp4j.transport.DefaultUdpTransportMapping; /*// / CAUTION: ALL THIS CLASS SHOULD BE TRANSLATED / //*/ public class TrapSnmp { Address address; UserTarget target; ScopedPDU pdu; Snmp snmp; private static Logger log; public TrapSnmp() { log = Logger.getLogger(TrapSnmp.class); } public void createAndSend() { createAddress(); createPDU(); createTarget(); sendTrap(); } private void createAddress() { log.info(Creating the SNMP destination address); address = GenericAddress.parse(udp:192.168.5.11/161); } private void createPDU() { log.info(Creating the TRAP message); pdu = new ScopedPDU(); pdu.setType(ScopedPDU.TRAP); pdu.setContextName(new OctetString(CryptoExtWeb problem)); log.info(The trap has been created with this values: ); log.info(Context name: +pdu.getContextName()); log.info(Context engine ID: +pdu.getContextEngineID()); log.info(Request