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