Search in sources :

Example 21 with Notification

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

the class IndexerClusterCheckerThread method doRun.

@Override
public void doRun() {
    if (!notificationService.isFirst(Notification.Type.ES_OPEN_FILES)) {
        return;
    }
    try {
        cluster.health().getStatus();
    } catch (Exception e) {
        LOG.info("Indexer not fully initialized yet. Skipping periodic cluster check.");
        return;
    }
    boolean allHigher = true;
    final Map<String, NodeInfo> nodesInfos = cluster.getDataNodes();
    final Map<String, NodeStats> nodesStats = cluster.getNodesStats(nodesInfos.keySet().toArray(new String[nodesInfos.size()]));
    for (Map.Entry<String, NodeStats> entry : nodesStats.entrySet()) {
        final String nodeId = entry.getKey();
        final NodeStats nodeStats = entry.getValue();
        final NodeInfo nodeInfo = nodesInfos.get(nodeId);
        final String nodeName = nodeInfo.getNode().getName();
        // Check number of maximum open files.
        final ProcessStats processStats = nodeStats.getProcess();
        if (processStats == null) {
            LOG.debug("Couldn't read process stats of Elasticsearch node {}", nodeName);
            return;
        }
        final long maxFileDescriptors = processStats.getMaxFileDescriptors();
        final JvmInfo jvmInfo = nodeInfo.getJvm();
        if (jvmInfo == null) {
            LOG.debug("Couldn't read JVM info of Elasticsearch node {}", nodeName);
            return;
        }
        final String osName = jvmInfo.getSystemProperties().getOrDefault("os.name", "");
        if (osName.startsWith("Windows")) {
            LOG.debug("Skipping open file limit check for Indexer node <{}> on Windows", nodeName);
        } else if (maxFileDescriptors != -1 && maxFileDescriptors < MINIMUM_OPEN_FILES_LIMIT) {
            // Write notification.
            final Notification notification = notificationService.buildNow().addType(Notification.Type.ES_OPEN_FILES).addSeverity(Notification.Severity.URGENT).addDetail("hostname", nodeInfo.getHostname()).addDetail("max_file_descriptors", maxFileDescriptors);
            if (notificationService.publishIfFirst(notification)) {
                LOG.warn("Indexer node <{}> open file limit is too low: [{}]. Set it to at least {}.", nodeName, maxFileDescriptors, MINIMUM_OPEN_FILES_LIMIT);
            }
            allHigher = false;
        }
    }
    if (allHigher) {
        Notification notification = notificationService.build().addType(Notification.Type.ES_OPEN_FILES);
        notificationService.fixed(notification);
    }
}
Also used : ProcessStats(org.elasticsearch.monitor.process.ProcessStats) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) Notification(org.graylog2.notifications.Notification) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) Map(java.util.Map)

Example 22 with Notification

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

the class EmailAlarmCallback method call.

@Override
public void call(Stream stream, AlertCondition.CheckResult result) throws AlarmCallbackException {
    // Send alerts.
    final EmailRecipients emailRecipients = this.getEmailRecipients();
    if (emailRecipients.isEmpty()) {
        if (!emailConfiguration.isEnabled()) {
            throw new AlarmCallbackException("Email transport is not enabled in server configuration file!");
        }
        LOG.info("Alarm callback has no email recipients, not sending any emails.");
        return;
    }
    AlertCondition alertCondition = result.getTriggeredCondition();
    try {
        if (alertCondition.getBacklog() > 0 && result.getMatchingMessages() != null) {
            alertSender.sendEmails(stream, emailRecipients, result, getAlarmBacklog(result));
        } else {
            alertSender.sendEmails(stream, emailRecipients, result);
        }
    } catch (TransportConfigurationException e) {
        LOG.warn("Alarm callback has email recipients and is triggered, but email transport is not configured.");
        Notification notification = notificationService.buildNow().addNode(nodeId.toString()).addType(Notification.Type.EMAIL_TRANSPORT_CONFIGURATION_INVALID).addSeverity(Notification.Severity.NORMAL).addDetail("stream_id", stream.getId()).addDetail("exception", e.getMessage());
        notificationService.publishIfFirst(notification);
        throw new AlarmCallbackException(e.getMessage(), e);
    } catch (Exception e) {
        LOG.error("Alarm callback has email recipients and is triggered, but sending emails failed", e);
        String exceptionDetail = e.toString();
        if (e.getCause() != null) {
            exceptionDetail += " (" + e.getCause() + ")";
        }
        Notification notification = notificationService.buildNow().addNode(nodeId.toString()).addType(Notification.Type.EMAIL_TRANSPORT_FAILED).addSeverity(Notification.Severity.NORMAL).addDetail("stream_id", stream.getId()).addDetail("exception", exceptionDetail);
        notificationService.publishIfFirst(notification);
        throw new AlarmCallbackException(e.getMessage(), e);
    }
}
Also used : TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) EmailRecipients(org.graylog2.alerts.EmailRecipients) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) Notification(org.graylog2.notifications.Notification) TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException)

Example 23 with Notification

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

the class AlertServiceImpl method shouldRepeatNotifications.

@Override
public boolean shouldRepeatNotifications(AlertCondition alertCondition, Alert alert) {
    // Do not repeat notifications if alert has no state, is resolved or the option to repeat notifications is disabled
    if (!alert.isInterval() || isResolved(alert) || !alertCondition.shouldRepeatNotifications()) {
        return false;
    }
    // Repeat notifications if no grace period is set, avoiding looking through the notification history
    if (alertCondition.getGrace() == 0) {
        return true;
    }
    AlarmCallbackHistory lastTriggeredAlertHistory = null;
    for (AlarmCallbackHistory history : alarmCallbackHistoryService.getForAlertId(alert.getId())) {
        if (lastTriggeredAlertHistory == null || lastTriggeredAlertHistory.createdAt().isBefore(history.createdAt())) {
            lastTriggeredAlertHistory = history;
        }
    }
    // Repeat notifications if no alert was ever triggered for this condition
    if (lastTriggeredAlertHistory == null) {
        return true;
    }
    final int lastAlertSecondsAgo = Seconds.secondsBetween(lastTriggeredAlertHistory.createdAt(), Tools.nowUTC()).getSeconds();
    return lastAlertSecondsAgo >= alertCondition.getGrace() * 60;
}
Also used : AlarmCallbackHistory(org.graylog2.alarmcallbacks.AlarmCallbackHistory)

Example 24 with Notification

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

the class Server method startNodeRegistration.

@Override
protected void startNodeRegistration(Injector injector) {
    // Register this node.
    final NodeService nodeService = injector.getInstance(NodeService.class);
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    final ActivityWriter activityWriter = injector.getInstance(ActivityWriter.class);
    final LeaderElectionService leaderElectionService = injector.getInstance(LeaderElectionService.class);
    nodeService.registerServer(serverStatus.getNodeId().toString(), leaderElectionService.isLeader(), httpConfiguration.getHttpPublishUri(), Tools.getLocalCanonicalHostname());
    serverStatus.setLocalMode(isLocal());
    if (leaderElectionService.isLeader() && !nodeService.isOnlyLeader(serverStatus.getNodeId())) {
        LOG.warn("Detected another leader in the cluster. Retrying in {} seconds to make sure it is not " + "an old stale instance.", TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleLeaderTimeout()));
        try {
            Thread.sleep(configuration.getStaleLeaderTimeout());
        } catch (InterruptedException e) {
        /* nope */
        }
        if (!nodeService.isOnlyLeader(serverStatus.getNodeId())) {
            // All devils here.
            String what = "Detected other leader node in the cluster! Starting as non-leader! " + "This is a mis-configuration you should fix.";
            LOG.warn(what);
            activityWriter.write(new Activity(what, Server.class));
            final NotificationService notificationService = injector.getInstance(NotificationService.class);
            // remove legacy notification, if present
            // noinspection deprecation
            notificationService.fixed(notificationService.build().addType(Notification.Type.MULTI_MASTER));
            // Write a notification.
            Notification notification = notificationService.buildNow().addType(Notification.Type.MULTI_LEADER).addSeverity(Notification.Severity.URGENT);
            notificationService.publishIfFirst(notification);
            configuration.setIsLeader(false);
        } else {
            LOG.warn("Stale leader has gone. Starting as leader.");
        }
    }
}
Also used : NodeService(org.graylog2.cluster.NodeService) ServerStatus(org.graylog2.plugin.ServerStatus) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) LeaderElectionService(org.graylog2.cluster.leader.LeaderElectionService) Activity(org.graylog2.shared.system.activities.Activity) NotificationService(org.graylog2.notifications.NotificationService) Notification(org.graylog2.notifications.Notification)

Example 25 with Notification

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

the class FixDeflectorByDeleteJob method doExecute.

public void doExecute(IndexSet indexSet) {
    if (!indexSet.getConfig().isWritable()) {
        LOG.debug("No need to fix deflector for non-writable index set <{}> ({})", indexSet.getConfig().id(), indexSet.getConfig().title());
        return;
    }
    if (indexSet.isUp() || !indices.exists(indexSet.getWriteIndexAlias())) {
        LOG.error("There is no index <{}>. No need to run this job. Aborting.", indexSet.getWriteIndexAlias());
        return;
    }
    LOG.info("Attempting to fix deflector with delete strategy.");
    // Pause message processing and lock the pause.
    boolean wasProcessing = serverStatus.isProcessing();
    serverStatus.pauseMessageProcessing();
    progress = 10;
    bufferSynchronizer.waitForEmptyBuffers(EnumSet.of(PROCESS, OUTPUT));
    progress = 25;
    // Delete deflector index.
    LOG.info("Deleting <{}> index.", indexSet.getWriteIndexAlias());
    indices.delete(indexSet.getWriteIndexAlias());
    progress = 70;
    // Set up deflector.
    indexSet.setUp();
    progress = 80;
    // Start message processing again.
    try {
        serverStatus.unlockProcessingPause();
        if (wasProcessing) {
            serverStatus.resumeMessageProcessing();
        }
    } catch (Exception e) {
        // lol checked exceptions
        throw new RuntimeException("Could not unlock processing pause.", e);
    }
    progress = 90;
    activityWriter.write(new Activity("Notification condition [" + Notification.Type.DEFLECTOR_EXISTS_AS_INDEX + "] " + "has been fixed.", this.getClass()));
    notificationService.fixed(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX);
    progress = 100;
    LOG.info("Finished.");
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

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