Changeset 43 for sample/hadoop-0.16/tw/org/nchc/code
- Timestamp:
- Jul 23, 2008, 5:08:53 PM (16 years ago)
- 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 97 97 98 98 // table name 99 final static String table_name = "HBaseRecord ";99 final static String table_name = "HBaseRecord2"; 100 100 101 101 // separate char 102 final static String sp = " :";102 final static String sp = ";"; 103 103 104 104 // conf tmp with column qualify -
sample/hadoop-0.16/tw/org/nchc/code/SnortParser.java
r33 r43 3 3 * Editor: Waue Chen 4 4 * From : NCHC. Taiwn 5 * Last Update Date: 07/ 17/20085 * Last Update Date: 07/23/2008 6 6 */ 7 7 … … 43 43 case 1: 44 44 patten_line = Pattern 45 .compile("^\\[\\**\\] \\[([ 1-9]*):([1-9]*):([1-9]*)\\] ([^\\[]*)\\[\\**\\]$");45 .compile("^\\[\\**\\] \\[([0-9]*):([0-9]*):([0-9]*)\\] ([^\\[]*)\\[\\**\\]$"); 46 46 break; 47 47 case 2: … … 80 80 int count = 0; 81 81 do { 82 String tmp= fi.readLine();83 if ( tmp== null) {82 line = fi.readLine(); 83 if (line == null) { 84 84 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) { 87 90 // System.out.println(line); 88 91 snortParser(line, count + 1); 89 92 count++; 90 } else if (count == 4){93 } else { 91 94 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;99 95 } 100 96 } while (true); … … 105 101 106 102 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"); 109 105 SnortParser a = new SnortParser(in, ou); 110 106 a.parseToLine(); -
sample/hadoop-0.16/tw/org/nchc/code/SnortUploadHbase.java
r33 r43 3 3 * Editor: Waue Chen 4 4 * From : NCHC. Taiwn 5 * Last Update Date: 07/ 02/20085 * Last Update Date: 07/23/2008 6 6 */ 7 7 8 8 /** 9 9 * 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". 13 12 * 14 13 * 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) 20 15 21 16 * Check Result: 22 17 * Go to hbase console, type : 23 * hql > select * from t1_table;18 * hql > select * from snort; 24 19 25 20 … … 46 41 import org.apache.hadoop.mapred.lib.IdentityReducer; 47 42 43 import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException; 44 48 45 public class SnortUploadHbase { 49 46 /* Major parameter */ … … 56 53 57 54 // table name 58 final static String table_name = "Snort Table";55 final static String table_name = "Snort"; 59 56 60 57 // separate char … … 62 59 63 60 // data source tmp 64 final static String text_tmp = "/tmp/ HBaseRecord.text.tmp";61 final static String text_tmp = "/tmp/alert_my"; 65 62 66 63 // on this sample, map is nonuse, we use reduce to handle … … 71 68 72 69 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;"; 75 72 76 73 // extract cf data … … 124 121 * Runs the demo. 125 122 */ 126 public static void main(String[] args) throws IOException {123 public static void main(String[] args) throws IOException,ParseException,Exception { 127 124 128 125 String[] col_family = {column_family}; … … 131 128 // setup.parseFirstLine(source_file, text_tmp); 132 129 // System.out.println(first_line); 133 new SnortParser(source_file,text_tmp); 130 SnortParser sp = new SnortParser(source_file,text_tmp); 131 sp.parseToLine(); 134 132 135 133
Note: See TracChangeset
for help on using the changeset viewer.