Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code touchups #89

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/glassfish_logging/glassfish_to_gelf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def transform_level(level)
end

$stdin.each("#]\n\n") do |line|
if line =~ /^\[#/ then
if line =~ /^\[#/
fields = line.chomp.split("|")

message = { "host" => hostname,
Expand Down
4 changes: 2 additions & 2 deletions misc/convert_rsyslog_db_to_mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

begin
dbh = Mysql.real_connect("localhost", "root", "mama", "Syslog")
res = dbh.query("SELECT Message, ReceivedAt, FromHost, Facility, Priority FROM SystemEvents ORDER BY ReceivedAt ASC");
res = dbh.query("SELECT Message, ReceivedAt, FromHost, Facility, Priority FROM SystemEvents ORDER BY ReceivedAt ASC")

db = Mongo::Connection.new.db("graylog2")
coll = db.collection("messages")

Expand Down
2 changes: 1 addition & 1 deletion misc/gnome-icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.notify message
class Graylog2Icon
def initialize
@icon = Gtk::StatusIcon.new
@icon.pixbuf = Gdk::Pixbuf.new(TRAYICON, 20, 20);
@icon.pixbuf = Gdk::Pixbuf.new(TRAYICON, 20, 20)
@icon.tooltip = "Graylog"
end

Expand Down
49 changes: 0 additions & 49 deletions src/main/java/org/graylog2/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,6 @@ public class Configuration {
@Parameter(value = "gelf_listen_port", required = true, validator = InetPortValidator.class)
private int gelfListenPort = 12201;

@Parameter("amqp_enabled")
private boolean amqpEnabled = false;

@Parameter("amqp_host")
private String amqpHost = "localhost";

@Parameter(value = "amqp_port", validator = InetPortValidator.class)
private int amqpPort = 5672;

@Parameter(value = "amqp_subscribed_queues", converter = StringListConverter.class)
private List<String> amqpSubscribedQueues;

@Parameter("amqp_username")
private String amqpUsername = "guest";

@Parameter("amqp_password")
private String amqpPassword = "guest";

@Parameter("amqp_virtualhost")
private String amqpVirtualhost = "/";

@Parameter(value = "forwarder_loggly_timeout", validator = PositiveIntegerValidator.class)
private int forwarderLogglyTimeout = 3;

Expand Down Expand Up @@ -237,10 +216,6 @@ public int getRecentIndexTtlMinutes() {
return recentIndexTtlMinutes;
}

public boolean performRetention() {
return !noRetention;
}

public int getOutputBatchSize() {
return outputBatchSize;
}
Expand Down Expand Up @@ -297,30 +272,6 @@ public int getGelfListenPort() {
return gelfListenPort;
}

public boolean isAmqpEnabled() {
return amqpEnabled;
}

public String getAmqpHost() {
return amqpHost;
}

public int getAmqpPort() {
return amqpPort;
}

public String getAmqpUsername() {
return amqpUsername;
}

public String getAmqpPassword() {
return amqpPassword;
}

public String getAmqpVirtualhost() {
return amqpVirtualhost;
}

public int getForwarderLogglyTimeout() {
return forwarderLogglyTimeout * 1000;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/graylog2/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static void main(String[] args) {
server.initialize(configuration);

// Register initializers.
server.registerInitializer(new ServerValueWriterInitializer(server, configuration));
server.registerInitializer(new ServerValueWriterInitializer(server));
server.registerInitializer(new DroolsInitializer(server, configuration));
server.registerInitializer(new HostCounterCacheWriterInitializer(server));
server.registerInitializer(new MessageCounterInitializer(server));
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/org/graylog2/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@

package org.graylog2;

import org.apache.log4j.Logger;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.util.Calendar;
import java.util.UUID;
Expand All @@ -43,8 +39,6 @@
*/
public final class Tools {

private static final Logger LOG = Logger.getLogger(Tools.class);

private Tools() { }

/**
Expand Down Expand Up @@ -196,7 +190,7 @@ public static double getUTCTimestampWithMilliseconds(long timestamp) {
}

public static String getLocalHostname() {
InetAddress addr = null;
InetAddress addr;
try {
addr = InetAddress.getLocalHost();
} catch (UnknownHostException ex) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/graylog2/database/MongoConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public synchronized Mongo connect() {
throw new RuntimeException("Could not authenticate to database '" + database + "' with user '" + username + "'.");
}
}
} catch (MongoException.Network e) {
throw e;
} catch (UnknownHostException e) {
throw new RuntimeException("Cannot resolve host name for MongoDB", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class HealthCheckRequestHandler extends SimpleChannelUpstreamHandler {
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
StringBuilder buffer = new StringBuilder();
HttpRequest request = (HttpRequest) e.getMessage();

buffer.setLength(0);
buffer.append(buildTextResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public EmbeddedElasticSearchClient(GraylogServer graylogServer) {

final NodeBuilder builder = nodeBuilder().client(true);
String esSettings;
Map<String, String> settings = null;
Map<String, String> settings;
try {
esSettings = FileUtils.readFileToString(new File(graylogServer.getConfiguration().getElasticSearchConfigFile()));
settings = new YamlSettingsLoader().load(esSettings);
Expand Down Expand Up @@ -85,8 +85,7 @@ public boolean createIndex() {
return false;
}
final PutMappingRequest mappingRequest = Mapping.getPutMappingRequest(client, getMainIndexName());
final boolean mappingCreated = client.admin().indices().putMapping(mappingRequest).actionGet().acknowledged();
return acknowledged && mappingCreated;
return client.admin().indices().putMapping(mappingRequest).actionGet().acknowledged();
}

public boolean createRecentIndex() {
Expand All @@ -103,8 +102,7 @@ public boolean createRecentIndex() {
return false;
}
final PutMappingRequest mappingRequest = Mapping.getPutMappingRequest(client, RECENT_INDEX_NAME);
final boolean mappingCreated = client.admin().indices().putMapping(mappingRequest).actionGet().acknowledged();
return acknowledged && mappingCreated;
return client.admin().indices().putMapping(mappingRequest).actionGet().acknowledged();
}

public boolean bulkIndex(final List<LogMessage> messages) {
Expand All @@ -130,8 +128,8 @@ public boolean bulkIndex(final List<LogMessage> messages) {
}

public boolean deleteMessagesByTimeRange(int to) {
DeleteByQueryRequestBuilder b = client.prepareDeleteByQuery(new String[] {getMainIndexName()});
b.setTypes(new String[] {TYPE});
DeleteByQueryRequestBuilder b = client.prepareDeleteByQuery( getMainIndexName() );
b.setTypes( TYPE );
final QueryBuilder qb = rangeQuery("created_at").from(0).to(to);
b.setQuery(qb);
ActionFuture<DeleteByQueryResponse> future = client.deleteByQuery(b.request());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/graylog2/indexer/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class Mapping {

public static PutMappingRequest getPutMappingRequest(final Client client, final String index) {
final PutMappingRequestBuilder builder = client.admin().indices().preparePutMapping(new String[] {index});
final PutMappingRequestBuilder builder = client.admin().indices().preparePutMapping( index );
builder.setType(EmbeddedElasticSearchClient.TYPE);

final Map<String, Object> mapping = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package org.graylog2.initializers;

import org.graylog2.Configuration;
import org.graylog2.GraylogServer;
import org.graylog2.HostSystem;
import org.graylog2.ServerValue;
Expand All @@ -32,11 +31,8 @@
*/
public class ServerValueWriterInitializer extends SimpleFixedRateScheduleInitializer implements Initializer {

private Configuration configuration;

public ServerValueWriterInitializer(GraylogServer graylogServer, Configuration configuration) {
public ServerValueWriterInitializer(GraylogServer graylogServer) {
this.graylogServer = graylogServer;
this.configuration = configuration;
}

@Override
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/org/graylog2/inputs/gelf/GELFChunkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ public class GELFChunkManager extends Thread {

private Map<String, Map<Integer, GELFMessageChunk>> chunks = Maps.newConcurrentMap();
private GELFProcessor processor;
private GraylogServer server;

// The number of seconds a chunk is valid. Every message with chunks older than this will be dropped.
// The number of seconds a chunk is valid. Every message with chunks older than this will be dropped.
public static final int SECONDS_VALID = 5;

public GELFChunkManager(GraylogServer server) {
this.processor = new GELFProcessor(server);
this.server = server;
}

@Override
Expand Down Expand Up @@ -101,12 +99,7 @@ public boolean isComplete(String messageId) {
}

int claimedSequenceCount = chunks.get(messageId).get(0).getSequenceCount();
if (claimedSequenceCount == chunks.get(messageId).size()) {
// Message seems to be complete.
return true;
}

return false;
return claimedSequenceCount == chunks.get( messageId ).size();
}

public boolean isOutdated(String messageId) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/graylog2/inputs/gelf/GELFMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum Type {
Type(final byte first, final byte second) {
this.first = first;
this.second = second;
};
}

static Type determineType(final byte first, final byte second) {
if (first == ZLIB.first && second == ZLIB.second) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/graylog2/inputs/gelf/GELFMessageChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void read() {
this.arrival = (int) (System.currentTimeMillis()/1000);
}

private String extractId() {
private void extractId() {
if (this.id == null) {
String tmp = "";
for (int i = 0; i < HEADER_PART_HASH_LENGTH; i++) {
Expand All @@ -118,8 +118,6 @@ private String extractId() {
}
this.id = tmp;
}

return this.id;
}

// lol duplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class MessageRetentionThread implements Runnable {

private static final Logger LOG = Logger.getLogger(MessageRetentionThread.class);

private int retentionTimeDays;

private final GraylogServer server;

private final MessageRetention messageRetention;
Expand All @@ -57,11 +55,11 @@ public void run() {
* to be sure to always have the *current* setting from database - even when
* used with scheduler.
*/
this.retentionTimeDays = settings.getRetentionTimeInDays();
final int retentionTimeDays = settings.getRetentionTimeInDays();

LOG.info("Initialized message retention thread - cleaning all messages older than <" + this.retentionTimeDays + " days>.");
LOG.info("Initialized message retention thread - cleaning all messages older than <" + retentionTimeDays + " days>.");

if (messageRetention.performCleanup(this.retentionTimeDays)) {
if (messageRetention.performCleanup( retentionTimeDays )) {
messageRetention.updateLastPerformedTime();
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class StreamRuleMatcherFactory {

public static StreamRuleMatcher build(int ruleType) throws InvalidStreamRuleTypeException {
StreamRuleMatcher matcher = null;
StreamRuleMatcher matcher;

// IMPORTANT: Also add every new rule type to the unit test.
switch (ruleType) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/graylog2/MessageCounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testResetHostCounts() {
public void testResetStreamCounts() {
counter.countUpStream(new ObjectId(), 100);
counter.resetStreamCounts();
assertEquals(new HashMap<ObjectId, Integer>(), counter.getStreamCounts()); }
assertEquals(new HashMap<String, Integer>(), counter.getStreamCounts()); }

@Test
public void testResetTotal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package org.graylog2.inputs.syslog;

import org.graylog2.Tools;
import org.graylog2.logmessage.LogMessage;
import java.net.InetAddress;
import org.graylog2.Configuration;
Expand All @@ -33,7 +32,6 @@ public class SyslogProcessorTest {
// http://tools.ietf.org/rfc/rfc5424.txt
public static String ValidStructuredMessage = "<165>1 2012-12-25T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"] BOMAn application event log entry";
public static String ValidNonStructuredMessage = "<86>Dec 24 17:05:01 foo-bar CRON[10049]: pam_unix(cron:session): session closed for user root";
public static String MessageLookingLikeStructured = "<133>NOMA101FW01A: NetScreen device_id=NOMA101FW01A [Root]system-notification-00257(traffic): start_time=\"2011-12-23 17:33:43\" duration=0 reason=Creation";

@Test
public void testMessageReceivedWithNonStructuredMessage() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testBuild() throws Exception {
public void testBuildWithInvalidStreamRuleType() {
boolean exceptionThrown = false;
try {
StreamRuleMatcher messageMatcher = StreamRuleMatcherFactory.build(9001);
StreamRuleMatcherFactory.build(9001);
} catch (InvalidStreamRuleTypeException e) {
exceptionThrown = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void testTheTruthToWork() {
@Test
public void testSuccessfulMath() {
String filename = "main.rb";
int line = 17;
String regex = "^main\\.rb:1\\d";

BasicDBObject mongoRule = new BasicDBObject();
Expand All @@ -56,7 +55,6 @@ public void testSuccessfulMath() {
@Test
public void testSuccessfulMatchWithoutRegex() {
String filename = "lol.php";
int line = 9001;
String regex = "lol\\.php:9001";

BasicDBObject mongoRule = new BasicDBObject();
Expand Down