读MIB文件


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.sinoufc.base.monitor.item.model.MibObject;

import net.percederberg.mibble.Mib;
import net.percederberg.mibble.MibLoader;
import net.percederberg.mibble.MibLoaderException;
import net.percederberg.mibble.MibValue;
import net.percederberg.mibble.MibValueSymbol;
import net.percederberg.mibble.snmp.SnmpObjectType;

public class Test {

/**
* @param args
* @throws MibLoaderException
* @throws IOException
*/
public static void main(String[] args) throws IOException, MibLoaderException {
Test t = new Test();
//String content = t.readFile();
// System.err.println("content==="+content);
t.aa();

}

@SuppressWarnings( { "unchecked" })
public void aa() throws IOException, MibLoaderException {
String filePath = this.getClass().getResource("/").getPath() + "RFC1315-MIB.mib";
File file = new File(filePath);
MibLoader ml = new MibLoader();
Mib mib = ml.load(file);
String mibName = mib.getName();

System.err.println("mibName===" + mibName);
System.err.println("-------------------------------------");
String syntax = "";
String access = "";
String status = "";
List<MibObject> list = new ArrayList<MibObject>();
Collection c = mib.getAllSymbols();
Iterator it = c.iterator();
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof MibValueSymbol) {
MibObject mo = new MibObject();
MibValueSymbol mvs = (MibValueSymbol) obj;
SnmpObjectType sot = null;
if (mvs.getType() instanceof SnmpObjectType) {
sot = (SnmpObjectType) mvs.getType();
}
if (sot != null ) {
syntax = sot.getSyntax().getName();
access = sot.getAccess().toString();
status = sot.getStatus().toString();
}
//是否为表的列
boolean isTableColumn = mvs.isTableColumn();
String name = mvs.getName();
MibValue value = mvs.getValue();
MibValueSymbol parent = mvs.getParent();
String parentValue = "";
System.err.println("name==" + name);
System.err.println("value==" + value);
System.err.println("isTableColumn==" + isTableColumn);
if (parent != null) {
parentValue = parent.getValue().toString();
if (parent.getParent()==null){
System.err.println("supperParentName======" + mibName);
System.err.println("supperParentValue=====" + parentValue);
//parent=root

}
System.err.println("parentName=" + parent.getName());
System.err.println("parentValue=" + parent.getValue());

} else {
}
System.err.println("syntax=" + syntax);
System.err.println("access=" + access);
System.err.println("status=" + status);
System.err.println("-------------------------------------");
mo.setName(name);
mo.setValue(value.toString());
mo.setParent(parentValue);
mo.setSyntax(syntax);
mo.setAccess(access);
mo.setStatus(status);
list.add(mo);
}
//System.out.println(it.next());
}

MibValueSymbol mvs = mib.getSymbolByOid("1.3.6.1.2.1.10");
System.err.println("mvs.getName()=" + mvs.getName());
System.err.println("mvs.getValue()=" + mvs.getValue());
MibValueSymbol parent = mvs.getParent();
System.err.println("parent=" + parent);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值