Search in sources :

Example 36 with Notification

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

the class ClusterHealthCheckThread method getNotification.

protected Notification getNotification() throws NodeNotFoundException {
    Notification notification = notificationService.buildNow();
    notification.addType(Notification.Type.NO_INPUT_RUNNING);
    notification.addSeverity(Notification.Severity.URGENT);
    notification.addNode(nodeId.toString());
    return notification;
}
Also used : Notification(org.graylog2.notifications.Notification)

Example 37 with Notification

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

the class GarbageCollectionWarningThread method doRun.

@Override
public void doRun() {
    for (final GarbageCollectorMXBean gc : garbageCollectors) {
        switch(gc.getName()) {
            case "ParNew":
            case "ConcurrentMarkSweep":
                LOG.debug("Skipping GC warning listener for concurrent collector {}.", gc.getName());
                continue;
        }
        LOG.debug("Installing GC warning listener for collector {}, total runtime threshold is {}.", gc.getName(), gcWarningThreshold);
        final NotificationEmitter emitter = (NotificationEmitter) gc;
        final NotificationListener listener = new NotificationListener() {

            @SuppressForbidden("Deliberate usage of GcInfo and GarbageCollectionNotificationInfo")
            @Override
            public void handleNotification(javax.management.Notification notification, Object handback) {
                if (GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION.equals(notification.getType())) {
                    final GcInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()).getGcInfo();
                    final Duration duration = Duration.milliseconds(gcInfo.getDuration());
                    if (duration.compareTo(gcWarningThreshold) > 0) {
                        LOG.warn("Last GC run with {} took longer than {} (last duration={})", gc.getName(), gcWarningThreshold, duration);
                        final Notification systemNotification = notificationService.buildNow().addNode(nodeId.toString()).addTimestamp(Tools.nowUTC()).addSeverity(Notification.Severity.URGENT).addType(Notification.Type.GC_TOO_LONG).addDetail("gc_name", gc.getName()).addDetail("gc_duration_ms", duration.toMilliseconds()).addDetail("gc_threshold_ms", gcWarningThreshold.toMilliseconds()).addDetail("gc_collection_count", gc.getCollectionCount()).addDetail("gc_collection_time", gc.getCollectionTime());
                        if (!notificationService.publishIfFirst(systemNotification)) {
                            LOG.debug("Couldn't publish notification: {}", notification);
                        }
                    }
                }
            }
        };
        emitter.addNotificationListener(listener, null, null);
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) GcInfo(com.sun.management.GcInfo) CompositeData(javax.management.openmbean.CompositeData) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) Duration(com.github.joschi.jadconfig.util.Duration) Notification(org.graylog2.notifications.Notification) NotificationListener(javax.management.NotificationListener)

Example 38 with Notification

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

the class NotificationsResource method deleteNotification.

@DELETE
@Timed
@Path("/{notificationType}")
@ApiOperation(value = "Delete a notification")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such notification type.") })
@AuditEvent(type = AuditEventTypes.SYSTEM_NOTIFICATION_DELETE)
public void deleteNotification(@ApiParam(name = "notificationType") @PathParam("notificationType") String notificationType) {
    Notification.Type type;
    checkPermission(RestPermissions.NOTIFICATIONS_DELETE, notificationType);
    try {
        type = Notification.Type.valueOf(notificationType.toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException e) {
        LOG.warn("No such notification type: [" + notificationType + "]");
        throw new BadRequestException(e);
    }
    notificationService.destroyAllByType(type);
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) Notification(org.graylog2.notifications.Notification) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 39 with Notification

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

the class NotificationsResource method listNotifications.

@GET
@Timed
@ApiOperation(value = "Get all active notifications")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> listNotifications() {
    final List<Map<String, Object>> notifications = Lists.newArrayList();
    for (Notification n : notificationService.all()) {
        final String notificationType = n.getType().toString().toLowerCase(Locale.ENGLISH);
        if (!isPermitted(RestPermissions.NOTIFICATIONS_READ, notificationType)) {
            continue;
        }
        final Map<String, Object> notification = n.asMap();
        try {
            notifications.add(notification);
        } catch (IllegalArgumentException e) {
            LOG.warn("There is a notification type we can't handle: [" + n.getType() + "]");
        }
    }
    return ImmutableMap.of("total", notifications.size(), "notifications", notifications);
}
Also used : Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Notification(org.graylog2.notifications.Notification) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 40 with Notification

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

the class StreamServiceImpl method destroy.

@Override
public void destroy(Stream stream) throws NotFoundException {
    for (StreamRule streamRule : streamRuleService.loadForStream(stream)) {
        super.destroy(streamRule);
    }
    final String streamId = stream.getId();
    for (Notification notification : notificationService.all()) {
        Object rawValue = notification.getDetail("stream_id");
        if (rawValue != null && rawValue.toString().equals(streamId)) {
            LOG.debug("Removing notification that references stream: {}", notification);
            notificationService.destroy(notification);
        }
    }
    super.destroy(stream);
    clusterEventBus.post(StreamsChangedEvent.create(streamId));
    clusterEventBus.post(StreamDeletedEvent.create(streamId));
    entityOwnershipService.unregisterStream(streamId);
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Notification(org.graylog2.notifications.Notification)

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