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);
}
}
读MIB文件
最新推荐文章于 2024-02-07 11:33:55 发布