Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package parse;
- import java.util.HashMap;
- import java.util.Objects;
- import org.javatuples.Pair;
- public class AuParser {
- private final static String libraryName = "au";
- static {
- System.loadLibrary(libraryName);
- }
- private long address;
- public AuParser() {
- }
- private native int firstField();
- private native int firstRecord();
- private native int nextField();
- private native int reset();
- private native int getMilliSeconds();
- private native long getSerial();
- private native long getSeconds();
- private native long init(String log);
- private native String getHost();
- private native String getFieldName();
- private native String getFieldStr();
- private native String findField(String name);
- private native String interpretField();
- public HashMap parseEvent(String log) {
- HashMap<String, Object> event = new HashMap<>();
- Pair<String, String> parsedLine = parseFlumeLine(log);
- String line = parsedLine.getValue0();
- String host = parsedLine.getValue1();
- address = init(line);
- firstRecord();
- firstField();
- while (true) {
- String field = getFieldName();
- String fieldValue = getFieldStr();
- if (Objects.equals(field, "hostname")) {
- fieldValue = fieldValue.substring(1, fieldValue.length());
- }
- event.put(field, fieldValue);
- if (nextField() == 0)
- break;
- }
- reset();
- firstRecord();
- if (!event.containsKey("type")) {
- event.put("type", "TRASH");
- }
- if (event.get("type").equals("SYSCALL")) {
- findField("syscall");
- event.put("syscall", interpretField());
- }
- int milliSeconds = getMilliSeconds();
- long seconds = getSeconds();
- int timestamp = (int)(1000*seconds + (float)milliSeconds);
- event.put("timestamp", timestamp);
- event.put("event_id", getSerial());
- event.putIfAbsent("hostname", host);
- return event;
- }
- private Pair<String, String> parseFlumeLine(String log) {
- char tenth = log.charAt(10);
- int ord = (int) tenth;
- int hostIndex= 11 + ord/2;
- int k = 3;
- if (log.charAt(hostIndex + 2) == 't') {
- k = 2;
- }
- int logLength = log.length();
- String line = log.substring(hostIndex + k, logLength);
- String host = log.substring(11, hostIndex);
- return new Pair<>(line, host);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement