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 閱讀(247) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          My Links

          News

          留言簿(18)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 龙陵县| 周宁县| 都江堰市| 增城市| 丽水市| 沧州市| 科尔| 郎溪县| 台北县| 武宁县| 巫山县| 石柱| 青浦区| 宝兴县| 酒泉市| 五华县| 门头沟区| 岳西县| 泌阳县| 崇州市| 屯昌县| 峨眉山市| 侯马市| 樟树市| 西乌珠穆沁旗| 扶风县| 湘西| 叶城县| 桂林市| 茶陵县| 邵武市| 肇源县| 勐海县| 邓州市| 鲜城| 南昌市| 南川市| 牙克石市| 盐山县| 怀集县| 北川|