Changeset 46


Ignore:
Timestamp:
Jul 25, 2008, 6:26:50 PM (16 years ago)
Author:
waue
Message:

SnortBase? -> complete and work fine ..

Location:
sample/hadoop-0.16
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sample/hadoop-0.16/test.java

    r45 r46  
    77import java.io.IOException;
    88import java.io.RandomAccessFile;
     9import java.text.ParsePosition;
    910import java.text.SimpleDateFormat;
    1011import java.util.Date;
     
    252253  }
    253254
    254   void Date()throws Exception{
    255     String da = "20/Jul/2008:08:26:55";
    256     SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",Locale.US);
     255  void Date() throws Exception {
     256    String da = "10/Jul/2008:08:26:55";
     257    SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",
     258        Locale.US);
    257259    Date timestamp = sdf.parse(da);
     260    long timeint = timestamp.getTime();
    258261    System.out.println(timestamp.toString());
     262    System.out.println(timeint);
     263  }
     264
     265  void getNowTime() {
     266    SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
     267    Date date = new Date();
     268    String strDate = sdFormat.format(date);
     269    System.out.println(strDate);
     270    System.out.println(date.getTime());
     271  }
     272
     273  void setTime() {
     274    String str = "07/08:01:01:01";
     275    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM:HH:mm:ss",
     276        Locale.TAIWAN);
     277    Date tim = sdf.parse(str, new ParsePosition(0));
     278    System.out.println(tim);
     279    Long timestamp = tim.getTime();
     280    System.out.println(timestamp);
     281
    259282  }
    260283
     
    278301    // 測試 enum 列舉
    279302    // t.enumTest();
    280     t.Date();
     303    // 測試設定
     304    // t.Date();
     305    // 測試取得現在時間
     306    // t.getNowTime();
     307    t.setTime();
    281308  }
    282309
  • sample/hadoop-0.16/tw/org/nchc/code/SnortBase.java

    r45 r46  
    5050import java.io.FileWriter;
    5151import java.io.IOException;
     52import java.text.ParseException;
     53import java.text.ParsePosition;
    5254import java.text.SimpleDateFormat;
     55import java.util.Date;
    5356import java.util.Locale;
    5457
     
    7275import org.apache.hadoop.mapred.Reporter;
    7376
     77
    7478class Log {
    7579
    76   public Log(String data) throws Exception {
     80  public Log(String data) {
    7781
    7882    String[] arr = data.split(";");
     
    8488    this.class_type = arr[4];
    8589    this.priority = arr[5];
    86     // this.timestamp = "2008" + arr[6] + arr[7] + arr[8] + arr[9] +
    87     // arr[10];
    88     this.timestamp = getTime(arr[7] + "/" + arr[6] + "/2008:" + arr[8]
     90    this.timestamp = getTime(arr[7] + "/" + arr[6] + ":" + arr[8]
    8991        + ":" + arr[9] + ":" + arr[10]);
     92//    this.timestamp = now.getTime();
    9093    this.source = arr[11];
    9194    this.destination = arr[12];
     
    98101
    99102  }
    100 
     103  Date now = new Date();
    101104  long timestamp;
    102105
     
    107110  String source, destination, type, ttl, tos, id, iplen, dgmlen;
    108111
    109   long getTime(String str) throws Exception {
    110     SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",
     112  long getTime(String str) {
     113    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM:HH:mm:ss",
    111114        Locale.TAIWAN);
    112     Long timestamp = sdf.parse(str).getTime();
     115    Long timestamp = sdf.parse(str,new ParsePosition(0)).getTime();
    113116    return timestamp;
    114117  }
     
    121124  public static final String TABLE = "table.name";
    122125
    123   static String tableName = "mySnort";
     126  static String tableName = "SnortBase";
    124127
    125128  static HTable table = null;
     
    140143    public void map(WritableComparable key, Text value,
    141144        OutputCollector<Text, Writable> output, Reporter reporter)
    142         throws IOException {
    143 
    144       try {
     145        throws IOException{
     146
     147//      try {
    145148
    146149        Log log = new Log(value.toString());
     
    181184        table.commit(lockId, log.timestamp);
    182185
    183       } catch (Exception e) {
    184         e.printStackTrace();
    185       }
     186//      } catch (Exception e) {
     187//        e.printStackTrace();
     188//      }
    186189
    187190    }
     
    200203  }
    201204
    202   public static void runMapReduce(String table, String inpath)
     205  public static void runMapReduce(String tableName, String inpath)
    203206      throws IOException {
    204207    Path tempDir = new Path("/tmp/Mylog/");
     
    207210    JobConf jobConf = new JobConf(conf, SnortBase.class);
    208211    jobConf.setJobName("Snort Parse");
    209     jobConf.set(TABLE, table);
     212    jobConf.set(TABLE, tableName);
    210213    // 先省略 自動搜尋目錄的功能
    211214    /*
     
    224227    jobConf.setNumMapTasks(cluster.getMapTasks());
    225228    jobConf.setNumReduceTasks(0);
     229    fs.delete(tempDir);
    226230    JobClient.runJob(jobConf);
    227231    fs.delete(tempDir);
     
    248252
    249253  public static void main(String[] args) throws IOException, Exception {
    250     String table_name = "snort";
     254
    251255    String path = "/user/waue/alert_meta";
    252256
     
    256260     * SnortParser("/tmp/alert","/tmp/alert_SnortBase"); sp.parseToLine();
    257261     */
    258     creatTable(table_name);
    259 
    260     runMapReduce(table_name, path);
     262    creatTable(tableName);
     263
     264    runMapReduce(tableName, path);
    261265
    262266  }
Note: See TracChangeset for help on using the changeset viewer.