Skip to content

Commit

Permalink
Upgrade to Graylog 2.4.0 and add more MQTT inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Schalanda committed Jul 12, 2018
1 parent 437d758 commit e5bfa8b
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 154 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MQTT Plugin for Graylog

This is an input plugin that allows you to subscribe to an [MQTT](http://mqtt.org) broker and index all published messages.

**Required Graylog version:** 2.0.0 and later
**Required Graylog version:** 2.4.0 and later

## Installation

Expand Down
143 changes: 49 additions & 94 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<prerequisites>
<maven>3.0</maven>
</prerequisites>

<groupId>org.graylog.plugins</groupId>
<parent>
<groupId>org.graylog.plugins</groupId>
<artifactId>graylog-plugin-parent</artifactId>
<version>2.4.0</version>
</parent>

<artifactId>graylog-plugin-mqtt</artifactId>
<version>1.2.0-SNAPSHOT</version>

Expand All @@ -19,150 +21,103 @@
</organization>

<scm>
<connection>scm:git:[email protected]:Graylog2/graylog-plugin-mqtt.git</connection>
<developerConnection>scm:git:[email protected]:Graylog2/graylog-plugin-mqtt.git</developerConnection>
<url>https://github.com/Graylog2/graylog-plugin-mqtt</url>
<connection>scm:git:[email protected]:graylog-labs/graylog-plugin-mqtt.git</connection>
<developerConnection>scm:git:[email protected]:graylog-labs/graylog-plugin-mqtt.git</developerConnection>
<url>https://github.com/graylog-labs/graylog-plugin-mqtt</url>
<tag>HEAD</tag>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.source.skip>true</maven.source.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>
<maven.site.skip>true</maven.site.skip>
<graylog2.plugin-dir>/usr/share/graylog-server/plugin</graylog2.plugin-dir>
<graylog2.version>2.0.0</graylog2.version>

<graylog.version>2.4.0</graylog.version>
</properties>

<dependencies>
<dependency>
<groupId>net.sf.xenqtt</groupId>
<groupId>net.xenqtt</groupId>
<artifactId>xenqtt</artifactId>
<version>0.9.7</version>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.graylog2</groupId>
<artifactId>graylog2-server</artifactId>
<version>${graylog2.version}</version>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${auto-service.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc2</version>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${auto-value.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.0.52-beta</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<annotationProcessors>
<annotationProcessor>com.google.auto.service.processor.AutoServiceProcessor
</annotationProcessor>
<annotationProcessor>com.google.auto.service.processor.AutoServiceProcessor</annotationProcessor>
<annotationProcessor>com.google.auto.value.processor.AutoValueProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Graylog-Plugin-Properties-Path>${project.groupId}.${project.artifactId}</Graylog-Plugin-Properties-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>false</minimizeJar>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<mavenExecutorId>forked-path</mavenExecutorId>
<tagNameFormat>@{project.version}</tagNameFormat>
<preparationGoals>clean test</preparationGoals>
<goals>package</goals>
</configuration>
</plugin>

<plugin>
<groupId>org.vafer</groupId>
<artifactId>jdeb</artifactId>
<version>1.5</version>
<configuration>
<deb>${project.build.directory}/${project.artifactId}-${project.version}.deb</deb>
<dataSet>
<data>
<src>${project.build.directory}/</src>
<includes>${project.build.finalName}.jar</includes>
<type>directory</type>
<mapper>
<type>perm</type>
<prefix>${graylog2.plugin-dir}</prefix>
<filemode>644</filemode>
<user>root</user>
<group>root</group>
</mapper>
</data>
</dataSet>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1.5</version>
<configuration>
<group>Application/Internet</group>
<prefix>/usr</prefix>
<defineStatements>
<defineStatement>_unpackaged_files_terminate_build 0</defineStatement>
<defineStatement>_binaries_in_noarch_packages_terminate_build 0</defineStatement>
</defineStatements>
<defaultFilemode>644</defaultFilemode>
<defaultDirmode>755</defaultDirmode>
<defaultUsername>root</defaultUsername>
<defaultGroupname>root</defaultGroupname>
<mappings>
<mapping>
<directory>${graylog2.plugin-dir}</directory>
<sources>
<source>
<location>${project.build.directory}/</location>
<includes>
<include>${project.build.finalName}.jar</include>
</includes>
</source>
</sources>
</mapping>
</mappings>
</configuration>
</plugin>
</plugins>
</build>
</project>
11 changes: 5 additions & 6 deletions src/main/java/org/graylog2/inputs/mqtt/ClientListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import net.sf.xenqtt.client.MqttClient;
import net.sf.xenqtt.client.MqttClientListener;
import net.sf.xenqtt.client.PublishMessage;
import net.sf.xenqtt.client.Subscription;
import net.sf.xenqtt.message.ConnectReturnCode;
import net.xenqtt.client.MqttClient;
import net.xenqtt.client.MqttClientListener;
import net.xenqtt.client.PublishMessage;
import net.xenqtt.client.Subscription;
import net.xenqtt.message.ConnectReturnCode;
import org.graylog2.plugin.inputs.MessageInput;
import org.graylog2.plugin.journal.RawMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

import static com.codahale.metrics.MetricRegistry.name;
Expand Down
26 changes: 1 addition & 25 deletions src/main/java/org/graylog2/inputs/mqtt/MQTTGELFInput.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
package org.graylog2.inputs.mqtt;

import com.codahale.metrics.MetricRegistry;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.common.hash.Hashing;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import net.sf.xenqtt.client.AsyncMqttClient;
import net.sf.xenqtt.client.MqttClient;
import net.sf.xenqtt.client.MqttClientConfig;
import net.sf.xenqtt.client.Subscription;
import net.sf.xenqtt.message.ConnectReturnCode;
import net.sf.xenqtt.message.QoS;
import org.graylog2.inputs.codecs.GelfCodec;
import org.graylog2.plugin.LocalMetricRegistry;
import org.graylog2.plugin.ServerStatus;
import org.graylog2.plugin.buffers.Buffer;
import org.graylog2.plugin.configuration.Configuration;
import org.graylog2.plugin.configuration.ConfigurationException;
import org.graylog2.plugin.configuration.ConfigurationRequest;
import org.graylog2.plugin.configuration.fields.BooleanField;
import org.graylog2.plugin.configuration.fields.ConfigurationField;
import org.graylog2.plugin.configuration.fields.NumberField;
import org.graylog2.plugin.configuration.fields.TextField;
import org.graylog2.plugin.inputs.MessageInput;
import org.graylog2.plugin.inputs.MisfireException;
import org.graylog2.plugin.system.NodeId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.List;
import java.util.Map;

public class MQTTGELFInput extends MessageInput {
private static final String NAME = "MQTT TCP (GELF)";
Expand Down Expand Up @@ -63,7 +39,7 @@ public interface Factory extends MessageInput.Factory<MQTTGELFInput> {
public static class Descriptor extends MessageInput.Descriptor {
@Inject
public Descriptor() {
super(NAME, false, "");
super(NAME, false, "https://github.com/graylog-labs/graylog-plugin-mqtt");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/graylog2/inputs/mqtt/MQTTInputMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.Set;

public class MQTTInputMetadata implements PluginMetaData {
private static final String PLUGIN_PROPERTIES = "org.graylog.plugins.graylog-plugin-mqtt/graylog-plugin.properties";

@Override
public String getUniqueId() {
return MQTTGELFInput.class.getCanonicalName();
Expand All @@ -31,7 +33,7 @@ public URI getURL() {

@Override
public Version getVersion() {
return new Version(2, 0, 0);
return Version.fromPluginProperties(getClass(), PLUGIN_PROPERTIES, "version", Version.from(1, 0, 0));
}

@Override
Expand All @@ -41,7 +43,7 @@ public String getDescription() {

@Override
public Version getRequiredVersion() {
return new Version(2, 0, 0);
return Version.fromPluginProperties(getClass(), PLUGIN_PROPERTIES, "graylog.version", Version.from(2, 4, 0));
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/graylog2/inputs/mqtt/MQTTInputModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
public class MQTTInputModule extends PluginModule {
@Override
protected void configure() {
installTransport(transportMapBinder(), "mqtt-transport", MQTTTransport.class);
installInput(inputsMapBinder(), MQTTGELFInput.class, MQTTGELFInput.Factory.class);
addTransport("mqtt-transport", MQTTTransport.class, MQTTTransport.Config.class, MQTTTransport.Factory.class);

addMessageInput(MQTTGELFInput.class, MQTTGELFInput.Factory.class);
addMessageInput(MQTTRawInput.class, MQTTRawInput.Factory.class);
addMessageInput(MQTTSyslogInput.class, MQTTSyslogInput.Factory.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public PluginMetaData metadata() {
return new MQTTInputMetadata();
}

@Override
public Collection<PluginModule> modules() {
return ImmutableSet.<PluginModule>of(new MQTTInputModule());
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/org/graylog2/inputs/mqtt/MQTTRawInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.graylog2.inputs.mqtt;

import com.codahale.metrics.MetricRegistry;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import org.graylog2.inputs.codecs.RawCodec;
import org.graylog2.plugin.LocalMetricRegistry;
import org.graylog2.plugin.ServerStatus;
import org.graylog2.plugin.configuration.Configuration;
import org.graylog2.plugin.inputs.MessageInput;

import javax.inject.Inject;

public class MQTTRawInput extends MessageInput {
private static final String NAME = "MQTT TCP (Raw/Plaintext)";

@AssistedInject
public MQTTRawInput(final MetricRegistry metricRegistry,
@Assisted Configuration configuration,
MQTTTransport.Factory mqttTransportFactory,
RawCodec.Factory rawCodecFactory,
LocalMetricRegistry localRegistry,
Config config,
Descriptor descriptor, ServerStatus serverStatus) {
super(metricRegistry, configuration, mqttTransportFactory.create(configuration), localRegistry, rawCodecFactory.create(configuration), config, descriptor, serverStatus);
}

public interface Factory extends MessageInput.Factory<MQTTRawInput> {
@Override
MQTTRawInput create(Configuration configuration);

@Override
Config getConfig();

@Override
Descriptor getDescriptor();
}

public static class Descriptor extends MessageInput.Descriptor {
@Inject
public Descriptor() {
super(NAME, false, "https://github.com/graylog-labs/graylog-plugin-mqtt");
}
}

public static class Config extends MessageInput.Config {
@Inject
public Config(MQTTTransport.Factory transport, RawCodec.Factory codec) {
super(transport.getConfig(), codec.getConfig());
}
}
}
Loading

0 comments on commit e5bfa8b

Please sign in to comment.