org.graylog2.telemetry.TelemetryConfiguration Maven / Gradle / Ivy
package org.graylog2.telemetry;
import com.github.joschi.jadconfig.Parameter;
import com.github.joschi.jadconfig.ValidationException;
import com.github.joschi.jadconfig.ValidatorMethod;
import com.github.joschi.jadconfig.util.Duration;
import com.github.joschi.jadconfig.validators.PositiveDurationValidator;
import com.github.joschi.jadconfig.validators.PositiveIntegerValidator;
import org.graylog2.plugin.PluginConfigBean;
import java.io.File;
import java.net.URI;
import static com.google.common.base.Strings.isNullOrEmpty;
public class TelemetryConfiguration implements PluginConfigBean {
private static final String PREFIX = "telemetry_";
@Parameter(value = PREFIX + "enabled")
private boolean enabled = false;
@Parameter(value = PREFIX + "token", required = true)
private String token = "";
@Parameter(value = PREFIX + "url", required = true)
private URI url = URI.create("https://telemetry-in.graylog.com/submit/");
@Parameter(value = PREFIX + "service_connect_timeout", validator = PositiveDurationValidator.class)
private Duration connectTimeout = Duration.seconds(1l);
@Parameter(value = PREFIX + "service_write_timeout", validator = PositiveDurationValidator.class)
private Duration writeTimeout = Duration.seconds(5l);
@Parameter(value = PREFIX + "service_read_timeout", validator = PositiveDurationValidator.class)
private Duration readTimeout = Duration.seconds(5l);
@Parameter(value = PREFIX + "cache_timeout", required = true, validator = PositiveDurationValidator.class)
private Duration cacheTimeout = Duration.minutes(1l);
@Parameter(value = PREFIX + "max_queue_size", required = true, validator = PositiveIntegerValidator.class)
private int maxQueueSize = 10;
@Parameter(value = PREFIX + "report_interval", required = true, validator = PositiveDurationValidator.class)
private Duration reportInterval = Duration.minutes(1l);
@Parameter(value = PREFIX + "gzip_enabled")
private boolean gzipEnabled = true;
@Parameter(value = PREFIX + "offline_mode")
private boolean offlineMode = false;
@Parameter(value = PREFIX + "dir")
private File directory = new File("data/telemetry");
public boolean isEnabled() {
return enabled;
}
public String getToken() {
return token;
}
public URI getUrl() {
return url;
}
public Duration getConnectTimeout() {
return connectTimeout;
}
public Duration getWriteTimeout() {
return writeTimeout;
}
public Duration getReadTimeout() {
return readTimeout;
}
public Duration getCacheTimeout() {
return cacheTimeout;
}
public int getMaxQueueSize() {
return maxQueueSize;
}
public Duration getReportInterval() {
return reportInterval;
}
public boolean isGzipEnabled() {
return gzipEnabled;
}
public boolean isOfflineMode() {
return offlineMode;
}
public File getDirectory() {
return directory;
}
@ValidatorMethod
public void validate() throws ValidationException {
if(isEnabled() && isOfflineMode() && getDirectory().exists() && !getDirectory().isDirectory()) {
throw new ValidationException("Directory " + getDirectory() + " must be a directory.");
}
if(isEnabled() && isOfflineMode() && getDirectory().exists() && !getDirectory().canWrite()) {
throw new ValidationException("Directory " + getDirectory() + " must be writable.");
}
if(isEnabled() && !isOfflineMode() && isNullOrEmpty(getToken())) {
throw new ValidationException("Authentication token for telemetry is missing.");
}
}
}