Search in sources :

Example 6 with Notification

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

the class VersionCheckThread method doRun.

@Override
public void doRun() {
    final Request request = new Request.Builder().addHeader(HttpHeaders.USER_AGENT, USER_AGENT).get().url(versionCheckUri.toString()).build();
    try (final Response response = httpClient.newCall(request).execute()) {
        if (response.isSuccessful()) {
            final VersionCheckResponse versionCheckResponse = objectMapper.readValue(response.body().byteStream(), VersionCheckResponse.class);
            final VersionResponse version = versionCheckResponse.version;
            final com.github.zafarkhaja.semver.Version reportedVersion = com.github.zafarkhaja.semver.Version.forIntegers(version.major, version.minor, version.patch);
            LOG.debug("Version check reports current version: " + versionCheckResponse);
            if (reportedVersion.greaterThan(ServerVersion.VERSION.getVersion())) {
                LOG.debug("Reported version is higher than ours ({}). Writing notification.", ServerVersion.VERSION);
                Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.NORMAL).addType(Notification.Type.OUTDATED_VERSION).addDetail("current_version", versionCheckResponse.toString());
                notificationService.publishIfFirst(notification);
            } else {
                LOG.debug("Reported version is not higher than ours ({}).", ServerVersion.VERSION);
                notificationService.fixed(Notification.Type.OUTDATED_VERSION);
            }
        } else {
            LOG.error("Version check unsuccessful (response code {}).", response.code());
        }
    } catch (IOException e) {
        LOG.error("Couldn't perform version check", e);
    }
}
Also used : VersionResponse(org.graylog2.versioncheck.VersionResponse) VersionCheckResponse(org.graylog2.versioncheck.VersionCheckResponse) Response(okhttp3.Response) VersionCheckResponse(org.graylog2.versioncheck.VersionCheckResponse) VersionResponse(org.graylog2.versioncheck.VersionResponse) Request(okhttp3.Request) IOException(java.io.IOException) Notification(org.graylog2.notifications.Notification)

Example 7 with Notification

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

the class InputStateListener method inputStateChanged.

@Subscribe
public void inputStateChanged(IOStateChangedEvent<MessageInput> event) {
    final IOState<MessageInput> state = event.changedState();
    final MessageInput input = state.getStoppable();
    switch(event.newState()) {
        case FAILED:
            activityWriter.write(new Activity(state.getDetailedMessage(), InputRegistry.class));
            Notification notification = notificationService.buildNow();
            notification.addType(Notification.Type.INPUT_FAILED_TO_START).addSeverity(Notification.Severity.NORMAL);
            notification.addNode(serverStatus.getNodeId().toString());
            notification.addDetail("input_id", input.getId());
            notification.addDetail("reason", state.getDetailedMessage());
            notificationService.publishIfFirst(notification);
            break;
        case RUNNING:
            notificationService.fixed(Notification.Type.NO_INPUT_RUNNING);
        // fall through
        default:
            final String msg = "Input [" + input.getName() + "/" + input.getId() + "] is now " + event.newState().toString();
            activityWriter.write(new Activity(msg, InputStateListener.class));
            break;
    }
    LOG.debug("Input State of [{}/{}] changed: {} -> {}", input.getTitle(), input.getId(), event.oldState(), event.newState());
    LOG.info("Input [{}/{}] is now {}", input.getName(), input.getId(), event.newState());
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) Activity(org.graylog2.shared.system.activities.Activity) InputRegistry(org.graylog2.shared.inputs.InputRegistry) Notification(org.graylog2.notifications.Notification) Subscribe(com.google.common.eventbus.Subscribe)

Example 8 with Notification

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

the class FormattedEmailAlertSender method sendEmails.

@Override
public void sendEmails(Stream stream, EmailRecipients recipients, AlertCondition.CheckResult checkResult, List<Message> backlog) throws TransportConfigurationException, EmailException {
    if (!configuration.isEnabled()) {
        throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
    }
    if (recipients == null || recipients.isEmpty()) {
        throw new RuntimeException("Cannot send emails: empty recipient list.");
    }
    final Set<String> recipientsSet = recipients.getEmailRecipients();
    if (recipientsSet.size() == 0) {
        final Notification notification = notificationService.buildNow().addNode(nodeId.toString()).addType(Notification.Type.GENERIC).addSeverity(Notification.Severity.NORMAL).addDetail("title", "Stream \"" + stream.getTitle() + "\" is alerted, but no recipients have been defined!").addDetail("description", "To fix this, go to the alerting configuration of the stream and add at least one alert recipient.");
        notificationService.publishIfFirst(notification);
    }
    for (String email : recipientsSet) {
        sendEmail(email, stream, checkResult, backlog);
    }
}
Also used : TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) Notification(org.graylog2.notifications.Notification)

Example 9 with Notification

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

the class UrlWhitelistNotificationService method publishWhitelistFailure.

/**
 * Publish a system notification indicating that there was an attempt to access a URL which is not whitelisted.
 *
 * <p>This method is synchronized to reduce the chance of emitting multiple notifications at the same time</p>
 *
 * @param description The description of the notification.
 */
public synchronized void publishWhitelistFailure(String description) {
    final Notification notification = notificationService.buildNow().addType(Notification.Type.GENERIC).addSeverity(Notification.Severity.NORMAL).addDetail("title", "URL not whitelisted.").addDetail("description", description);
    notificationService.publishIfFirst(notification);
}
Also used : Notification(org.graylog2.notifications.Notification)

Example 10 with Notification

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

the class LegacyAlarmCallbackEventNotification method execute.

@Override
public void execute(EventNotificationContext ctx) throws PermanentEventNotificationException {
    final LegacyAlarmCallbackEventNotificationConfig config = (LegacyAlarmCallbackEventNotificationConfig) ctx.notificationConfig();
    final ImmutableList<MessageSummary> messagesForEvent = notificationCallbackService.getBacklogForEvent(ctx);
    final Optional<EventDefinitionDto> optionalEventDefinition = ctx.eventDefinition();
    if (!optionalEventDefinition.isPresent()) {
        final String msg = String.format(Locale.ROOT, "Unable to find definition for event <%s>", ctx.event().id());
        LOG.error(msg);
        throw new PermanentEventNotificationException(msg);
    }
    try {
        alarmCallbackSender.send(config, optionalEventDefinition.get(), ctx.event(), messagesForEvent);
    } catch (Exception e) {
        // TODO: Is there a case where we want to retry? (and are able to detect when to do it)
        throw new PermanentEventNotificationException("Couldn't send legacy notification - legacy notifications cannot be retried!", e);
    }
}
Also used : EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) PermanentEventNotificationException(org.graylog.events.notifications.PermanentEventNotificationException) MessageSummary(org.graylog2.plugin.MessageSummary) PermanentEventNotificationException(org.graylog.events.notifications.PermanentEventNotificationException)

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