Search in sources :

Example 81 with Configuration

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

the class DashboardServiceImpl method create.

private Dashboard create(ObjectId id, Map<String, Object> fields) {
    final Dashboard dashboard = new DashboardImpl(id, fields);
    // Add all widgets of this dashboard.
    if (fields.containsKey(DashboardImpl.EMBEDDED_WIDGETS)) {
        if (fields.get(DashboardImpl.EMBEDDED_WIDGETS) instanceof List) {
            for (BasicDBObject widgetFields : (List<BasicDBObject>) fields.get(DashboardImpl.EMBEDDED_WIDGETS)) {
                try {
                    final DashboardWidget widget = dashboardWidgetCreator.fromPersisted(widgetFields);
                    dashboard.addPersistedWidget(widget);
                } catch (DashboardWidget.NoSuchWidgetTypeException e) {
                    LOG.error("No such widget type: [" + widgetFields.get("type") + "] - Dashboard: [" + dashboard.getId() + "]", e);
                } catch (InvalidRangeParametersException e) {
                    LOG.error("Invalid range parameters of widget in dashboard: [" + dashboard.getId() + "]", e);
                } catch (InvalidWidgetConfigurationException e) {
                    LOG.error("Invalid configuration of widget in dashboard: [" + dashboard.getId() + "]", e);
                }
            }
        }
    }
    return dashboard;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) DashboardWidget(org.graylog2.dashboards.widgets.DashboardWidget) List(java.util.List) InvalidWidgetConfigurationException(org.graylog2.dashboards.widgets.InvalidWidgetConfigurationException)

Example 82 with Configuration

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

the class AlertConditionFactory method createAlertCondition.

public AlertCondition createAlertCondition(String type, Stream stream, String id, DateTime createdAt, String creatorId, Map<String, Object> parameters, String title) throws ConfigurationException {
    final AlertCondition.Factory factory = this.alertConditionMap.get(type);
    checkArgument(factory != null, "Unknown alert condition type: " + type);
    /*
         * Ensure the given parameters fulfill the requested configuration preconditions.
         * Here we strictly use the Configuration object to verify the configuration and don't pass it down to
         * the factory. The reason for this is that Configuration only support int values, but at least an
         * alert condition expects a double.
         */
    try {
        final ConfigurationRequest requestedConfiguration = factory.config().getRequestedConfiguration();
        final Configuration configuration = new Configuration(parameters);
        requestedConfiguration.check(configuration);
    } catch (ConfigurationException e) {
        final String conditionTitle = isNullOrEmpty(title) ? "" : "'" + title + "' ";
        LOG.error("Could not load alert condition " + conditionTitle + "<" + id + ">, invalid configuration detected.");
        throw e;
    }
    return factory.create(stream, id, createdAt, creatorId, parameters, title);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) AlertCondition(org.graylog2.plugin.alarms.AlertCondition)

Example 83 with Configuration

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

the class AlertNotificationsSender method send.

public void send(AlertCondition.CheckResult result, Stream stream, Alert alert, AlertCondition alertCondition) {
    final List<AlarmCallbackConfiguration> callConfigurations = alarmCallbackConfigurationService.getForStream(stream);
    // Checking if alarm callbacks have been defined
    for (AlarmCallbackConfiguration configuration : callConfigurations) {
        AlarmCallbackHistory alarmCallbackHistory;
        AlarmCallback alarmCallback = null;
        try {
            alarmCallback = alarmCallbackFactory.create(configuration);
            alarmCallback.call(stream, result);
            alarmCallbackHistory = alarmCallbackHistoryService.success(configuration, alert, alertCondition);
        } catch (Exception e) {
            if (alarmCallback != null) {
                LOG.warn("Alarm callback <" + alarmCallback.getName() + "> failed. Skipping.", e);
            } else {
                LOG.warn("Alarm callback with id " + configuration.getId() + " failed. Skipping.", e);
            }
            alarmCallbackHistory = alarmCallbackHistoryService.error(configuration, alert, alertCondition, e.getMessage());
        }
        try {
            alarmCallbackHistoryService.save(alarmCallbackHistory);
        } catch (Exception e) {
            LOG.warn("Unable to save history of alarm callback run: ", e);
        }
    }
}
Also used : AlarmCallbackHistory(org.graylog2.alarmcallbacks.AlarmCallbackHistory) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)

Example 84 with Configuration

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

the class FormattedEmailAlertSender method sendEmail.

private void sendEmail(String emailAddress, Stream stream, AlertCondition.CheckResult checkResult, List<Message> backlog) throws TransportConfigurationException, EmailException {
    LOG.debug("Sending mail to " + emailAddress);
    if (!configuration.isEnabled()) {
        throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
    }
    final Email email = new SimpleEmail();
    email.setCharset(EmailConstants.UTF_8);
    if (isNullOrEmpty(configuration.getHostname())) {
        throw new TransportConfigurationException("No hostname configured for email transport while trying to send alert email!");
    } else {
        email.setHostName(configuration.getHostname());
    }
    email.setSmtpPort(configuration.getPort());
    if (configuration.isUseSsl()) {
        email.setSslSmtpPort(Integer.toString(configuration.getPort()));
    }
    if (configuration.isUseAuth()) {
        email.setAuthenticator(new DefaultAuthenticator(Strings.nullToEmpty(configuration.getUsername()), Strings.nullToEmpty(configuration.getPassword())));
    }
    email.setSSLOnConnect(configuration.isUseSsl());
    email.setStartTLSEnabled(configuration.isUseTls());
    if (pluginConfig != null && !isNullOrEmpty(pluginConfig.getString("sender"))) {
        email.setFrom(pluginConfig.getString("sender"));
    } else {
        email.setFrom(configuration.getFromEmail());
    }
    email.setSubject(buildSubject(stream, checkResult, backlog));
    email.setMsg(buildBody(stream, checkResult, backlog));
    email.addTo(emailAddress);
    email.send();
}
Also used : Email(org.apache.commons.mail.Email) SimpleEmail(org.apache.commons.mail.SimpleEmail) TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) DefaultAuthenticator(org.apache.commons.mail.DefaultAuthenticator) SimpleEmail(org.apache.commons.mail.SimpleEmail)

Example 85 with Configuration

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

the class AlarmCallbackFactory method create.

public AlarmCallback create(AlarmCallbackConfiguration configuration) throws ClassNotFoundException, AlarmCallbackConfigurationException {
    AlarmCallback alarmCallback = create(configuration.getType());
    alarmCallback.initialize(new Configuration(configuration.getConfiguration()));
    return alarmCallback;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback)

Aggregations

Test (org.junit.Test)34 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