高分求救:用过snmp4j的大虾进!
我现在用agenpro把一个mib文件转换成了java代码,但是不知道这个类怎么使用。也就是如何放在agent里。望指点迷津啊!!!
java代码
import org.snmp4j.smi.*;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.agent.*;
import org.snmp4j.agent.mo.*;
import org.snmp4j.agent.mo.snmp.*;
import org.snmp4j.agent.mo.snmp.smi.*;
import org.snmp4j.agent.request.*;
import org.snmp4j.log.LogFactory;
import org.snmp4j.log.LogAdapter;
import org.snmp4j.agent.mo.snmp.tc.*;
//--AgentGen BEGIN=_IMPORT
//--AgentGen END
public class HelloMib
//--AgentGen BEGIN=_EXTENDS
//--AgentGen END
implements MOGroup
//--AgentGen BEGIN=_IMPLEMENTS
//--AgentGen END
{
private static final LogAdapter LOGGER =
LogFactory.getLogger(HelloMib.class);
//--AgentGen BEGIN=_STATIC
//--AgentGen END
// Factory
private MOFactory moFactory =
DefaultMOFactory.getInstance();
// Constants
/**
* OID of this MIB module for usage which can be
* used for its identification.
*/
public static final OID oidHelloMib =
new OID(new int[] { });
public static final OID oidSysDescr =
new OID(new int[] { 1,3,6,1,2,1,1,1,0 });
public static final OID oidSysTest =
new OID(new int[] { 1,3,6,1,2,1,1,2,0 });
// Enumerations
// TextualConventions
// Scalars
private MOScalar sysDescr;
private MOScalar sysTest;
// Tables
//--AgentGen BEGIN=_MEMBERS
//--AgentGen END
/**
* Constructs a HelloMib instance without actually creating its
* <code>ManagedObject</code> instances. This has to be done in a
* sub-class constructor or after construction by calling
* {@link #createMO(MOFactory moFactory)}.
*/
protected HelloMib() {
//--AgentGen BEGIN=_DEFAULTCONSTRUCTOR
//--AgentGen END
}
/**
* Constructs a HelloMib instance and actually creates its
* <code>ManagedObject</code> instances using the supplied
* <code>MOFactory</code> (by calling
* {@link #createMO(MOFactory moFactory)}).
* @param moFactory
* the <code>MOFactory</code> to be used to create the
* managed objects for this module.
*/
public HelloMib(MOFactory moFactory) {
createMO(moFactory);
//--AgentGen BEGIN=_FACTORYCONSTRUCTOR
//--AgentGen END
}
//--AgentGen BEGIN=_CONSTRUCTORS
//--AgentGen END
/**
* Create the ManagedObjects defined for this MIB module
* using the specified {@link MOFactory}.
* @param moFactory
* the <code>MOFactory</code> instance to use for object
* creation.
*/
protected void createMO(MOFactory moFactory) {
addTCsToFactory(moFactory);
sysDescr =
moFactory.createScalar(oidSysDescr,
moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY),
new OctetString());
sysTest =
moFactory.createScalar(oidSysTest,
moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY),
new OctetString());
}
public MOScalar getSysDescr() {
return sysDescr;
}
public MOScalar getSysTest() {
return sysTest;
}
public void registerMOs(MOServer server, OctetString context)
throws DuplicateRegistrationException
{
// Scalar Objects
server.register(this.sysDescr, context);
server.register(this.sysTest, context);
//--AgentGen BEGIN=_registerMOs
//--AgentGen END
}
public void unregisterMOs(MOServer server, OctetString context) {
// Scalar Objects
server.unregister(this.sysDescr, context);
server.unregister(this.sysTest, context);
//--AgentGen BEGIN=_unregisterMOs
//--AgentGen END
}
// Notifications
// Scalars
// Value Validators
// Rows and Factories
//--AgentGen BEGIN=_METHODS
//--AgentGen END
// Textual Definitions of MIB module HelloMib
protected void addTCsToFactory(MOFactory moFactory) {
}
//--AgentGen BEGIN=_TC_CLASSES_IMPORTED_MODULES_BEGIN
//--AgentGen END
// Textual Definitions of other MIB modules
public void addImportedTCsToFactory(MOFactory moFactory) {
}
//--AgentGen BEGIN=_TC_CLASSES_IMPORTED_MODULES_END
//--AgentGen END
//--AgentGen BEGIN=_CLASSES
//--AgentGen END
//--AgentGen BEGIN=_END
//--AgentGen END
}
[解决办法]
难道就没人用过?
[解决办法]
该回复于2010-08-10 15:12:06被版主删除
[解决办法]
已解决!如果有意这方面资料的朋友请加我MSN:weipeijie@hotmail.com.共同学习。
[解决办法]
高手赐教,能否发一份可运行的程序让小弟借鉴学习一下,最近在弄SNMP4j,很是头疼。多谢了!
[解决办法]
忘了留邮箱了,呵呵!
gangwei_chen@163.com
再次感谢!