Changeset 46 for sample/hadoop-0.16/tw/org/nchc
- Timestamp:
- Jul 25, 2008, 6:26:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/hadoop-0.16/tw/org/nchc/code/SnortBase.java
r45 r46 50 50 import java.io.FileWriter; 51 51 import java.io.IOException; 52 import java.text.ParseException; 53 import java.text.ParsePosition; 52 54 import java.text.SimpleDateFormat; 55 import java.util.Date; 53 56 import java.util.Locale; 54 57 … … 72 75 import org.apache.hadoop.mapred.Reporter; 73 76 77 74 78 class Log { 75 79 76 public Log(String data) throws Exception{80 public Log(String data) { 77 81 78 82 String[] arr = data.split(";"); … … 84 88 this.class_type = arr[4]; 85 89 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] 89 91 + ":" + arr[9] + ":" + arr[10]); 92 // this.timestamp = now.getTime(); 90 93 this.source = arr[11]; 91 94 this.destination = arr[12]; … … 98 101 99 102 } 100 103 Date now = new Date(); 101 104 long timestamp; 102 105 … … 107 110 String source, destination, type, ttl, tos, id, iplen, dgmlen; 108 111 109 long getTime(String str) throws Exception{110 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM M/yyyy:HH:mm:ss",112 long getTime(String str) { 113 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM:HH:mm:ss", 111 114 Locale.TAIWAN); 112 Long timestamp = sdf.parse(str ).getTime();115 Long timestamp = sdf.parse(str,new ParsePosition(0)).getTime(); 113 116 return timestamp; 114 117 } … … 121 124 public static final String TABLE = "table.name"; 122 125 123 static String tableName = " mySnort";126 static String tableName = "SnortBase"; 124 127 125 128 static HTable table = null; … … 140 143 public void map(WritableComparable key, Text value, 141 144 OutputCollector<Text, Writable> output, Reporter reporter) 142 throws IOException 143 144 try {145 throws IOException{ 146 147 // try { 145 148 146 149 Log log = new Log(value.toString()); … … 181 184 table.commit(lockId, log.timestamp); 182 185 183 } catch (Exception e) {184 e.printStackTrace();185 }186 // } catch (Exception e) { 187 // e.printStackTrace(); 188 // } 186 189 187 190 } … … 200 203 } 201 204 202 public static void runMapReduce(String table , String inpath)205 public static void runMapReduce(String tableName, String inpath) 203 206 throws IOException { 204 207 Path tempDir = new Path("/tmp/Mylog/"); … … 207 210 JobConf jobConf = new JobConf(conf, SnortBase.class); 208 211 jobConf.setJobName("Snort Parse"); 209 jobConf.set(TABLE, table );212 jobConf.set(TABLE, tableName); 210 213 // 先省略 自動搜尋目錄的功能 211 214 /* … … 224 227 jobConf.setNumMapTasks(cluster.getMapTasks()); 225 228 jobConf.setNumReduceTasks(0); 229 fs.delete(tempDir); 226 230 JobClient.runJob(jobConf); 227 231 fs.delete(tempDir); … … 248 252 249 253 public static void main(String[] args) throws IOException, Exception { 250 String table_name = "snort"; 254 251 255 String path = "/user/waue/alert_meta"; 252 256 … … 256 260 * SnortParser("/tmp/alert","/tmp/alert_SnortBase"); sp.parseToLine(); 257 261 */ 258 creatTable(table _name);259 260 runMapReduce(table _name, path);262 creatTable(tableName); 263 264 runMapReduce(tableName, path); 261 265 262 266 }
Note: See TracChangeset
for help on using the changeset viewer.