SnmpHibernate

开源SnmpHibernate: http://ery.lee.googlepages.com/snmphibernate@opengoss

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();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值