Search in sources :

Example 1 with PayaraNotificationBuilder

use of fish.payara.internal.notification.PayaraNotificationBuilder in project Payara by payara.

the class JMXMonitoringFormatter method sendNotification.

/**
 * Sends a notification to all notifiers enabled with the JMX monitoring
 * service
 * <p>
 * The subject of the notification will be {@code MBean Attributes:}
 *
 * @since 4.1.2.174
 * @param level Log level to notification at
 * @param message The message to send
 * @param parameters An array of the objects that the notification is about
 * i.e. the Mbeans being monitored
 */
private void sendNotification(Level level, String message, Object[] parameters) {
    PayaraNotificationBuilder notification = notificationFactory.newBuilder().whitelist(enabledNotifiers.toArray(new String[0])).subject(LOGMESSAGE_PREFIX + message);
    if (parameters != null && parameters.length > 0) {
        notification = notification.message(MessageFormat.format(message, parameters));
    }
    notificationEventBus.publish(notification.build());
}
Also used : PayaraNotificationBuilder(fish.payara.internal.notification.PayaraNotificationBuilder)

Example 2 with PayaraNotificationBuilder

use of fish.payara.internal.notification.PayaraNotificationBuilder 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);
    }
}
Also used : PayaraNotificationBuilder(fish.payara.internal.notification.PayaraNotificationBuilder) PayaraNotification(fish.payara.internal.notification.PayaraNotification) ActionReport(org.glassfish.api.ActionReport)

Aggregations

PayaraNotificationBuilder (fish.payara.internal.notification.PayaraNotificationBuilder)2 PayaraNotification (fish.payara.internal.notification.PayaraNotification)1 ActionReport (org.glassfish.api.ActionReport)1