Search in sources :

Example 41 with Notification

use of org.graylog2.notifications.Notification in project graylog2-server by Graylog2.

the class StreamFaultManager method triggerNotification.

private void triggerNotification(final Stream stream, final int streamFaultCount) {
    final Notification notification = notificationService.buildNow().addType(Notification.Type.STREAM_PROCESSING_DISABLED).addSeverity(Notification.Severity.URGENT).addDetail("stream_id", stream.getId()).addDetail("stream_title", stream.getTitle()).addDetail("fault_count", streamFaultCount);
    notificationService.publishIfFirst(notification);
}
Also used : Notification(org.graylog2.notifications.Notification)

Example 42 with Notification

use of org.graylog2.notifications.Notification 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");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) NotificationDto(org.graylog.events.notifications.NotificationDto) JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) Test(org.junit.Test)

Example 43 with Notification

use of org.graylog2.notifications.Notification in project graylog2-server by Graylog2.

the class NotificationFacadeTest method exportEntity.

@Test
@MongoDBFixtures("NotificationFacadeTest.json")
public void exportEntity() {
    final ModelId id = ModelId.of("5d4d33753d27460ad18e0c4d");
    final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.NOTIFICATION_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Optional<Entity> entity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(entity).isPresent();
    final EntityV1 entityV1 = (EntityV1) entity.get();
    final NotificationEntity notificationEntity = objectMapper.convertValue(entityV1.data(), NotificationEntity.class);
    assertThat(notificationEntity.title().asString()).isEqualTo("title");
    assertThat(notificationEntity.description().asString()).isEqualTo("description");
    assertThat(notificationEntity.config().type()).isEqualTo("email-notification-v1");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) EmailEventNotificationConfigEntity(org.graylog.events.contentpack.entities.EmailEventNotificationConfigEntity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 44 with Notification

use of org.graylog2.notifications.Notification in project graylog2-server by Graylog2.

the class EmailSender method sendEmails.

// TODO: move EmailRecipients class to events code
void sendEmails(EmailEventNotificationConfig notificationConfig, EventNotificationContext ctx, ImmutableList<MessageSummary> backlog) throws TransportConfigurationException, EmailException, ConfigurationError {
    if (!emailFactory.isEmailTransportEnabled()) {
        throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
    }
    final EmailRecipients emailRecipients = emailRecipientsFactory.create(new ArrayList<>(notificationConfig.userRecipients()), new ArrayList<>(notificationConfig.emailRecipients()));
    if (emailRecipients.isEmpty()) {
        LOG.debug("Cannot send emails: empty recipient list.");
        return;
    }
    final Set<String> recipientsSet = emailRecipients.getEmailRecipients();
    if (recipientsSet.size() == 0) {
        final Notification notification = notificationService.buildNow().addNode(nodeId.toString()).addType(Notification.Type.GENERIC).addSeverity(Notification.Severity.NORMAL).addDetail("title", "No recipients have been defined!").addDetail("description", "To fix this, go to the notification configuration and add at least one alert recipient.");
        notificationService.publishIfFirst(notification);
    }
    final Map<String, Object> model = getModel(ctx, backlog, notificationConfig.timeZone());
    for (String email : recipientsSet) {
        sendEmail(notificationConfig, email, model);
    }
}
Also used : TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) EmailRecipients(org.graylog2.alerts.EmailRecipients) Notification(org.graylog2.notifications.Notification)

Example 45 with Notification

use of org.graylog2.notifications.Notification in project graylog2-server by Graylog2.

the class EventBacklogService method getMessagesForEvent.

public ImmutableList<MessageSummary> getMessagesForEvent(EventDto eventDto, long backlogSize) throws NotFoundException {
    if (backlogSize <= 0) {
        return ImmutableList.of();
    }
    final EventProcessor.Factory factory = eventProcessorFactories.get(eventDto.eventDefinitionType());
    if (factory == null) {
        throw new NotFoundException("Couldn't find event processor factory for type " + eventDto.eventDefinitionType());
    }
    final EventDefinition eventDefinition = eventDefinitionService.get(eventDto.eventDefinitionId()).orElseThrow(() -> new NotFoundException("Could not find event definintion <" + eventDto.eventDefinitionId() + ">"));
    final EventProcessor eventProcessor = factory.create(eventDefinition);
    final ImmutableList.Builder<MessageSummary> backlogBuilder = ImmutableList.builder();
    try {
        eventProcessor.sourceMessagesForEvent(Event.fromDto(eventDto), backlogBuilder::addAll, backlogSize);
    } catch (EventProcessorException e) {
        // TODO return this error, so it can be included in the notification message?
        LOG.error("Failed to query backlog messages for Event {}", eventDto.id(), e);
    }
    return backlogBuilder.build();
}
Also used : EventProcessorException(org.graylog.events.processor.EventProcessorException) ImmutableList(com.google.common.collect.ImmutableList) EventProcessor(org.graylog.events.processor.EventProcessor) NotFoundException(org.graylog2.database.NotFoundException) EventDefinition(org.graylog.events.processor.EventDefinition) MessageSummary(org.graylog2.plugin.MessageSummary)

Aggregations

Notification (org.graylog2.notifications.Notification)28 Test (org.junit.Test)7 ImmutableList (com.google.common.collect.ImmutableList)6 ApiOperation (io.swagger.annotations.ApiOperation)6 NotificationDto (org.graylog.events.notifications.NotificationDto)6 Map (java.util.Map)5 EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)5 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)5 Activity (org.graylog2.shared.system.activities.Activity)5 Timed (com.codahale.metrics.annotation.Timed)4 List (java.util.List)4 Path (javax.ws.rs.Path)4 JobDefinitionDto (org.graylog.scheduler.JobDefinitionDto)4 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)4 NotFoundException (org.graylog2.database.NotFoundException)4 MessageSummary (org.graylog2.plugin.MessageSummary)4 TransportConfigurationException (org.graylog2.plugin.alarms.transports.TransportConfigurationException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ApiResponses (io.swagger.annotations.ApiResponses)3