use of fish.payara.internal.notification.PayaraNotification in project Payara by payara.
the class AdminAuditService method recordAsadminCommand.
public void recordAsadminCommand(String command, ParameterMap parameters, Subject subject) {
if (enabled && !enabledNotifiers.isEmpty() && checkAuditLevel(command)) {
Set<Principal> principals = subject.getPrincipals();
String name = principals.iterator().next().getName();
PayaraNotification notification = notificationFactory.newBuilder().whitelist(enabledNotifiers.toArray(new String[0])).subject(AUDIT_MESSAGE).message(name + " issued command " + command + " with parameters " + parameters.toString()).build();
notificationEventBus.publish(notification);
}
}
use of fish.payara.internal.notification.PayaraNotification in project Payara by payara.
the class RequestTracingService method processTraceEnd.
private void processTraceEnd() {
Long thresholdValueInNanos = getThresholdValueInNanos();
long elapsedTime = requestEventStore.getElapsedTime();
long elapsedTimeInNanos = TimeUnit.NANOSECONDS.convert(elapsedTime, TimeUnit.MILLISECONDS);
if (elapsedTimeInNanos - thresholdValueInNanos > 0) {
// Determine whether to sample the request, if sampleRateFirstEnabled is false
if (!executionOptions.getSampleRateFirstEnabled()) {
if (!sampleFilter.sample()) {
requestEventStore.flushStore();
return;
}
}
// collect any trace exceeding the threshold
if (uncollectedTraces.size() >= 50) {
// avoid queue creating a memory leak by accumulating entries in case no consumer polls them
uncollectedTraces.poll();
}
RequestTrace requestTrace = requestEventStore.getTrace();
uncollectedTraces.add(requestTrace);
Runnable addTask = () -> {
RequestTrace removedTrace = requestTraceStore.addTrace(requestTrace);
// Store the trace in the historic trace store if it's enabled, avoiding recalculation
if (executionOptions.isHistoricTraceStoreEnabled()) {
historicRequestTraceStore.addTrace(requestTrace, removedTrace);
}
if (removedTrace != null) {
if (hazelcast.isEnabled()) {
eventBus.publish(EVENT_BUS_LISTENER_NAME, new ClusterMessage(RequestTracingEvents.STORE_FULL.toString()));
} else {
events.send(new EventListener.Event(RequestTracingEvents.STORE_FULL));
}
}
};
payaraExecutorService.submit(addTask);
Collection<String> enabledNotifiers = getExecutionOptions().getEnabledNotifiers();
PayaraNotification notification = notificationFactory.newBuilder().whitelist(enabledNotifiers.toArray(new String[0])).subject("Request execution time: " + elapsedTime + "(ms) exceeded the acceptable threshold").message(requestTrace.toString()).data(new RequestTracingNotificationData(requestTrace)).build();
notificationEventBus.publish(notification);
}
requestEventStore.flushStore();
}
use of fish.payara.internal.notification.PayaraNotification in project Payara by payara.
the class BaseHealthCheck method sendNotification.
/**
* Sends a notification to all notifier enabled with the healthcheck service.
* <p>
* @param checkResult information collected by the regarding health check service
* @param level Level of the message to send
* @param name Name of the checker executed
*/
public void sendNotification(String name, HealthCheckResult checkResult, Level level) {
String message = "{0}:{1}";
String subject = "Health Check notification with severity level: " + level.getName();
String messageFormatted = getMessageFormatted(new Object[] { name, getCumulativeMessages(checkResult.getEntries()) });
Collection<String> enabledNotifiers = healthCheckService.getEnabledNotifiers();
PayaraNotification notification = notificationFactory.newBuilder().whitelist(enabledNotifiers.toArray(new String[0])).subject(name).message(messageFormatted).data(new HealthCheckNotificationData(checkResult.getEntries())).eventType(level.getName()).build();
notificationEventBus.publish(notification);
if (healthCheckService.isHistoricalTraceEnabled()) {
healthCheckEventStore.addTrace(new Date().getTime(), level, subject, message, new Object[] { name, checkResult.getEntries().toString() });
}
}
use of fish.payara.internal.notification.PayaraNotification in project Payara by payara.
the class TestNotifier method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
PayaraNotificationBuilder builder = factory.newBuilder().eventType(EVENT_TYPE).subject(SUBJECT).message(MESSAGE);
if (all == null || !all) {
if (notifiers == null || notifiers.isEmpty()) {
report.setMessage("Must either specify all notifiers or a select list");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
builder = builder.whitelist(notifiers.toArray(new String[0]));
}
final PayaraNotification event = builder.build();
try {
topic.publish(event);
report.setMessage("SUCCESS");
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception ex) {
report.setMessage(ex.getMessage());
report.setFailureCause(ex);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
Aggregations