afunms

My Software,My Dream—Forge a more perfect NMS product.

PSAX Trap 翻译(1)

     今天终于实现把朗讯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();
        }

    }
结果如下:


posted on 2009-10-21 10:47 afunms 阅读(230) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

My Links

News

留言簿(18)

随笔档案

相册

搜索

最新评论

阅读排行榜