// Path: src/main/java/org/graylog/collector/MessageBuilder.java
// public class MessageBuilder {
//     private final long ownerId = Thread.currentThread().getId();
// 
//     private String message;
//     private String source;
//     private DateTime timestamp;
//     private Message.Level level;
//     private String input;
//     private Set<String> outputs;
//     private MessageFields fields = new MessageFields();
// 
//     public MessageBuilder() {
//     }
// 
//     private MessageBuilder(String message, String source, DateTime timestamp, Message.Level level, String input, Set<String> outputs, MessageFields fields) {
//         this.message = message;
//         this.source = source;
//         this.timestamp = timestamp;
//         this.level = level;
//         this.input = input;
//         this.outputs = outputs;
//         this.fields = fields;
//     }
// 
//     public MessageBuilder message(String message) {
//         checkOwnership();
//         this.message = message;
//         return this;
//     }
// 
//     public MessageBuilder source(String source) {
//         checkOwnership();
//         this.source = source;
//         return this;
//     }
// 
//     public MessageBuilder timestamp(DateTime timestamp) {
//         checkOwnership();
//         this.timestamp = timestamp;
//         return this;
//     }
// 
//     public MessageBuilder level(Message.Level level) {
//         checkOwnership();
//         this.level = level;
//         return this;
//     }
// 
//     public MessageBuilder input(String input) {
//         checkOwnership();
//         this.input = input;
//         return this;
//     }
// 
//     public MessageBuilder outputs(Set<String> outputs) {
//         checkOwnership();
//         if (outputs == null) {
//             this.outputs = null;
//         } else {
//             this.outputs = ImmutableSet.copyOf(outputs);
//         }
//         return this;
//     }
// 
//     public MessageBuilder fields(MessageFields fields) {
//         checkOwnership();
//         this.fields = fields;
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, int value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, long value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, boolean value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, String value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public Message build() {
//         checkNotNull(message, "Message should not be null!");
//         checkNotNull(source, "Message source should not be null!");
//         checkNotNull(timestamp, "Message timestamp should not be null!");
//         checkNotNull(input, "Message input should not be null!");
//         checkNotNull(outputs, "Message outputs should not be null!");
// 
//         if (fields == null) {
//             return new Message(message, source, timestamp, level, input, outputs);
//         } else {
//             return new Message(message, source, timestamp, level, input, outputs, fields);
//         }
//     }
// 
//     public MessageBuilder copy() {
//         return new MessageBuilder(message, source, timestamp, level, input, outputs, fields.copy());
//     }
// 
//     private void checkOwnership() {
//         final long currentId = Thread.currentThread().getId();
//         checkState(ownerId == currentId, "Modification only allowed by owning thread. (owner=" + ownerId + " current=" + currentId + ")");
//     }
// }
// 
// Path: src/main/java/org/graylog/collector/buffer/Buffer.java
// public interface Buffer {
//     void insert(Message message);
// 
//     Message remove();
// }


import org.graylog.collector.Message;
import org.graylog.collector.MessageBuilder;
import org.graylog.collector.buffer.Buffer;
import org.hyperic.sigar.win32.EventLogNotification;
import org.hyperic.sigar.win32.EventLogRecord;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Strings.isNullOrEmpty;
/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.graylog.collector.inputs.eventlog;



public class WindowsEventlogHandler implements EventLogNotification {
    private static final Logger LOG = LoggerFactory.getLogger(WindowsEventlogHandler.class);

    private final MessageBuilder messageBuilder;
    private final Buffer buffer;

    public WindowsEventlogHandler(MessageBuilder messageBuilder, Buffer buffer) {
        this.messageBuilder = messageBuilder;
        this.buffer = buffer;
    }

    @Override
    public boolean matches(EventLogRecord eventLogRecord) {
        return true;
    }

    @Override
    public void handleNotification(EventLogRecord record) {
        LOG.debug("EventLogRecord: {}", record);

        final MessageBuilder builder = messageBuilder
                .copy()
                .message(isNullOrEmpty(record.getMessage()) ? "empty" : record.getMessage().trim())
                .timestamp(getDateTime(record.getTimeGenerated()))
                .level(getMessageLevel(record));

        builder.addField("event_source", record.getSource());
        builder.addField("event_category", record.getCategory());
        builder.addField("event_category_string", record.getCategoryString());
        builder.addField("event_computer_name", record.getComputerName());
        builder.addField("event_id", record.getEventId());
        builder.addField("event_type", record.getEventType());
        builder.addField("event_type_string", record.getEventTypeString());
// Path: src/main/java/org/graylog/collector/MessageBuilder.java
// public class MessageBuilder {
//     private final long ownerId = Thread.currentThread().getId();
// 
//     private String message;
//     private String source;
//     private DateTime timestamp;
//     private Message.Level level;
//     private String input;
//     private Set<String> outputs;
//     private MessageFields fields = new MessageFields();
// 
//     public MessageBuilder() {
//     }
// 
//     private MessageBuilder(String message, String source, DateTime timestamp, Message.Level level, String input, Set<String> outputs, MessageFields fields) {
//         this.message = message;
//         this.source = source;
//         this.timestamp = timestamp;
//         this.level = level;
//         this.input = input;
//         this.outputs = outputs;
//         this.fields = fields;
//     }
// 
//     public MessageBuilder message(String message) {
//         checkOwnership();
//         this.message = message;
//         return this;
//     }
// 
//     public MessageBuilder source(String source) {
//         checkOwnership();
//         this.source = source;
//         return this;
//     }
// 
//     public MessageBuilder timestamp(DateTime timestamp) {
//         checkOwnership();
//         this.timestamp = timestamp;
//         return this;
//     }
// 
//     public MessageBuilder level(Message.Level level) {
//         checkOwnership();
//         this.level = level;
//         return this;
//     }
// 
//     public MessageBuilder input(String input) {
//         checkOwnership();
//         this.input = input;
//         return this;
//     }
// 
//     public MessageBuilder outputs(Set<String> outputs) {
//         checkOwnership();
//         if (outputs == null) {
//             this.outputs = null;
//         } else {
//             this.outputs = ImmutableSet.copyOf(outputs);
//         }
//         return this;
//     }
// 
//     public MessageBuilder fields(MessageFields fields) {
//         checkOwnership();
//         this.fields = fields;
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, int value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, long value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, boolean value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public MessageBuilder addField(String key, String value) {
//         checkOwnership();
//         checkNotNull(fields);
//         this.fields.put(key, value);
//         return this;
//     }
// 
//     public Message build() {
//         checkNotNull(message, "Message should not be null!");
//         checkNotNull(source, "Message source should not be null!");
//         checkNotNull(timestamp, "Message timestamp should not be null!");
//         checkNotNull(input, "Message input should not be null!");
//         checkNotNull(outputs, "Message outputs should not be null!");
// 
//         if (fields == null) {
//             return new Message(message, source, timestamp, level, input, outputs);
//         } else {
//             return new Message(message, source, timestamp, level, input, outputs, fields);
//         }
//     }
// 
//     public MessageBuilder copy() {
//         return new MessageBuilder(message, source, timestamp, level, input, outputs, fields.copy());
//     }
// 
//     private void checkOwnership() {
//         final long currentId = Thread.currentThread().getId();
//         checkState(ownerId == currentId, "Modification only allowed by owning thread. (owner=" + ownerId + " current=" + currentId + ")");
//     }
// }
// 
// Path: src/main/java/org/graylog/collector/buffer/Buffer.java
// public interface Buffer {
//     void insert(Message message);
// 
//     Message remove();
// }


// Path: src/main/java/org/graylog/collector/inputs/eventlog/WindowsEventlogHandler.java
import org.graylog.collector.Message;
import org.graylog.collector.MessageBuilder;
import org.graylog.collector.buffer.Buffer;
import org.hyperic.sigar.win32.EventLogNotification;
import org.hyperic.sigar.win32.EventLogRecord;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Strings.isNullOrEmpty;

/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.graylog.collector.inputs.eventlog;



public class WindowsEventlogHandler implements EventLogNotification {
    private static final Logger LOG = LoggerFactory.getLogger(WindowsEventlogHandler.class);

    private final MessageBuilder messageBuilder;
    private final Buffer buffer;

    public WindowsEventlogHandler(MessageBuilder messageBuilder, Buffer buffer) {
        this.messageBuilder = messageBuilder;
        this.buffer = buffer;
    }

    @Override
    public boolean matches(EventLogRecord eventLogRecord) {
        return true;
    }

    @Override
    public void handleNotification(EventLogRecord record) {
        LOG.debug("EventLogRecord: {}", record);

        final MessageBuilder builder = messageBuilder
                .copy()
                .message(isNullOrEmpty(record.getMessage()) ? "empty" : record.getMessage().trim())
                .timestamp(getDateTime(record.getTimeGenerated()))
                .level(getMessageLevel(record));

        builder.addField("event_source", record.getSource());
        builder.addField("event_category", record.getCategory());
        builder.addField("event_category_string", record.getCategoryString());
        builder.addField("event_computer_name", record.getComputerName());
        builder.addField("event_id", record.getEventId());
        builder.addField("event_type", record.getEventType());
        builder.addField("event_type_string", record.getEventTypeString());
        builder.addField("event_log_name", record.getLogName());