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;
}
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);
}
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);
}
}
}
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();
}
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;
}
Aggregations