use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class StreamAlarmCallbackResource method update.
@PUT
@Path("/{alarmCallbackId}")
@Timed
@ApiOperation(value = "Update an alarm callback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_UPDATE)
public void update(@ApiParam(name = "streamid", value = "The stream id this alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "alarmCallbackId", required = true) @PathParam("alarmCallbackId") String alarmCallbackId, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest alarmCallbackRequest) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_EDIT, streamid);
final AlarmCallbackConfiguration callbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
if (callbackConfiguration == null) {
throw new NotFoundException("Unable to find alarm callback configuration " + alarmCallbackId);
}
final Map<String, Object> configuration = convertConfigurationValues(alarmCallbackRequest);
final AlarmCallbackConfiguration updatedConfig = ((AlarmCallbackConfigurationImpl) callbackConfiguration).toBuilder().setTitle(alarmCallbackRequest.title()).setConfiguration(configuration).build();
try {
alarmCallbackFactory.create(updatedConfig).checkConfiguration();
alarmCallbackConfigurationService.save(updatedConfig);
} catch (ValidationException | AlarmCallbackConfigurationException | ConfigurationException e) {
LOG.error("Invalid alarm callback configuration.", e);
throw new BadRequestException(e.getMessage(), e);
} catch (ClassNotFoundException e) {
LOG.error("Invalid alarm callback type.", e);
throw new BadRequestException("Invalid alarm callback type.", e);
}
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class AvailableAlarmCallbackSummaryResponse method extractRequestedConfiguration.
public List<RequestedConfigurationField> extractRequestedConfiguration(Map<String, Map<String, Object>> config) {
List<RequestedConfigurationField> result = Lists.newArrayList();
List<RequestedConfigurationField> booleanFields = Lists.newArrayList();
for (Map.Entry<String, Map<String, Object>> entry : config.entrySet()) {
try {
String fieldType = (String) entry.getValue().get("type");
switch(fieldType) {
case "text":
result.add(new TextField(entry));
continue;
case "number":
result.add(new NumberField(entry));
continue;
case "boolean":
booleanFields.add(new BooleanField(entry));
continue;
case "dropdown":
result.add(new DropdownField(entry));
continue;
default:
LOG.info("Unknown field type [{}].", fieldType);
}
} catch (Exception e) {
LOG.error("Skipping invalid configuration field [" + entry.getKey() + "]", e);
}
}
result.addAll(booleanFields);
return result;
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class ConfigurationRequest method filter.
/**
* Creates a new {@link org.graylog2.plugin.configuration.Configuration configuration object} containing only the
* fields specified in this request object.
* @param config original Configuration
* @return filtered Configuration, not null but might be empty
*/
@Nonnull
public Configuration filter(Configuration config) {
final Map<String, Object> values = Maps.newHashMap();
for (final ConfigurationField field : fields.values()) {
final String name = field.getName();
final String type = field.getFieldType();
switch(type) {
case BooleanField.FIELD_TYPE:
if (config.booleanIsSet(name)) {
values.put(name, config.getBoolean(name));
}
break;
case NumberField.FIELD_TYPE:
if (config.intIsSet(name)) {
values.put(name, config.getInt(name));
}
break;
case TextField.FIELD_TYPE:
case DropdownField.FIELD_TYPE:
if (config.stringIsSet(name)) {
values.put(name, config.getString(name));
}
break;
default:
throw new IllegalStateException("Unknown field type " + type + ". This is a bug.");
}
}
return new Configuration(values);
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class UdpTransportTest method receiveBufferSizeIsNotLimited.
@Test
public void receiveBufferSizeIsNotLimited() throws Exception {
final int recvBufferSize = Ints.saturatedCast(Size.megabytes(1L).toBytes());
ImmutableMap<String, Object> source = ImmutableMap.<String, Object>of(NettyTransport.CK_BIND_ADDRESS, BIND_ADDRESS, NettyTransport.CK_PORT, PORT, NettyTransport.CK_RECV_BUFFER_SIZE, recvBufferSize);
Configuration config = new Configuration(source);
UdpTransport udpTransport = new UdpTransport(config, throughputCounter, new LocalMetricRegistry());
assertThat(udpTransport.getBootstrap().getOption("receiveBufferSize")).isEqualTo(recvBufferSize);
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class UdpTransportTest method setUp.
@Before
public void setUp() throws Exception {
throughputCounter = new ThroughputCounter(new HashedWheelTimer());
localMetricRegistry = new LocalMetricRegistry();
udpTransport = new UdpTransport(CONFIGURATION, throughputCounter, localMetricRegistry);
}
Aggregations