Changeset 43


Ignore:
Timestamp:
Jul 23, 2008, 5:08:53 PM (16 years ago)
Author:
waue
Message:

HBaseRecordPro.java -> only modified for debuging SnortUploadHbase?.java

SnortParser?.java -> catch a bug and fix it

SnortUploadHbase?.java -> it can run finally ..

Location:
sample/hadoop-0.16/tw/org/nchc/code
Files:
3 edited

Legend:

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

    r27 r43  
    9797
    9898  // table name
    99   final static String table_name = "HBaseRecord";
     99  final static String table_name = "HBaseRecord2";
    100100
    101101  // separate char
    102   final static String sp = ":";
     102  final static String sp = ";";
    103103 
    104104  // conf tmp with column qualify
  • sample/hadoop-0.16/tw/org/nchc/code/SnortParser.java

    r33 r43  
    33 * Editor: Waue Chen
    44 * From :  NCHC. Taiwn
    5  * Last Update Date: 07/17/2008
     5 * Last Update Date: 07/23/2008
    66 */
    77
     
    4343    case 1:
    4444      patten_line = Pattern
    45           .compile("^\\[\\**\\] \\[([1-9]*):([1-9]*):([1-9]*)\\] ([^\\[]*)\\[\\**\\]$");
     45          .compile("^\\[\\**\\] \\[([0-9]*):([0-9]*):([0-9]*)\\] ([^\\[]*)\\[\\**\\]$");
    4646      break;
    4747    case 2:
     
    8080    int count = 0;
    8181    do {
    82       String tmp = fi.readLine();
    83       if (tmp == null) {
     82      line = fi.readLine();
     83      if (line == null) {
    8484        break;
    85       } else if (count < 4) {
    86         line = tmp;
     85      }else if(line.isEmpty()){
     86        fw.write(this.logData.toString() + "\n");
     87        this.logData = "";
     88        count = 0;       
     89      }else if (count < 4) {
    8790        // System.out.println(line);
    8891        snortParser(line, count + 1);
    8992        count++;
    90       } else if (count == 4) {
     93      } else {
    9194        count++;
    92       } else if (count == 5) {
    93         fw.write(this.logData.toString() + "\n");
    94         this.logData = "";
    95         count = 0;
    96       } else {
    97         System.err.print(" Error ! ");
    98         return;
    9995      }
    10096    } while (true);
     
    105101
    106102  public static void main(String[] args) throws ParseException, Exception {
    107     String in = new String("/home/waue/Desktop/alert");
    108     String ou = new String("/home/waue/Desktop/bb");
     103    String in = new String("/home/waue/Desktop/alert_m");
     104    String ou = new String("/tmp/alert_my");
    109105    SnortParser a = new SnortParser(in, ou);
    110106    a.parseToLine();
  • sample/hadoop-0.16/tw/org/nchc/code/SnortUploadHbase.java

    r33 r43  
    33 * Editor: Waue Chen
    44 * From :  NCHC. Taiwn
    5  * Last Update Date: 07/02/2008
     5 * Last Update Date: 07/23/2008
    66 */
    77
    88/**
    99 * Purpose :
    10  *  First, program would parse your record and create Hbase.\
    11  *  Then it sets the first line as column qualify \
    12  *  Finally it stores in HBase automatically.
     10 *  The program will parse the log of snort (/var/log/snort/alert)
     11 *    into Hbase table "snort".
    1312 *
    1413 * HowToUse :
    15  *  Make sure two thing :
    16  *  1. source_file must be regular as follow:
    17  *    first line: qualify1:qualify2:...:qualifyN
    18  *    other line: records1:records2:...:recordsN
    19  *  2. source_file path must be correct.
     14 *  Run by eclipse ! (dependency by SnortParser.java)
    2015
    2116 * Check Result:
    2217 *  Go to hbase console, type :
    23  *    hql > select * from t1_table;
     18 *    hql > select * from snort;
    2419
    2520
     
    4641import org.apache.hadoop.mapred.lib.IdentityReducer;
    4742
     43import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
     44
    4845public class SnortUploadHbase {
    4946  /* Major parameter */
     
    5653
    5754  // table name
    58   final static String table_name = "SnortTable";
     55  final static String table_name = "Snort";
    5956
    6057  // separate char
     
    6259 
    6360  // data source tmp
    64   final static String text_tmp = "/tmp/HBaseRecord.text.tmp";
     61  final static String text_tmp = "/tmp/alert_my";
    6562
    6663  // on this sample, map is nonuse, we use reduce to handle
     
    7168
    7269      String first_line = "gid;sid;version;alert name;" +
    73           "class;priority;year;month;day;hour;min;second;source;" +
    74           "destination;type;ttl;tos;id; iplen;dgmlen";
     70          "class;priority;month;day;hour;min;second;source;" +
     71          "destination;type;ttl;tos;id; iplen;dgmlen;";
    7572
    7673      // extract cf data
     
    124121   * Runs the demo.
    125122   */
    126   public static void main(String[] args) throws IOException {
     123  public static void main(String[] args) throws IOException,ParseException,Exception {
    127124   
    128125    String[] col_family = {column_family};
     
    131128//    setup.parseFirstLine(source_file, text_tmp);
    132129//    System.out.println(first_line);
    133     new SnortParser(source_file,text_tmp);
     130    SnortParser sp = new SnortParser(source_file,text_tmp);
     131    sp.parseToLine();
    134132   
    135133   
Note: See TracChangeset for help on using the changeset viewer.