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

SnortBase? -> complete and work fine ..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.