Search in sources :

Example 31 with Notification

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

the class V20201103145400_LegacyAuthServiceMigration method upgrade.

@Override
public void upgrade() {
    final MigrationCompleted migrationState = clusterConfigService.getOrDefault(MigrationCompleted.class, MigrationCompleted.createEmpty());
    final ImmutableSet.Builder<String> migratedConfigsBuilder = ImmutableSet.builder();
    // While the LDAP settings collection could contain more than one document, in practice we only expect a
    // single one. That's why we are using the ID of the last created auth service for the notification.
    String lastCreatedAuthServiceId = null;
    // Add all configs that have already been migrated
    migratedConfigsBuilder.addAll(migrationState.migratedConfigs());
    for (final Document document : ldapSettings.find().sort(Sorts.ascending("_id"))) {
        final String idString = document.getObjectId("_id").toHexString();
        if (!document.getBoolean("enabled")) {
            LOG.debug("Skipping disabled configuration <{}>", idString);
            continue;
        }
        if (migrationState.isDone(idString)) {
            LOG.debug("Configuration <{}> already migrated", idString);
            continue;
        }
        final AuthServiceBackendDTO newConfig;
        if (document.getBoolean("active_directory")) {
            newConfig = buildActiveDirectoryConfig(document);
        } else {
            newConfig = buildLDAPConfig(document);
        }
        final AuthServiceBackendDTO savedConfig = authServiceBackendService.save(newConfig);
        for (final MigrationModule migrationModule : migrationModules) {
            migrationModule.upgrade(document, savedConfig);
        }
        lastCreatedAuthServiceId = savedConfig.id();
        migratedConfigsBuilder.add(idString);
    }
    final ImmutableSet<String> migratedConfigs = migratedConfigsBuilder.build();
    clusterConfigService.write(MigrationCompleted.create(migratedConfigs));
    if (lastCreatedAuthServiceId != null) {
        final Notification notification = notificationService.buildNow().addType(Notification.Type.LEGACY_LDAP_CONFIG_MIGRATION).addSeverity(Notification.Severity.URGENT).addDetail("auth_service_id", lastCreatedAuthServiceId);
        notificationService.publishIfFirst(notification);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) AuthServiceBackendDTO(org.graylog.security.authservice.AuthServiceBackendDTO) Document(org.bson.Document) Notification(org.graylog2.notifications.Notification)

Example 32 with Notification

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

the class IndexRotationThread method rotationProblemNotification.

private void rotationProblemNotification(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 33 with Notification

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

the class IndexRotationThread method checkAndRepair.

protected void checkAndRepair(IndexSet indexSet) {
    if (!indexSet.isUp()) {
        if (indices.exists(indexSet.getWriteIndexAlias())) {
            // Publish a notification if there is an *index* called graylog2_deflector
            Notification notification = notificationService.buildNow().addType(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX).addSeverity(Notification.Severity.URGENT);
            final boolean published = notificationService.publishIfFirst(notification);
            if (published) {
                LOG.warn("There is an index called [" + indexSet.getWriteIndexAlias() + "]. Cannot fix this automatically and published a notification.");
            }
        } else {
            indexSet.setUp();
        }
    } else {
        try {
            String currentTarget;
            try {
                currentTarget = indexSet.getActiveWriteIndex();
            } catch (TooManyAliasesException e) {
                // If we get this exception, there are multiple indices which have the deflector alias set.
                // We try to cleanup the alias and try again. This should not happen, but might under certain
                // circumstances.
                indexSet.cleanupAliases(e.getIndices());
                try {
                    currentTarget = indexSet.getActiveWriteIndex();
                } catch (TooManyAliasesException e1) {
                    throw new IllegalStateException(e1);
                }
            }
            String shouldBeTarget = indexSet.getNewestIndex();
            if (!shouldBeTarget.equals(currentTarget)) {
                String msg = "Deflector is pointing to [" + currentTarget + "], not the newest one: [" + shouldBeTarget + "]. Re-pointing.";
                LOG.warn(msg);
                activityWriter.write(new Activity(msg, IndexRotationThread.class));
                if (indices.waitForRecovery(shouldBeTarget) == HealthStatus.Red) {
                    LOG.error("New target index for deflector didn't get healthy within timeout. Skipping deflector update.");
                } else {
                    indexSet.pointTo(shouldBeTarget, currentTarget);
                }
            }
        } catch (NoTargetIndexException e) {
            LOG.warn("Deflector is not up. Not trying to point to another index.");
        }
    }
}
Also used : NoTargetIndexException(org.graylog2.indexer.NoTargetIndexException) Activity(org.graylog2.shared.system.activities.Activity) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) Notification(org.graylog2.notifications.Notification)

Example 34 with Notification

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

the class NodePingThread method doRun.

@Override
public synchronized // This method is "synchronized" because we are also calling it directly in AutomaticLeaderElectionService
void doRun() {
    final boolean isLeader = leaderElectionService.isLeader();
    try {
        Node node = nodeService.byNodeId(serverStatus.getNodeId());
        nodeService.markAsAlive(node, isLeader, httpConfiguration.getHttpPublishUri().resolve(HttpConfiguration.PATH_API));
    } catch (NodeNotFoundException e) {
        LOG.warn("Did not find meta info of this node. Re-registering.");
        nodeService.registerServer(serverStatus.getNodeId().toString(), isLeader, httpConfiguration.getHttpPublishUri().resolve(HttpConfiguration.PATH_API), Tools.getLocalCanonicalHostname());
    }
    try {
        // Remove old nodes that are no longer running. (Just some housekeeping)
        nodeService.dropOutdated();
        // Check that we still have a leader node in the cluster, if not, warn the user.
        if (nodeService.isAnyLeaderPresent()) {
            if (fixNoLeaderNotification()) {
                activityWriter.write(new Activity("Notification condition [" + NotificationImpl.Type.NO_LEADER + "] " + "has been fixed.", NodePingThread.class));
            }
        } else {
            Notification notification = notificationService.buildNow().addNode(serverStatus.getNodeId().toString()).addType(Notification.Type.NO_LEADER).addSeverity(Notification.Severity.URGENT);
            notificationService.publishIfFirst(notification);
        }
    } catch (Exception e) {
        LOG.warn("Caught exception during node ping.", e);
    }
}
Also used : NodeNotFoundException(org.graylog2.cluster.NodeNotFoundException) Node(org.graylog2.cluster.Node) Activity(org.graylog2.shared.system.activities.Activity) Notification(org.graylog2.notifications.Notification) NodeNotFoundException(org.graylog2.cluster.NodeNotFoundException)

Example 35 with Notification

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

the class ThrottleStateUpdaterThread method doRun.

@Override
public void doRun() {
    throttleState = new ThrottleState(throttleState);
    final long committedOffset = journal.getCommittedOffset();
    // TODO there's a lot of duplication around this class. Probably should be refactored a bit.
    // also update metrics for each of the values, so clients can get to it cheaply
    long prevTs = currentTs;
    currentTs = System.nanoTime();
    long previousLogEndOffset = logEndOffset;
    long previousReadOffset = currentReadOffset;
    long logStartOffset = journal.getLogStartOffset();
    // -1 because getLogEndOffset is the next offset that gets assigned
    logEndOffset = journal.getLogEndOffset() - 1;
    // just to make it clear which field we read
    currentReadOffset = journal.getNextReadOffset() - 1;
    // for the first run, don't send an update, there's no previous data available to calc rates
    if (firstRun) {
        firstRun = false;
        return;
    }
    throttleState.appendEventsPerSec = (long) Math.floor((logEndOffset - previousLogEndOffset) / ((currentTs - prevTs) / 1.0E09));
    throttleState.readEventsPerSec = (long) Math.floor((currentReadOffset - previousReadOffset) / ((currentTs - prevTs) / 1.0E09));
    throttleState.journalSize = journal.size();
    throttleState.journalSizeLimit = retentionSize.toBytes();
    throttleState.processBufferCapacity = processBuffer.getRemainingCapacity();
    if (committedOffset == LocalKafkaJournal.DEFAULT_COMMITTED_OFFSET) {
        // nothing committed at all, the entire log is uncommitted, or completely empty.
        throttleState.uncommittedJournalEntries = journal.size() == 0 ? 0 : logEndOffset - logStartOffset;
    } else {
        throttleState.uncommittedJournalEntries = logEndOffset - committedOffset;
    }
    log.debug("ThrottleState: {}", throttleState);
    // the journal needs this to provide information to rest clients
    journal.setThrottleState(throttleState);
    // publish to interested parties
    eventBus.post(throttleState);
    // Abusing the current thread to send notifications from KafkaJournal in the graylog2-shared module
    final double journalUtilizationPercentage = throttleState.journalSizeLimit > 0 ? (throttleState.journalSize * 100) / throttleState.journalSizeLimit : 0.0;
    if (journalUtilizationPercentage > LocalKafkaJournal.NOTIFY_ON_UTILIZATION_PERCENTAGE) {
        Notification notification = notificationService.buildNow().addNode(serverStatus.getNodeId().toString()).addType(Notification.Type.JOURNAL_UTILIZATION_TOO_HIGH).addSeverity(Notification.Severity.URGENT).addDetail("journal_utilization_percentage", journalUtilizationPercentage);
        notificationService.publishIfFirst(notification);
    }
    if (journal.getPurgedSegmentsInLastRetention() > 0) {
        Notification notification = notificationService.buildNow().addNode(serverStatus.getNodeId().toString()).addType(Notification.Type.JOURNAL_UNCOMMITTED_MESSAGES_DELETED).addSeverity(Notification.Severity.URGENT);
        notificationService.publishIfFirst(notification);
    }
}
Also used : ThrottleState(org.graylog2.plugin.ThrottleState) 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