Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static final class Descriptor extends ToolDescriptor<LogstashInstallation
private String username;
private String password;
private String key;
private String pipeline;

public Descriptor() {
super();
Expand Down Expand Up @@ -210,5 +211,14 @@ public void setKey(String key)
this.key = key;
}

public String getPipeline()
{
return pipeline;
}

public void setPipeline(String pipeline)
{
this.pipeline = pipeline;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import static com.google.common.collect.Ranges.closedOpen;

import jenkins.model.Jenkins;
import jenkins.plugins.logstash.LogstashInstallation;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
Expand All @@ -45,6 +47,8 @@
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.common.collect.Range;

Expand All @@ -55,6 +59,8 @@
* @since 1.0.4
*/
public class ElasticSearchDao extends AbstractLogstashIndexerDao {
private String pipeline = "";
private final static Logger LOG = Logger.getLogger(ElasticSearchDao.class.getName());
private final HttpClientBuilder clientBuilder;
private final URI uri;
private final String auth;
Expand All @@ -74,11 +80,24 @@ public ElasticSearchDao(String host, int port, String key, String username, Stri
}

try {
uri = new URIBuilder(host)
LogstashInstallation.Descriptor logstashPluginConfig = (LogstashInstallation.Descriptor) Jenkins.getInstance().getDescriptor(LogstashInstallation.class);
pipeline = logstashPluginConfig.getPipeline();
} catch (NullPointerException e){
LOG.log(Level.WARNING, "Unable to read pipeline in the jenkins logstash plugin configuration");
}

try {
URIBuilder baseUri = new URIBuilder(host)
.setPort(port)
// Normalizer will remove extra starting slashes, but missing slash will cause annoying failures
.setPath("/" + key)
.build();
.setPath("/" + key);

if (StringUtils.isBlank(pipeline)) {
uri = baseUri.build();
} else {
uri = baseUri
.setParameter("pipeline", pipeline)
.build();
}
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Could not create uri", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
checkUrl="'${resURL}/descriptorByName/LogstashInstallation/checkString?value='+escape(this.value)" />
</f:entry>
<f:advanced>
<f:entry title="${%Elasticsearch pipeline}" field="pipeline">
<f:textbox value="${descriptor.pipeline}" />
</f:entry>
<f:entry title="${%Syslog format}" field="syslogFormat">
<f:enum value="${descriptor.syslogFormat}">${it.name()}</f:enum>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>
<p>The elasticsearch pipeline to send logs through (only effective for ELASTICSEARCH Indexer type).<br/>
Leave this field blank if you are not routing through a pipeline.</p>
</div>