Search in sources :

Example 61 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class EmailSender method sendEmail.

private void sendEmail(EmailEventNotificationConfig config, String emailAddress, Map<String, Object> model) throws TransportConfigurationException, EmailException {
    LOG.debug("Sending mail to " + emailAddress);
    if (!emailFactory.isEmailTransportEnabled()) {
        throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
    }
    final Email email = createEmailWithBody(config, model);
    if (!isNullOrEmpty(config.sender())) {
        email.setFrom(config.sender());
    }
    email.setSubject(buildSubject(config, model));
    email.addTo(emailAddress);
    email.send();
}
Also used : Email(org.apache.commons.mail.Email) HtmlEmail(org.apache.commons.mail.HtmlEmail) SimpleEmail(org.apache.commons.mail.SimpleEmail) TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException)

Example 62 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class LegacyAlarmCallbackSender method send.

public void send(LegacyAlarmCallbackEventNotificationConfig config, EventDefinition eventDefinition, EventDto event, List<MessageSummary> backlog) throws Exception {
    final String callbackType = config.callbackType();
    final Stream stream = findStream(eventDefinition.config());
    final AbstractAlertCondition alertCondition = new LegacyAlertCondition(stream, eventDefinition, event);
    final AbstractAlertCondition.CheckResult checkResult = new AbstractAlertCondition.CheckResult(true, alertCondition, event.message(), event.processingTimestamp(), backlog);
    try {
        final AlarmCallback callback = alarmCallbackFactory.create(callbackType, config.configuration());
        callback.checkConfiguration();
        callback.call(stream, checkResult);
    } catch (ClassNotFoundException e) {
        LOG.error("Couldn't find implementation class for type <{}>", callbackType);
        throw e;
    } catch (AlarmCallbackConfigurationException e) {
        LOG.error("Invalid legacy alarm callback configuration", e);
        throw e;
    } catch (ConfigurationException e) {
        LOG.error("Invalid configuration for legacy alarm callback <{}>", callbackType, e);
        throw e;
    } catch (AlarmCallbackException e) {
        LOG.error("Couldn't execute legacy alarm callback <{}>", callbackType, e);
        throw e;
    }
}
Also used : AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Stream(org.graylog2.plugin.streams.Stream) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException)

Example 63 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class SidecarCollectorConfigurationFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Configuration configuration = configurationService.find(modelId.id());
    if (isNull(configuration)) {
        LOG.debug("Couldn't find collector configuration {}", entityDescriptor);
        return Optional.empty();
    }
    return Optional.of(exportNativeEntity(configuration, entityDescriptorIds));
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 64 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class SidecarCollectorConfigurationFacade method exportNativeEntity.

@VisibleForTesting
Entity exportNativeEntity(Configuration configuration, EntityDescriptorIds entityDescriptorIds) {
    final SidecarCollectorConfigurationEntity configurationEntity = SidecarCollectorConfigurationEntity.create(ValueReference.of(entityDescriptorIds.getOrThrow(configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1)), ValueReference.of(configuration.name()), ValueReference.of(configuration.color()), ValueReference.of(configuration.template()));
    final JsonNode data = objectMapper.convertValue(configurationEntity, JsonNode.class);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(configuration.id(), ModelTypes.SIDECAR_COLLECTOR_CONFIGURATION_V1))).type(TYPE_V1).data(data).build();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 65 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class SidecarCollectorConfigurationFacade method resolveNativeEntity.

@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
    final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entityDescriptor);
    final ModelId modelId = entityDescriptor.id();
    final Configuration configuration = configurationService.find(modelId.id());
    if (isNull(configuration)) {
        LOG.debug("Could not find configuration {}", entityDescriptor);
    } else {
        final EntityDescriptor collectorEntityDescriptor = EntityDescriptor.create(configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1);
        mutableGraph.putEdge(entityDescriptor, collectorEntityDescriptor);
    }
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) ModelId(org.graylog2.contentpacks.model.ModelId)

Aggregations

Test (org.junit.Test)67 Configuration (org.graylog2.plugin.configuration.Configuration)46 Configuration (org.apache.commons.configuration2.Configuration)35 ApiOperation (io.swagger.annotations.ApiOperation)31 Timed (com.codahale.metrics.annotation.Timed)23 AuditEvent (org.graylog2.audit.jersey.AuditEvent)23 Path (javax.ws.rs.Path)22 BadRequestException (javax.ws.rs.BadRequestException)21 MessageInput (org.graylog2.plugin.inputs.MessageInput)18 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)17 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)15 Stream (org.graylog2.plugin.streams.Stream)15 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)14 File (java.io.File)14 Consumes (javax.ws.rs.Consumes)14 DateTime (org.joda.time.DateTime)14 POST (javax.ws.rs.POST)13 Produces (javax.ws.rs.Produces)13 Configuration (org.graylog2.Configuration)13 ApiResponses (io.swagger.annotations.ApiResponses)12