PSAX Trap 翻譯(2)
接著,用mibble把acmib中所有事件導入數據庫:
/**
* 導入事件
*/
public void importEvent(){
MibBrowser mb = new MibBrowser();
Mib mib = mb.getMib("e:/ACMIB.mib");
List mvss = (List)mib.getAllSymbols();
Connection conn = ConnectionManager.getConnection();
int id = 1;
try{
Statement stat = conn.createStatement();
for(int i=0,n=mvss.size();i<n;i++){
if(mvss.get(i) instanceof MibValueSymbol
&& ((MibValueSymbol)mvss.get(i)).getType() instanceof SnmpNotificationType) {
MibValueSymbol mvs = (MibValueSymbol)mvss.get(i);
SnmpNotificationType snt = (SnmpNotificationType)mvs.getType();
String descr = null;
String originDescr = null;
if(snt.getDescription().indexOf(":") > 0)
descr = snt.getDescription().substring(snt.getDescription().indexOf(":") + 2);
else
descr = snt.getDescription();
if(descr.indexOf("Return value") > 0)
descr = descr.substring(0,descr.indexOf("Return value"));
if(descr.indexOf("Data send with the trap") > 0)
descr = descr.substring(0,descr.indexOf("Data send with the trap"));
descr = descr.replaceAll("\n", " ");
descr = descr.replaceAll("'", "''");
originDescr = snt.getDescription().replaceAll("'", "''");
stat.addBatch("insert into acmib_event(id,symbol,description,origin_description)values(" + id + ",'" + mvs.getName() + "','" + descr + "','" + originDescr + "')");
id++;
if( id % 100 == 0)
stat.executeBatch();
}
}
stat.executeBatch();
}catch(Exception e){
e.printStackTrace();
}
}
結果如下:








































結果如下:
