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

fixing Feature: Customizable ClientID #13 #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions src/main/java/org/graylog2/inputs/mqtt/MQTTTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public class MQTTTransport implements Transport {
private static final String CK_PASSWORD = "password";
private static final String CK_USERNAME = "username";
private static final String CK_USE_AUTH = "useAuth";
private static final String CK_CLEINT_ID = "clientID";

private final Configuration configuration;
private final MetricRegistry metricRegistry;
private final String clientId;
private String clientId;
private ServerStatus serverStatus;
private MqttClient client;
private List<String> topics;
Expand All @@ -64,7 +65,6 @@ public MQTTTransport(@Assisted Configuration configuration,
this.configuration = configuration;
this.metricRegistry = metricRegistry;
this.serverStatus = serverStatus;
this.clientId = "graylog2_" + Hashing.murmur3_32().hashUnencodedChars(this.serverStatus.getNodeId().toString()).toString();
}

@Override
Expand All @@ -84,6 +84,8 @@ public void launch(MessageInput messageInput) throws MisfireException {

final ConnectReturnCode returnCode;
try {
this.clientId = configuration.getString(CK_CLEINT_ID)
+ Hashing.murmur3_32().hashUnencodedChars(this.serverStatus.getNodeId().toString()).toString();
if (configuration.getBoolean(CK_USE_AUTH)) {
final String username = configuration.getString(CK_USERNAME);
final String password = configuration.getString(CK_PASSWORD);
Expand Down Expand Up @@ -176,6 +178,11 @@ public ConfigurationRequest getRequestedConfiguration() {
"tcp://localhost:1883",
"This is the URL of the MQTT broker."));

cr.addField(new TextField(CK_CLEINT_ID,
"Client ID Prefix",
"graylog2_",
"This is the prefix of Clien ID field"));

cr.addField(new BooleanField(CK_USE_AUTH,
"Use Authentication",
false,
Expand Down