今天終于實現把朗訊PSAX ATM交換機的SNMP Trap翻譯成明文的功能。前后花了四天的時間。
開始,我想用mibble把acmib完全解析出來,但折騰了一整天,都沒有結果,至少最重要的OID是終始出不來,可能是我不會用mibble吧。
接著換種思路,用SolarWinds(一個很好用的mib browser)把acmib copy成純文本。
文本如下:
acMIB 1.3.6.1.4.1.1751.2.18
connectionConfig 1.3.6.1.4.1.1751.2.18.6
atmAtmSpvcVccTable 1.3.6.1.4.1.1751.2.18.6.33
atmAtmSpvcVccEntry 1.3.6.1.4.1.1751.2.18.6.33.1
atmAtmSpvcVccStatsInOdometerCellCountHiB 1.3.6.1.4.1.1751.2.18.6.33.1.50
atmAtmSpvcVccStatsInOdometerCellCountLoA 1.3.6.1.4.1.1751.2.18.6.33.1.47
atmAtmSpvcVccStatsInOdometerCellCountLoB 1.3.6.1.4.1.1751.2.18.6.33.1.51
atmAtmSpvcVccStatsOdometerReset 1.3.6.1.4.1.1751.2.18.6.33.1.55
atmAtmSpvcVccStatsOdometerTimer 1.3.6.1.4.1.1751.2.18.6.33.1.54
atmAtmSpvcVccStatsOutCellCountHiA1.3.6.1.4.1.1751.2.18.6.33.1.37
atmAtmSpvcVccStatsOutCellCountHiB1.3.6.1.4.1.1751.2.18.6.33.1.41
atmAtmSpvcVccStatsOutCellCountLoA 1.3.6.1.4.1.1751.2.18.6.33.1.38
atmAtmSpvcVccStatsOutCellCountLoB 1.3.6.1.4.1.1751.2.18.6.33.1.42
atmAtmSpvcVccStatsOutOdometerCellCountHiA1.3.6.1.4.1.1751.2.18.6.33.1.48
atmAtmSpvcVccStatsOutOdometerCellCountHiB1.3.6.1.4.1.1751.2.18.6.33.1.52
atmAtmSpvcVccStatsOutOdometerCellCountLoA 1.3.6.1.4.1.1751.2.18.6.33.1.49
atmAtmSpvcVccStatsOutOdometerCellCountLoB 1.3.6.1.4.1.1751.2.18.6.33.1.53
atmAtmSpvcVccStatsTimer 1.3.6.1.4.1.1751.2.18.6.33.1.43
atmAtmSpvcVccSusCellRateA2B 1.3.6.1.4.1.1751.2.18.6.33.1.10
atmAtmSpvcVccSusCellRateB2A 1.3.6.1.4.1.1751.2.18.6.33.1.16
atmAtmSpvcVccTfcDescModify 1.3.6.1.4.1.1751.2.18.6.33.1.70
atmAtmSpvcVccTrafficShapingA2B 1.3.6.1.4.1.1751.2.18.6.33.1.64
atmAtmSpvcVccTrafficShapingB2A 1.3.6.1.4.1.1751.2.18.6.33.1.65
atmAtmSpvcVccType 1.3.6.1.4.1.1751.2.18.6.33.1.20
atmAtmSpvcVccVciA 1.3.6.1.4.1.1751.2.18.6.33.1.2
atmAtmSpvcVccVciB 1.3.6.1.4.1.1751.2.18.6.33.1.6
atmAtmSpvcVccViA 1.3.6.1.4.1.1751.2.18.6.33.1.56
……
把這個文本導入數據庫:

/** *//**
* acmib.mib有兩個版本,此方法把兩個版本中數據都導入數據庫.
* 但保證不會有重復的oid
*/

public void importOid()
{
Connection conn = ConnectionManager.getConnection();

try
{
Statement stat = conn.createStatement();
BufferedReader in1 = new BufferedReader(new FileReader("e:/acmib.txt"));
String row = null;
int id = 1;

while((row=in1.readLine())!=null)
{
int loc = row.indexOf("1.3.6.");
String symbol = row.substring(0, loc - 1).trim();
String oid = row.substring(loc).trim();
stat.addBatch("insert into acmib_oid(id,oid,symbol)values(" + id + ",'" + oid + "','" + symbol + "')");
id++;
if( id % 100 == 0)
stat.executeBatch();
}
stat.executeBatch();
ResultSet rs = stat.executeQuery("select oid from acmib_oid order by oid");
List<String> oids = new ArrayList<String>();
while(rs.next())
oids.add(rs.getString(1));
BufferedReader in2 = new BufferedReader(new FileReader("e:/acmib2.txt"));

while((row=in2.readLine())!=null)
{
String[] rowCols = row.split(" ");
if(oids.contains(rowCols[2])) continue;

stat.addBatch("insert into acmib_oid(id,oid,symbol)values(" + id + ",'" + rowCols[2] + "','" + rowCols[1] + "')");
id++;
if( id % 100 == 0)
stat.executeBatch();
}
stat.executeBatch();

}catch(Exception e)
{
e.printStackTrace();
}
}
結果如下:
