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.");
}
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;
}
}
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;
}
}
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();
}
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);
}
});
}
Aggregations