Ignore:
Timestamp:
Aug 8, 2008, 4:37:54 PM (16 years ago)
Author:
waue
Message:

SnortBase?.java -> tuning some field
SnortParser?.java -> debug and fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sample/hadoop-0.16/tw/org/nchc/code/SnortBase.java

    r46 r47  
    4747package tw.org.nchc.code;
    4848
    49 import java.io.File;
    50 import java.io.FileWriter;
    5149import java.io.IOException;
    52 import java.text.ParseException;
    5350import java.text.ParsePosition;
    5451import java.text.SimpleDateFormat;
     
    7572import org.apache.hadoop.mapred.Reporter;
    7673
    77 
    7874class Log {
    79 
    80   public Log(String data)  {
     75  String gid, sid, version;
     76
     77  String alert_name, class_type, priority;
     78
     79  String source, destination, type;
     80
     81  // String ttl, tos, id, iplen, dgmlen;
     82 
     83  String srcport, dstport,tmp;
     84  public Log(String data) {
    8185
    8286    String[] arr = data.split(";");
    83 
    8487    this.gid = arr[0];
    8588    this.sid = arr[1];
     
    8891    this.class_type = arr[4];
    8992    this.priority = arr[5];
    90     this.timestamp = getTime(arr[7] + "/" + arr[6] + ":" + arr[8]
    91         + ":" + arr[9] + ":" + arr[10]);
    92 //    this.timestamp = now.getTime();
    93     this.source = arr[11];
    94     this.destination = arr[12];
     93    this.timestamp = getTime(arr[7] + "/" + arr[6] + ":" + arr[8] + ":"
     94        + arr[9] + ":" + arr[10]);
     95    this.source = getIP(arr[11]);
     96    this.srcport = this.tmp;
     97    this.destination = getIP(arr[12]);
     98    this.dstport = this.tmp;
    9599    this.type = arr[13];
    96     this.ttl = arr[14];
    97     this.tos = arr[15];
    98     this.id = arr[16];
    99     this.iplen = arr[17];
    100     this.dgmlen = arr[18];
    101 
    102   }
    103   Date now = new Date();
     100    // this.ttl = arr[14];
     101    // this.tos = arr[15];
     102    // this.id = arr[16];
     103    // this.iplen = arr[17];
     104    // this.dgmlen = arr[18];
     105   
     106  }
    104107  long timestamp;
    105108
    106   String gid, sid, version;
    107 
    108   String alert_name, class_type, priority;
    109 
    110   String source, destination, type, ttl, tos, id, iplen, dgmlen;
     109
     110  String getIP(String str){
     111    String res;
     112    int n = str.indexOf(":");
     113    if (n == -1) {
     114      res = str;
     115      this.tmp = "0";
     116    } else {
     117      String[] vec = str.split(":");
     118      res = vec[0];
     119      this.tmp = vec[1];
     120    }
     121    return res;
     122  }
    111123
    112124  long getTime(String str) {
    113125    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM:HH:mm:ss",
    114126        Locale.TAIWAN);
    115     Long timestamp = sdf.parse(str,new ParsePosition(0)).getTime();
     127    Long timestamp = sdf.parse(str, new ParsePosition(0)).getTime();
    116128    return timestamp;
    117129  }
     
    124136  public static final String TABLE = "table.name";
    125137
    126   static String tableName = "SnortBase";
     138  static String tableName = "flex";
    127139
    128140  static HTable table = null;
    129 
    130141
    131142  public static class MapClass extends MapReduceBase implements
     
    143154    public void map(WritableComparable key, Text value,
    144155        OutputCollector<Text, Writable> output, Reporter reporter)
    145         throws IOException{
    146 
    147 //      try {
    148 
    149         Log log = new Log(value.toString());
    150        
    151         // 查看value的值
    152         FileWriter out = new FileWriter(new File(
    153             "/home/waue/Desktop/snort-result.txt"));
    154         out.write(value.toString() + "_time=" + log.timestamp + "\n");
    155         out.flush();
    156         out.close();
    157 
    158         if (table == null)
    159           table = new HTable(conf, new Text(tableName));
    160 
    161         long lockId = table.startUpdate(new Text(log.destination));
    162         table.put(lockId, new Text("id:gid"), log.gid.getBytes());
    163         table.put(lockId, new Text("id:sid"), log.sid.getBytes());
    164         table.put(lockId, new Text("id:version"), log.version
    165             .getBytes());
    166         table.put(lockId, new Text("name:name"), log.alert_name
    167             .getBytes());
    168         table.put(lockId, new Text("name:class"), log.class_type
    169             .getBytes());
    170         table.put(lockId, new Text("index:priority"), log.priority
    171             .getBytes());
    172         table.put(lockId, new Text("index:soure"), log.source
    173             .getBytes());
    174         table
    175             .put(lockId, new Text("payload:type"), log.type
    176                 .getBytes());
    177         table.put(lockId, new Text("payload:ttl"), log.ttl.getBytes());
    178         table.put(lockId, new Text("payload:tos"), log.tos.getBytes());
    179         table.put(lockId, new Text("payload:id"), log.id.getBytes());
    180         table.put(lockId, new Text("payload:iplen"), log.iplen
    181             .getBytes());
    182         table.put(lockId, new Text("payload:dgmlen"), log.dgmlen
    183             .getBytes());
    184         table.commit(lockId, log.timestamp);
    185 
    186 //      } catch (Exception e) {
    187 //        e.printStackTrace();
    188 //      }
     156        throws IOException {
     157
     158      // try {
     159
     160      Log log = new Log(value.toString());
     161
     162      // 查看value的值
     163      // FileWriter out = new FileWriter(new File(
     164      // "/home/waue/Desktop/snort-result.txt"));
     165      // out.write(value.toString() + "_time=" + log.timestamp + "\n");
     166      // out.flush();
     167      // out.close();
     168
     169      if (table == null)
     170        table = new HTable(conf, new Text(tableName));
     171
     172      long lockId = table.startUpdate(new Text(log.destination));
     173      table.put(lockId, new Text("id:gid"), log.gid.getBytes());
     174      table.put(lockId, new Text("id:sid"), log.sid.getBytes());
     175      table.put(lockId, new Text("id:version"), log.version.getBytes());
     176      table.put(lockId, new Text("name:name"), log.alert_name.getBytes());
     177      table
     178          .put(lockId, new Text("name:class"), log.class_type
     179              .getBytes());
     180      table.put(lockId, new Text("id:priority"), log.priority
     181          .getBytes());
     182      table.put(lockId, new Text("direction:soure"), log.source.getBytes());
     183      table.put(lockId, new Text("direction:srcport"), log.srcport.getBytes());
     184      table.put(lockId, new Text("direction:dstport"), log.dstport.getBytes());
     185      table.put(lockId, new Text("payload:type"), log.type.getBytes());
     186      // table.put(lockId, new Text("payload:ttl"), log.ttl.getBytes());
     187      // table.put(lockId, new Text("payload:tos"), log.tos.getBytes());
     188      // table.put(lockId, new Text("payload:id"), log.id.getBytes());
     189      // table.put(lockId, new Text("payload:iplen"), log.iplen
     190      // .getBytes());
     191      // table.put(lockId, new Text("payload:dgmlen"), log.dgmlen
     192      // .getBytes());
     193      table.commit(lockId, log.timestamp);
     194
     195      // } catch (Exception e) {
     196      // e.printStackTrace();
     197      // }
    189198
    190199    }
     
    212221    jobConf.set(TABLE, tableName);
    213222    // 先省略 自動搜尋目錄的功能
    214     /*
    215      * Path[] in = listPaths(fs, InputDir); if (fs.isFile(InputDir)) {
    216      * jobConf.setInputPath(InputDir); } else { for (int i = 0; i <
    217      * in.length; i++) { if (fs.isFile(in[i])) {
    218      * jobConf.addInputPath(in[i]); } else { Path[] sub = listPaths(fs,
    219      * in[i]); for (int j = 0; j < sub.length; j++) { if (fs.isFile(sub[j])) {
    220      * jobConf.addInputPath(sub[j]); } } } } }
    221      */
     223    // Path InputDir = new Path(inpath);
     224    // Path[] in = listPaths(fs, InputDir);
     225    // if (fs.isFile(InputDir))
     226    // {
     227    // jobConf.setInputPath(InputDir);
     228    // }
     229    // else{
     230    // for (int i = 0; i < in.length; i++){
     231    // if (fs.isFile(in[i])){
     232    // jobConf.addInputPath(in[i]);
     233    // } else
     234    // {
     235    // Path[] sub = listPaths(fs, in[i]);
     236    // for (int j = 0; j < sub.length; j++)
     237    // {
     238    // if (fs.isFile(sub[j]))
     239    // {
     240    // jobConf.addInputPath(sub[j]);
     241    // } } } } }
     242
    222243    jobConf.setInputPath(InputPath);
    223244    jobConf.setOutputPath(tempDir);
     
    241262      tableDesc.addFamily(new HColumnDescriptor("id:"));
    242263      tableDesc.addFamily(new HColumnDescriptor("name:"));
    243       tableDesc.addFamily(new HColumnDescriptor("index:"));
     264      tableDesc.addFamily(new HColumnDescriptor("direction:"));
    244265      tableDesc.addFamily(new HColumnDescriptor("payload:"));
    245       tableDesc.addFamily(new HColumnDescriptor("priority:"));
    246266      admin.createTable(tableDesc);
    247267    } else {
     
    253273  public static void main(String[] args) throws IOException, Exception {
    254274
    255     String path = "/user/waue/alert_meta";
     275    String path = "/user/waue/snort-log/alert_flex_parsed.txt";
    256276
    257277    // 先省略掉 parse完後自動上傳部份
Note: See TracChangeset for help on using the changeset viewer.