use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class MessageResource method decodeMessage.
private Message decodeMessage(Codec codec, ResolvableInetSocketAddress remoteAddress, RawMessage rawMessage) {
Message message;
try {
message = codec.decode(rawMessage);
} catch (Exception e) {
throw new BadRequestException("Could not decode message");
}
if (message == null) {
throw new BadRequestException("Could not decode message");
}
// Ensure the decoded Message has a source, otherwise creating a ResultMessage will fail
if (isNullOrEmpty(message.getSource())) {
final String address = InetAddresses.toAddrString(remoteAddress.getAddress());
message.setSource(address);
}
// Override source
final Configuration configuration = codec.getConfiguration();
if (configuration.stringIsSet(Codec.Config.CK_OVERRIDE_SOURCE)) {
message.setSource(configuration.getString(Codec.Config.CK_OVERRIDE_SOURCE));
}
return message;
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class StreamAlarmCallbackResource method create.
@POST
@Timed
@ApiOperation(value = "Create an alarm callback", response = CreateAlarmCallbackResponse.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_CREATE)
public Response create(@ApiParam(name = "streamid", value = "The stream id this new alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest originalCr) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_EDIT, streamid);
// make sure the values are correctly converted to the declared configuration types
final CreateAlarmCallbackRequest cr = CreateAlarmCallbackRequest.create(originalCr.type(), originalCr.title(), convertConfigurationValues(originalCr));
final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.create(streamid, cr, getCurrentUser().getName());
final String id;
try {
alarmCallbackFactory.create(alarmCallbackConfiguration).checkConfiguration();
id = alarmCallbackConfigurationService.save(alarmCallbackConfiguration);
} 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);
}
final URI alarmCallbackUri = getUriBuilderToSelf().path(StreamAlarmCallbackResource.class).path("{alarmCallbackId}").build(streamid, id);
return Response.created(alarmCallbackUri).entity(CreateAlarmCallbackResponse.create(id)).build();
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class FormattedEmailAlertSenderTest method buildBodyContainsInfoMessageIfWebInterfaceURLIsNotSet.
@Test
public void buildBodyContainsInfoMessageIfWebInterfaceURLIsNotSet() throws Exception {
final EmailConfiguration configuration = new EmailConfiguration() {
@Override
public URI getWebInterfaceUri() {
return null;
}
};
this.emailAlertSender = new FormattedEmailAlertSender(configuration, mockNotificationService, mockNodeId, templateEngine);
Stream stream = mock(Stream.class);
when(stream.getId()).thenReturn("123456");
when(stream.getTitle()).thenReturn("Stream Title");
AlertCondition alertCondition = mock(AlertCondition.class);
AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
when(checkResult.getTriggeredAt()).thenReturn(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
when(checkResult.getTriggeredCondition()).thenReturn(alertCondition);
String body = emailAlertSender.buildBody(stream, checkResult, Collections.<Message>emptyList());
assertThat(body).contains("Stream URL: Please configure 'transport_email_web_interface_url' in your Graylog configuration file.");
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class FormattedEmailAlertSenderTest method buildBodyContainsURLIfWebInterfaceURLIsSet.
@Test
public void buildBodyContainsURLIfWebInterfaceURLIsSet() throws Exception {
final EmailConfiguration configuration = new EmailConfiguration() {
@Override
public URI getWebInterfaceUri() {
return URI.create("https://localhost");
}
};
this.emailAlertSender = new FormattedEmailAlertSender(configuration, mockNotificationService, mockNodeId, templateEngine);
Stream stream = mock(Stream.class);
when(stream.getId()).thenReturn("123456");
when(stream.getTitle()).thenReturn("Stream Title");
AlertCondition alertCondition = mock(AlertCondition.class);
AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
when(checkResult.getTriggeredAt()).thenReturn(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
when(checkResult.getTriggeredCondition()).thenReturn(alertCondition);
String body = emailAlertSender.buildBody(stream, checkResult, Collections.<Message>emptyList());
assertThat(body).contains("Stream URL: https://localhost/streams/123456/");
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class FormattedEmailAlertSenderTest method buildSubjectUsesCustomSubject.
@Test
public void buildSubjectUsesCustomSubject() throws Exception {
Configuration pluginConfig = new Configuration(Collections.<String, Object>singletonMap("subject", "Test"));
emailAlertSender.initialize(pluginConfig);
Stream stream = mock(Stream.class);
AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
String subject = emailAlertSender.buildSubject(stream, checkResult, Collections.<Message>emptyList());
assertThat(subject).isEqualTo("Test");
}
Aggregations