Search in sources :

Example 11 with Configuration

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);
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 12 with Configuration

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;
}
Also used : DropdownField(org.graylog2.rest.models.configuration.responses.DropdownField) BooleanField(org.graylog2.rest.models.configuration.responses.BooleanField) RequestedConfigurationField(org.graylog2.rest.models.configuration.responses.RequestedConfigurationField) TextField(org.graylog2.rest.models.configuration.responses.TextField) Map(java.util.Map) NumberField(org.graylog2.rest.models.configuration.responses.NumberField)

Example 13 with Configuration

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);
}
Also used : ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) Nonnull(javax.annotation.Nonnull)

Example 14 with Configuration

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);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Test(org.junit.Test)

Example 15 with Configuration

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);
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)36 Configuration (org.graylog2.plugin.configuration.Configuration)29 ApiOperation (io.swagger.annotations.ApiOperation)24 Timed (com.codahale.metrics.annotation.Timed)23 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)17 Consumes (javax.ws.rs.Consumes)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Stream (org.graylog2.plugin.streams.Stream)13 ApiResponses (io.swagger.annotations.ApiResponses)12 PUT (javax.ws.rs.PUT)11 ValidationException (org.graylog2.plugin.database.ValidationException)11 DateTime (org.joda.time.DateTime)11 Produces (javax.ws.rs.Produces)10 Configuration (org.graylog2.Configuration)10 POST (javax.ws.rs.POST)9 EmailConfiguration (org.graylog2.configuration.EmailConfiguration)9 URI (java.net.URI)8