免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1354 | 回复: 0
打印 上一主题 下一主题

SnmpHibernate 1.0.0beta released finally! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-02-19 21:48 |只看该作者 |倒序浏览

                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. Below is some samples,
The project location:
SnmpHibernate on Sourceforge
The 1.0.0beta release is based on
SNMP4J project
.
I hope u could contribute to the project. Contact me by ery.lee@gmail.com if any problems and suggestions.
  • Get/Set MIB2-System:
1 Write the SystemInfo POJO first,
import java.io.Serializable;import net.sourceforge.snmphibernate.api.SmiType;import net.sourceforge.snmphibernate.api.annotation.MibObjectType;import net.sourceforge.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;}
2. Get/Set by the session API,
        ISnmpClientFacade facade = new Snmp4JClientFacade();        ISnmpSessionFactory sessionFactory = facade.getSnmpSessionFactory();        ISnmpTargetFactory targetFactory = facade.getSnmpTargetFactory();        ISnmpSession session = sessionFactory.newSnmpSession(targetFactory.newSnmpTarget(                "127.0.0.1", 161));SystemInfo sysMIB = (SystemInfo)session.get(SystemInfo.class);
  • Get IfTable:
1. Write the IfEntry POJO first,
import java.io.Serializable;import net.sourceforge.snmphibernate.api.SmiType;import net.sourceforge.snmphibernate.api.annotation.MibIndex;import net.sourceforge.snmphibernate.api.annotation.MibObjectType;import net.sourceforge.snmphibernate.api.annotation.MibTable;import net.sourceforge.snmphibernate.api.annotation.MibObjectType.Access;@MibTablepublic class IfEntry implements Serializable {    @MibIndex(no = 0, length = 1)    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.1", smiType = SmiType.INTEGER32, access = Access.READ)    public int ifIndex;     @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.2", smiType = SmiType.DISPLAY_STRING, access = Access.READ)    public String ifDescr;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.3", smiType = SmiType.INTEGER32, access = Access.READ)    public int ifType;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.4", smiType = SmiType.INTEGER32, access = Access.READ)    public int ifMtu;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.5", smiType = SmiType.GAUGE32, access = Access.READ)    public long ifSpeed;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.6", smiType = SmiType.OCTET_STRING, access = Access.READ)    public byte[] ifPhysAddress;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.7", smiType = SmiType.INTEGER32, access = Access.READ)    public int ifAdminStatus;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.8", smiType = SmiType.INTEGER32, access = Access.READ)    public int ifOperStatus;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.9", smiType = SmiType.TIMETICKS, access = Access.READ)    public long ifLastChange;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.10", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifInOctets;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.11", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifInUcastPkts;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.12", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifInNUcastPkts;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.13", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifInDiscards;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.14", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifInErrors;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.15", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifInUnknownProtos;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.16", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifOutOctets;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.17", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifOutUcastPkts;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.18", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifOutNUcastPkts;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.19", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifOutDiscards;    @MibObjectType(oid = "1.3.6.1.2.1.2.2.1.20", smiType = SmiType.COUNTER32, access = Access.READ)    public long ifOutErrors;    public IfEntry() {}        public IfEntry(int index) {        this.ifIndex = index;    }    public boolean isLoopback() {        return ifType == 24;    }}
2. Get the whole table,
  ISnmpClientFacade facade = new Snmp4JClientFacade();
        ISnmpSessionFactory sessionFactory = facade.getSnmpSessionFactory();
        ISnmpTargetFactory targetFactory = facade.getSnmpTargetFactory();
        ISnmpSession session = sessionFactory.newSnmpSession(targetFactory.newSnmpTarget(
                "127.0.0.1", 161));
List list = session.getTable(IfEntry.class);
  • There are other features listed below,
1. You can get part of properties a Mib entry or scalar group.2. Create an entry of a MIB table.3. Delete an entry of a MIB table.4. Lanched as an OSGi bundle. If you are not familiar with OSGI, I suggest u remove the "Activator" from the src of release jars to pass compile.
Enjoy it:)
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/14066/showart_76388.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP