Search in sources :

Example 1 with BlockingQueueHandler

use of fish.payara.nucleus.notification.BlockingQueueHandler in project Payara by payara.

the class TestLogNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    LogNotifierConfiguration logConfig = config.getExtensionByType(LogNotifierConfiguration.class);
    if (useSeparateLogFile == null) {
        useSeparateLogFile = Boolean.parseBoolean(logConfig.getUseSeparateLogFile());
    }
    // prepare log message
    LogNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    LogNotifierConfigurationExecutionOptions options = new LogNotifierConfigurationExecutionOptions();
    options.setUseSeparateLogFile(useSeparateLogFile);
    // set up logger to store result
    LogNotifierService service = new LogNotifierService();
    Logger logger = Logger.getLogger(LogNotifierService.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    service.handleNotification(event);
    logger.setLevel(oldLevel);
    LogRecord message = bqh.poll();
    logger.removeHandler(bqh);
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestLogNotifier.class.getCanonicalName()).log(Level.SEVERE, "Failed to send Log message");
        actionReport.setMessage("Failed to send Log message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        ;
        actionReport.setMessage(message.getMessage());
        if (message.getLevel() == Level.FINE) {
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) Config(com.sun.enterprise.config.serverbeans.Config) Level(java.util.logging.Level) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Example 2 with BlockingQueueHandler

use of fish.payara.nucleus.notification.BlockingQueueHandler in project Payara by payara.

the class TestEventbusNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    EventbusNotifierConfiguration eventbusConfig = config.getExtensionByType(EventbusNotifierConfiguration.class);
    if (topicName == null) {
        topicName = eventbusConfig.getTopicName();
    }
    // prepare eventbus message
    EventbusNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    EventbusMessageImpl mesg = new EventbusMessageImpl(event, event.getSubject(), event.getMessage());
    EventbusNotifierConfigurationExecutionOptions options = new EventbusNotifierConfigurationExecutionOptions();
    options.setTopicName(topicName);
    // set up logger to store result
    Logger logger = Logger.getLogger(EventbusNotifierService.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    if (eventbus.publish(options.getTopicName(), new ClusterMessage<>(mesg))) {
        actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } else {
        actionReport.setMessage("Error sending message. Is Hazelcast enabled?");
        Logger.getGlobal().log(Level.SEVERE, "Error sending message. Is Hazelcast enabled?");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Example 3 with BlockingQueueHandler

use of fish.payara.nucleus.notification.BlockingQueueHandler in project Payara by payara.

the class TestHipchatNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    HipchatNotifierConfiguration hipchatConfig = config.getExtensionByType(HipchatNotifierConfiguration.class);
    if (roomName == null) {
        roomName = hipchatConfig.getRoomName();
    }
    if (token == null) {
        token = hipchatConfig.getToken();
    }
    // prepare hipchat message
    HipchatNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    HipchatMessageQueue queue = new HipchatMessageQueue();
    queue.addMessage(new HipchatMessage(event, event.getSubject(), event.getMessage()));
    HipchatNotifierConfigurationExecutionOptions options = new HipchatNotifierConfigurationExecutionOptions();
    options.setRoomName(roomName);
    options.setToken(token);
    HipchatNotificationRunnable notifierRun = new HipchatNotificationRunnable(queue, options);
    // set up logger to store result
    Logger logger = Logger.getLogger(HipchatNotificationRunnable.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    // send message, this occurs in its own thread
    Thread notifierThread = new Thread(notifierRun, "test-hipchat-notifier-thread");
    notifierThread.start();
    try {
        notifierThread.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(TestHipchatNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        logger.setLevel(oldLevel);
    }
    LogRecord message = bqh.poll();
    logger.removeHandler(bqh);
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestHipchatNotifier.class.getName()).log(Level.SEVERE, "Failed to send HipChat message");
        actionReport.setMessage("Failed to send HipChat message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        actionReport.setMessage(message.getMessage());
        if (message.getLevel() == Level.FINE) {
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) Level(java.util.logging.Level)

Example 4 with BlockingQueueHandler

use of fish.payara.nucleus.notification.BlockingQueueHandler in project Payara by payara.

the class TestNewRelicNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    NewRelicNotifierConfiguration newRelicConfig = config.getExtensionByType(NewRelicNotifierConfiguration.class);
    if (key == null) {
        key = newRelicConfig.getKey();
    }
    if (accountId == null) {
        accountId = newRelicConfig.getAccountId();
    }
    // prepare NewRelic message
    NewRelicNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    event.setEventType(SUBJECT);
    NewRelicEventMessageQueue queue = new NewRelicEventMessageQueue();
    queue.addMessage(new NewRelicEventMessage(event, event.getSubject(), event.getMessage()));
    NewRelicNotifierConfigurationExecutionOptions options = new NewRelicNotifierConfigurationExecutionOptions();
    options.setKey(key);
    options.setAccountId(accountId);
    NewRelicNotificationRunnable notifierRun = new NewRelicNotificationRunnable(queue, options);
    // set up logger to store result
    Logger logger = Logger.getLogger(NewRelicNotificationRunnable.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler();
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    // send message, this occurs in its own thread
    Thread notifierThread = new Thread(notifierRun, "test-newrelic-notifier-thread");
    notifierThread.start();
    try {
        notifierThread.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(TestNewRelicNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        logger.setLevel(oldLevel);
    }
    LogRecord message = bqh.poll();
    logger.removeHandler(bqh);
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestNewRelicNotifier.class.getName()).log(Level.SEVERE, "Failed to send New Relic message");
        actionReport.setMessage("Failed to send New Relic message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        actionReport.setMessage(message.getMessage());
        if (message.getLevel() == Level.FINE) {
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) Level(java.util.logging.Level)

Example 5 with BlockingQueueHandler

use of fish.payara.nucleus.notification.BlockingQueueHandler in project Payara by payara.

the class TestSnmpNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    SnmpNotifierConfiguration snmpConfig = config.getExtensionByType(SnmpNotifierConfiguration.class);
    if (community == null) {
        community = snmpConfig.getCommunity();
    }
    if (oid == null) {
        oid = snmpConfig.getOid();
    }
    if (version == null) {
        version = snmpConfig.getVersion();
    }
    if (hostName == null) {
        hostName = snmpConfig.getHost();
    }
    if (port == null) {
        port = snmpConfig.hashCode();
    }
    // prepare SNMP message
    SnmpNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    SnmpMessageQueue queue = new SnmpMessageQueue();
    queue.addMessage(new SnmpMessage(event, event.getSubject(), event.getMessage()));
    SnmpNotifierConfigurationExecutionOptions options = new SnmpNotifierConfigurationExecutionOptions();
    options.setCommunity(community);
    options.setOid(oid);
    options.setVersion(version);
    options.setHost(hostName);
    options.setPort(port);
    SnmpNotificationRunnable notifierRun = null;
    try {
        TransportMapping transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        CommunityTarget cTarget = new CommunityTarget();
        cTarget.setCommunity(new OctetString(options.getCommunity()));
        int snmpVersion = SnmpNotifierService.decideOnSnmpVersion(options.getVersion());
        cTarget.setVersion(snmpVersion);
        cTarget.setAddress(new UdpAddress(options.getHost() + SnmpNotifierService.ADDRESS_SEPARATOR + options.getPort()));
        notifierRun = new SnmpNotificationRunnable(queue, options, snmp, cTarget, snmpVersion);
    } catch (IOException e) {
        Logger.getLogger(TestSnmpNotifier.class.getCanonicalName()).log(Level.SEVERE, "Error occurred while creating UDP transport", e);
        actionReport.setMessage("Error occurred while creating UDP transport");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } catch (InvalidSnmpVersion invalidSnmpVersion) {
        Logger.getLogger(TestSnmpNotifier.class.getCanonicalName()).log(Level.SEVERE, "Error occurred while configuring SNMP version: " + invalidSnmpVersion.getMessage());
        actionReport.setMessage("Error occurred while configuring SNMP version: " + invalidSnmpVersion.getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    // set up logger to store result
    Logger logger = Logger.getLogger(SnmpNotificationRunnable.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    // send message, this occurs in its own thread
    Thread notifierThread = new Thread(notifierRun, "test-snmp-notifier-thread");
    notifierThread.start();
    try {
        notifierThread.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(TestSnmpNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        logger.setLevel(oldLevel);
    }
    LogRecord message = bqh.poll();
    bqh.clear();
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestSnmpNotifier.class.getName()).log(Level.SEVERE, "Failed to send SNMP message");
        actionReport.setMessage("Failed to send SNMP message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        actionReport.setMessage(message.getMessage());
        if (message.getLevel() == Level.FINE) {
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Config(com.sun.enterprise.config.serverbeans.Config) TransportMapping(org.snmp4j.TransportMapping) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) RestEndpoint(org.glassfish.api.admin.RestEndpoint) InvalidSnmpVersion(fish.payara.notification.snmp.exception.InvalidSnmpVersion) BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) Snmp(org.snmp4j.Snmp) Level(java.util.logging.Level) CommunityTarget(org.snmp4j.CommunityTarget)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)10 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Logger (java.util.logging.Logger)10 ActionReport (org.glassfish.api.ActionReport)10 Level (java.util.logging.Level)9 LogRecord (java.util.logging.LogRecord)9 IOException (java.io.IOException)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 InvalidSnmpVersion (fish.payara.notification.snmp.exception.InvalidSnmpVersion)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 JMSException (javax.jms.JMSException)1 Session (javax.mail.Session)1 RestEndpoint (org.glassfish.api.admin.RestEndpoint)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)1 XMPPTCPConnectionConfiguration (org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)1 CommunityTarget (org.snmp4j.CommunityTarget)1