SnmpHibernate is a MIB/Object mapping framework inspired by Hibernate Project(O/R Mapping framework). It will release u from coding tedious SNMP client code. Current release is based on SNMP4J project.
Sample code to get and set MIB2 system information:)
1. Write the SystemInfo class and annotate properties of the class with MIB defination.
import java.io.Serializable;
import org.opengoss.snmphibernate.api.SmiType;
import org.opengoss.snmphibernate.api.annotation.MibObjectType;
import org.opengoss.snmphibernate.api.annotation.MibObjectType.Access;
public class SystemInfo implements Serializable {
@MibObjectType(oid = "1.3.6.1.2.1.1.1.0", smiType = SmiType.DISPLAY_STRING, access = Access.READ)
public String sysDesc;
@MibObjectType(oid = "1.3.6.1.2.1.1.2.0", smiType = SmiType.OID, access = Access.READ)
public String sysObjectID;
@MibObjectType(oid = "1.3.6.1.2.1.1.3.0", smiType = SmiType.TIMETICKS, access = Access.READ)
public long sysUpTime;
@MibObjectType(oid = "1.3.6.1.2.1.1.4.0", smiType = SmiType.DISPLAY_STRING, access = Access.WRITE)
public String sysContact;
@MibObjectType(oid = "1.3.6.1.2.1.1.5.0", smiType = SmiType.DISPLAY_STRING, access = Access.WRITE)
public String sysName;
@MibObjectType(oid = "1.3.6.1.2.1.1.6.0", smiType = SmiType.DISPLAY_STRING, access = Access.WRITE)
public String sysLocation;
public String getSysContact() {
return sysContact;
}
public void setSysContact(String sysContact) {
this.sysContact = sysContact;
}
public String getSysDesc() {
return sysDesc;
}
public void setSysDesc(String sysDesc) {
this.sysDesc = sysDesc;
}
public String getSysLocation() {
return sysLocation;
}
public void setSysLocation(String sysLocation) {
this.sysLocation = sysLocation;
}
public String getSysName() {
return sysName;
}
public void setSysName(String sysName) {
this.sysName = sysName;
}
public String getSysObjectID() {
return sysObjectID;
}
public void setSysObjectID(String sysObjectID) {
this.sysObjectID = sysObjectID;
}
public long getSysUpTime() {
return sysUpTime;
}
public void setSysUpTime(long sysUpTime) {
this.sysUpTime = sysUpTime;
}
}
2. Create the ISnmpSession API, and execute Get/Set operation.
ISnmpSession session = null;
try {
ISnmpClientFacade facade = new Snmp4JClientFacade();
ISnmpSessionFactory sessionFactory = facade.getSnmpSessionFactory();
ISnmpTargetFactory targetFactory = facade.getSnmpTargetFactory();
session = sessionFactory.newSnmpSession(targetFactory.newSnmpTarget("127.0.0.1", 161));
SystemInfo sysMIB = session.get(SystemInfo.class);
sysMIB.setSysContact("ery.lee@gmail.com");
session.set(sysMIB);
} finally {
if(session != null) session.close();
}
分享到:
相关推荐
SnmpHibernate是一个MIB/Object映射框架,它的灵感源自Hibernate项目(O/R映射框架)。SnmpHibernate能让你从编写冗长乏味的SNMP客户端代码中解脱出来。当前发布是基于SNMP4J项目。
SnmpHibernate是一个基于Java开发的框架,主要用于整合SNMP(简单网络管理协议)与Hibernate ORM(对象关系映射)技术。这个框架的核心目的是提供一种高效、便捷的方式来管理和监控网络设备,同时利用Hibernate来...
《深入解析SNMPHibernate.API源代码》 在IT领域,理解和使用开源库是提升效率、增强功能的关键。本文将深入探讨"snmphibernate.api"这一项目,它属于org.opengoss.snmphibernate.api,主要涉及SNMP(简单网络管理...
标题中的"snmphibernate相关jar"表明这是一组与SNMP(H简单网络管理协议)和Hibernate ORM框架结合使用的Java库。这些jar文件是开发人员在使用SNMP进行网络设备管理和监控时,通过Hibernate来实现更方便的数据交互所...
SnmpHibernate是一个MIB/Object映射框架,它的灵感源自Hibernate项目(O/R映射框架)。SnmpHibernate能让你从编写冗长乏味的SNMP客户端代码中解脱出来。当前发布是基于SNMP4J项目
SnmpHibernate是一个受Hibernate Project(O / R映射框架)启发的MIB /对象映射框架。