Search in sources :

Example 26 with Notification

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

the class FixDeflectorByMoveJob 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 move strategy.");
    boolean wasProcessing = true;
    try {
        // Pause message processing and lock the pause.
        wasProcessing = serverStatus.isProcessing();
        serverStatus.pauseMessageProcessing();
        progress = 5;
        bufferSynchronizer.waitForEmptyBuffers(EnumSet.of(PROCESS, OUTPUT));
        progress = 10;
        // Copy messages to new index.
        String newTarget = null;
        try {
            newTarget = indexSet.getNewestIndex();
            LOG.info("Starting to move <{}> to <{}>.", indexSet.getWriteIndexAlias(), newTarget);
            indices.move(indexSet.getWriteIndexAlias(), newTarget);
        } catch (Exception e) {
            LOG.error("Moving index failed. Rolling back.", e);
            if (newTarget != null) {
                indices.delete(newTarget);
            }
            throw new RuntimeException(e);
        }
        LOG.info("Done moving deflector index.");
        progress = 85;
        // Delete deflector index.
        LOG.info("Deleting <{}> index.", indexSet.getWriteIndexAlias());
        indices.delete(indexSet.getWriteIndexAlias());
        progress = 90;
        // Set up deflector.
        indexSet.setUp();
        progress = 95;
    } finally {
        // Start message processing again.
        serverStatus.unlockProcessingPause();
        if (wasProcessing) {
            serverStatus.resumeMessageProcessing();
        }
    }
    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)

Example 27 with Notification

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

the class LookupTableService method createCache.

private LookupCache createCache(CacheDto dto) {
    try {
        final LookupCache.Factory<? extends LookupCache> factory = cacheFactories.get(dto.config().type());
        if (factory == null) {
            LOG.warn("Unable to load cache {} of type {}, missing a factory. Is a required plugin missing?", dto.name(), dto.config().type());
            // TODO system notification
            return null;
        }
        final LookupCache cache = factory.create(dto.id(), dto.name(), dto.config());
        cache.addListener(new LoggingServiceListener("Cache", String.format(Locale.ENGLISH, "%s/%s [@%s]", dto.name(), dto.id(), objectId(cache)), LOG), scheduler);
        return cache;
    } catch (Exception e) {
        LOG.error("Couldn't create cache <{}/{}>", dto.name(), dto.id(), e);
        return null;
    }
}
Also used : LookupCache(org.graylog2.plugin.lookup.LookupCache) LoggingServiceListener(org.graylog2.utilities.LoggingServiceListener)

Example 28 with Notification

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

the class LookupTableService method createAdapter.

protected LookupDataAdapter createAdapter(DataAdapterDto dto) {
    try {
        final LookupDataAdapter.Factory2 factory2 = adapterFactories2.get(dto.config().type());
        final LookupDataAdapter.Factory factory = adapterFactories.get(dto.config().type());
        final LookupDataAdapter adapter;
        if (factory2 != null) {
            adapter = factory2.create(dto);
        } else if (factory != null) {
            adapter = factory.create(dto.id(), dto.name(), dto.config());
        } else {
            LOG.warn("Unable to load data adapter {} of type {}, missing a factory. Is a required plugin missing?", dto.name(), dto.config().type());
            // TODO system notification
            return null;
        }
        addListeners(adapter, dto);
        return adapter;
    } catch (Exception e) {
        LOG.error("Couldn't create adapter <{}/{}>", dto.name(), dto.id(), e);
        return null;
    }
}
Also used : LookupDataAdapter(org.graylog2.plugin.lookup.LookupDataAdapter)

Example 29 with Notification

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

the class V20161125142400_EmailAlarmCallbackMigration method migrateStream.

private Optional<String> migrateStream(Stream stream) {
    final Map<String, Object> defaultConfig = this.getDefaultEmailAlarmCallbackConfig();
    LOG.debug("Creating email alarm callback for stream <" + stream.getId() + ">");
    final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackService.create(stream.getId(), CreateAlarmCallbackRequest.create(EmailAlarmCallback.class.getCanonicalName(), "Email Alert Notification", defaultConfig), "local:admin");
    try {
        final String callbackId = this.alarmCallbackService.save(alarmCallbackConfiguration);
        LOG.debug("Successfully created email alarm callback <" + callbackId + "> for stream <" + stream.getId() + ">.");
        return Optional.of(callbackId);
    } catch (ValidationException e) {
        LOG.error("Unable to create email alarm callback for stream <" + stream.getId() + ">: ", e);
    }
    return Optional.empty();
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)

Example 30 with Notification

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

the class ESVersionCheckPeriodical method doRun.

@Override
public void doRun() {
    if (versionOverride.isPresent()) {
        LOG.debug("Elasticsearch version is set manually. Not running check.");
        return;
    }
    final Optional<SearchVersion> probedVersion = this.versionProbe.probe(this.elasticsearchHosts);
    probedVersion.ifPresent(version -> {
        if (compatible(this.initialElasticsearchVersion, version)) {
            notificationService.fixed(Notification.Type.ES_VERSION_MISMATCH);
        } else {
            LOG.warn("Elasticsearch version currently running ({}) is incompatible with the one Graylog was started " + "with ({}) - a restart is required!", version, initialElasticsearchVersion);
            final Notification notification = notificationService.buildNow().addType(Notification.Type.ES_VERSION_MISMATCH).addSeverity(Notification.Severity.URGENT).addDetail("initial_version", initialElasticsearchVersion.toString()).addDetail("current_version", version.toString());
            notificationService.publishIfFirst(notification);
        }
    });
}
Also used : SearchVersion(org.graylog2.storage.SearchVersion) DetectedSearchVersion(org.graylog2.storage.DetectedSearchVersion) 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