use of org.graylog.events.notifications.NotificationDto in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final EntityV1 entityV1 = createTestEntity();
final NotificationDto notificationDto = NotificationDto.builder().config(HTTPEventNotificationConfig.builder().url("https://hulud.net").build()).title("Notify me Senpai").description("A notification for senpai").id("dead-beef").build();
final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
final ImmutableMap<EntityDescriptor, Object> nativeEntities = ImmutableMap.of(entityDescriptor, notificationDto);
final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
final JobTriggerDto jobTriggerDto = mock(JobTriggerDto.class);
when(jobDefinitionDto.id()).thenReturn("job-123123");
when(jobSchedulerClock.nowUTC()).thenReturn(DateTime.now(DateTimeZone.UTC));
when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
when(jobTriggerService.create(any(JobTriggerDto.class))).thenReturn(jobTriggerDto);
final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
when(userService.load("kmerz")).thenReturn(kmerzUser);
final NativeEntity<EventDefinitionDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), nativeEntities, "kmerz");
assertThat(nativeEntity).isNotNull();
final EventDefinitionDto eventDefinitionDto = nativeEntity.entity();
assertThat(eventDefinitionDto.title()).isEqualTo("title");
assertThat(eventDefinitionDto.description()).isEqualTo("description");
assertThat(eventDefinitionDto.config().type()).isEqualTo("aggregation-v1");
// verify that ownership was registered for this entity
verify(entityOwnershipService, times(1)).registerNewEventDefinition(nativeEntity.entity().id(), kmerzUser);
}
use of org.graylog.events.notifications.NotificationDto in project graylog2-server by Graylog2.
the class NotificationFacadeTest method createExcerpt.
@Test
@MongoDBFixtures("NotificationFacadeTest.json")
public void createExcerpt() {
final Optional<NotificationDto> notificationDto = notificationService.get("5d4d33753d27460ad18e0c4d");
assertThat(notificationDto).isPresent();
final EntityExcerpt excerpt = facade.createExcerpt(notificationDto.get());
assertThat(excerpt.title()).isEqualTo("title");
assertThat(excerpt.id()).isEqualTo(ModelId.of("5d4d33753d27460ad18e0c4d"));
assertThat(excerpt.type()).isEqualTo(ModelTypes.NOTIFICATION_V1);
}
use of org.graylog.events.notifications.NotificationDto in project graylog2-server by Graylog2.
the class NotificationFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final EntityV1 entityV1 = createTestEntity();
final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
when(userService.load("kmerz")).thenReturn(kmerzUser);
final NativeEntity<NotificationDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), ImmutableMap.of(), "kmerz");
assertThat(nativeEntity).isNotNull();
final NotificationDto notificationDto = nativeEntity.entity();
assertThat(notificationDto.title()).isEqualTo("title");
assertThat(notificationDto.description()).isEqualTo("descriptions");
assertThat(notificationDto.config().type()).isEqualTo("http-notification-v1");
}
use of org.graylog.events.notifications.NotificationDto in project graylog2-server by Graylog2.
the class LegacyAlertConditionMigrator method migrateAlarmCallback.
/**
* Example alarm callback data structure:
* <pre>{@code
* {
* "_id": "54e3deadbeefdeadbeef0001",
* "stream_id" : "54e3deadbeefdeadbeef0001",
* "type" : "org.graylog2.alarmcallbacks.HTTPAlarmCallback",
* "title" : "HTTP Callback Test",
* "configuration" : {
* "url" : "http://localhost:11000/"
* },
* "created_at": "2019-01-01T00:00:00.000Z",
* "creator_user_id" : "admin"
* }
* }</pre>
*/
private NotificationDto migrateAlarmCallback(Document alarmCallback) {
final String title = alarmCallback.getString("title");
final String type = alarmCallback.getString("type");
final Document configDoc = (Document) alarmCallback.get("configuration");
final Map<String, Object> configuration = configDoc.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
final LegacyAlarmCallbackEventNotificationConfig config = LegacyAlarmCallbackEventNotificationConfig.builder().callbackType(type).configuration(configuration).build();
final NotificationDto dto = NotificationDto.builder().title(firstNonNull(title, "Untitled")).description("Migrated legacy alarm callback").config(config).build();
LOG.info("Migrate legacy alarm callback <{}>", dto.title());
return notificationResourceHandler.create(dto, userService.getRootUser());
}
use of org.graylog.events.notifications.NotificationDto in project graylog2-server by Graylog2.
the class NotificationFacade method decode.
private NativeEntity<NotificationDto> decode(EntityV1 entityV1, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, User user) {
final NotificationEntity entity = objectMapper.convertValue(entityV1.data(), NotificationEntity.class);
final NotificationDto notificationDto = entity.toNativeEntity(parameters, nativeEntities);
final NotificationDto savedDto = notificationResourceHandler.create(notificationDto, Optional.ofNullable(user));
return NativeEntity.create(entityV1.id(), savedDto.id(), ModelTypes.NOTIFICATION_V1, savedDto.title(), savedDto);
}
Aggregations