Search in sources :

Example 56 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class V20161116172200_CreateDefaultStreamMigration method createDefaultStream.

private void createDefaultStream() {
    final IndexSet indexSet = indexSetRegistry.getDefault();
    final ObjectId id = new ObjectId(Stream.DEFAULT_STREAM_ID);
    final Map<String, Object> fields = ImmutableMap.<String, Object>builder().put(StreamImpl.FIELD_TITLE, "All messages").put(StreamImpl.FIELD_DESCRIPTION, "Stream containing all messages").put(StreamImpl.FIELD_DISABLED, false).put(StreamImpl.FIELD_CREATED_AT, DateTime.now(DateTimeZone.UTC)).put(StreamImpl.FIELD_CREATOR_USER_ID, "local:admin").put(StreamImpl.FIELD_MATCHING_TYPE, StreamImpl.MatchingType.DEFAULT.name()).put(StreamImpl.FIELD_REMOVE_MATCHES_FROM_DEFAULT_STREAM, false).put(StreamImpl.FIELD_DEFAULT_STREAM, true).put(StreamImpl.FIELD_INDEX_SET_ID, indexSet.getConfig().id()).build();
    final Stream stream = new StreamImpl(id, fields, Collections.emptyList(), Collections.emptySet(), indexSet);
    try {
        streamService.save(stream);
        LOG.info("Successfully created default stream: {}", stream.getTitle());
    } catch (ValidationException e) {
        LOG.error("Couldn't create default stream! This is a bug!");
    }
    clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) ObjectId(org.bson.types.ObjectId) StreamImpl(org.graylog2.streams.StreamImpl) Stream(org.graylog2.plugin.streams.Stream) IndexSet(org.graylog2.indexer.IndexSet)

Example 57 with ValidationException

use of org.graylog2.plugin.database.ValidationException 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), localAdminUser.getId());
    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 58 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class LdapGroupMappingMigration method doRun.

@Override
public void doRun() {
    final LdapSettings ldapSettings = ldapSettingsService.load();
    if (ldapSettings != null) {
        ldapSettings.setGroupMapping(ldapSettings.getGroupMapping());
        try {
            ldapSettingsService.save(ldapSettings);
            clusterConfigService.write(LdapGroupMappingMigrationState.create(true));
            log.info("Migrated LDAP group mapping format");
        } catch (ValidationException e) {
            log.error("Unable to save migrated LDAP settings!", e);
        }
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) LdapSettings(org.graylog2.shared.security.ldap.LdapSettings)

Example 59 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class LdapUserAuthenticator method syncFromLdapEntry.

@Nullable
@VisibleForTesting
User syncFromLdapEntry(LdapEntry userEntry, LdapSettings ldapSettings, String username) {
    User user = userService.load(username);
    // create new user object if necessary
    if (user == null) {
        user = userService.create();
    }
    // update user attributes from ldap entry
    updateFromLdap(user, userEntry, ldapSettings, username);
    try {
        userService.save(user);
    } catch (ValidationException e) {
        LOG.error("Cannot save user.", e);
        return null;
    }
    return user;
}
Also used : User(org.graylog2.plugin.database.users.User) ValidationException(org.graylog2.plugin.database.ValidationException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Nullable(javax.annotation.Nullable)

Example 60 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class StreamFaultManager method registerFailure.

public void registerFailure(final Stream stream) {
    final AtomicInteger faultCount = getFaultCount(stream);
    final int streamFaultCount = faultCount.incrementAndGet();
    streamMetrics.markStreamRuleTimeout(stream.getId());
    if (maxFaultCount > 0 && streamFaultCount >= maxFaultCount) {
        try {
            streamService.pause(stream);
            faultCount.set(0);
            streamMetrics.markStreamFaultsExceeded(stream.getId());
            LOG.error("Processing of stream <{}> failed to return within {}ms for more than {} times. Disabling stream.", stream.getId(), streamProcessingTimeout, maxFaultCount);
            triggerNotification(stream, streamFaultCount);
        } catch (ValidationException ex) {
            LOG.error("Unable to pause stream: {}", ex);
        }
    } else {
        LOG.warn("Processing of stream <{}> failed to return within {}ms.", stream.getId(), streamProcessingTimeout);
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)47 AuditEvent (org.graylog2.audit.jersey.AuditEvent)47 Timed (com.codahale.metrics.annotation.Timed)36 ValidationException (org.graylog2.plugin.database.ValidationException)32 ApiResponses (io.swagger.annotations.ApiResponses)29 Path (javax.ws.rs.Path)29 BadRequestException (javax.ws.rs.BadRequestException)25 PUT (javax.ws.rs.PUT)24 Produces (javax.ws.rs.Produces)23 Consumes (javax.ws.rs.Consumes)22 POST (javax.ws.rs.POST)21 URI (java.net.URI)18 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)13 Stream (org.graylog2.plugin.streams.Stream)12 User (org.graylog2.plugin.database.users.User)11 MessageInput (org.graylog2.plugin.inputs.MessageInput)11 NotFoundException (org.graylog2.database.NotFoundException)10 List (java.util.List)7 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)7 Dashboard (org.graylog2.dashboards.Dashboard)7