Search in sources :

Example 1 with Notification

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

the class EventNotificationHandlerConfigEntity method toNativeEntity.

@Override
public EventNotificationHandler.Config toNativeEntity(Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> natvieEntities) {
    String notificationId = notificationId().asString(parameters);
    final EntityDescriptor notificationDescriptor = EntityDescriptor.create(notificationId, ModelTypes.NOTIFICATION_V1);
    final Object notification = natvieEntities.get(notificationDescriptor);
    final EventNotificationHandler.Config.Builder configBuilder = EventNotificationHandler.Config.builder();
    if (notification == null) {
        throw new ContentPackException("Missing notification (" + notificationId + ") for event definition");
    } else if (notification instanceof NotificationDto) {
        NotificationDto notificationDto = (NotificationDto) notification;
        configBuilder.notificationId(notificationDto.id());
    } else {
        throw new ContentPackException("Invalid type for notification (" + notificationId + ") of event definition: " + notification.getClass());
    }
    return configBuilder.notificationParameters(notificationParameters().orElse(null)).build();
}
Also used : ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NotificationDto(org.graylog.events.notifications.NotificationDto)

Example 2 with Notification

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

the class NotificationFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Optional<NotificationDto> notificationDto = notificationService.get(modelId.id());
    if (!notificationDto.isPresent()) {
        LOG.debug("Couldn't find notification {}", entityDescriptor);
        return Optional.empty();
    }
    final NotificationEntity entity = (NotificationEntity) notificationDto.get().toContentPackEntity(entityDescriptorIds);
    final JsonNode data = objectMapper.convertValue(entity, JsonNode.class);
    return Optional.of(EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(notificationDto.get().id(), ModelTypes.NOTIFICATION_V1))).type(ModelTypes.NOTIFICATION_V1).data(data).build());
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 3 with Notification

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

the class IndexRetentionThread method retentionProblemNotification.

private void retentionProblemNotification(String title, String description) {
    final Notification notification = notificationService.buildNow().addNode(nodeId.toString()).addType(Notification.Type.GENERIC).addSeverity(Notification.Severity.URGENT).addDetail("title", title).addDetail("description", description);
    notificationService.publishIfFirst(notification);
}
Also used : Notification(org.graylog2.notifications.Notification)

Example 4 with Notification

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

the class IndexerClusterCheckerThread method publishDiskUsageNotifications.

private void publishDiskUsageNotifications(Map<Notification.Type, List<String>> notificationTypePerNodeIdentifier) {
    for (Map.Entry<Notification.Type, List<String>> entry : notificationTypePerNodeIdentifier.entrySet()) {
        if (!notificationExists(entry.getKey())) {
            Notification notification = notificationService.buildNow().addType(entry.getKey()).addSeverity(Notification.Severity.URGENT).addDetail("nodes", String.join(", ", entry.getValue()));
            notificationService.publishIfFirst(notification);
            for (String node : entry.getValue()) {
                LOG.warn("Elasticsearch node [{}] triggered [{}] due to low free disk space", node, entry.getKey());
            }
        }
    }
}
Also used : List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) HashMap(java.util.HashMap) Map(java.util.Map) Notification(org.graylog2.notifications.Notification)

Example 5 with Notification

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

the class IndexerClusterCheckerThread method checkOpenFiles.

@VisibleForTesting
void checkOpenFiles() {
    if (notificationExists(Notification.Type.ES_OPEN_FILES)) {
        return;
    }
    boolean allHigher = true;
    final Set<NodeFileDescriptorStats> fileDescriptorStats = cluster.getFileDescriptorStats();
    for (NodeFileDescriptorStats nodeFileDescriptorStats : fileDescriptorStats) {
        final String name = nodeFileDescriptorStats.name();
        final String ip = nodeFileDescriptorStats.ip();
        final String host = nodeFileDescriptorStats.host();
        final long maxFileDescriptors = nodeFileDescriptorStats.fileDescriptorMax().orElse(-1L);
        if (maxFileDescriptors != -1L && maxFileDescriptors < MINIMUM_OPEN_FILES_LIMIT) {
            // Write notification.
            final String ipOrHostName = firstNonNull(host, ip);
            final Notification notification = notificationService.buildNow().addType(Notification.Type.ES_OPEN_FILES).addSeverity(Notification.Severity.URGENT).addDetail("hostname", ipOrHostName).addDetail("max_file_descriptors", maxFileDescriptors);
            if (notificationService.publishIfFirst(notification)) {
                LOG.warn("Indexer node <{}> ({}) open file limit is too low: [{}]. Set it to at least {}.", name, ipOrHostName, maxFileDescriptors, MINIMUM_OPEN_FILES_LIMIT);
            }
            allHigher = false;
        }
    }
    if (allHigher) {
        Notification notification = notificationService.build().addType(Notification.Type.ES_OPEN_FILES);
        notificationService.fixed(notification);
    }
}
Also used : NodeFileDescriptorStats(org.graylog2.indexer.cluster.health.NodeFileDescriptorStats) Notification(org.graylog2.notifications.Notification) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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