Search in sources :

Example 6 with JavaMailer

use of org.opennms.javamail.JavaMailer in project opennms by OpenNMS.

the class JavaMailNotificationStrategy method buildMessage.

/**
 * This method extracts the to, subject, and message text from the
 * parameters passed in the notification.
 *
 * @param arguments
 * @throws JavaMailerException
 */
private JavaMailer buildMessage(List<Argument> arguments) throws JavaMailerException {
    JavaMailer jm = new JavaMailer();
    for (int i = 0; i < arguments.size(); i++) {
        Argument arg = arguments.get(i);
        LOG.debug("Current arg switch: {} of {} is: {}", i, arguments.size(), arg.getSwitch());
        LOG.debug("Current arg  value: {} of {} is: {}", i, arguments.size(), arg.getValue());
        /*
             * Note: The recipient gets set by whichever of the two switches:
             * (PARAM_EMAIL or PARAM_PAGER_EMAIL) are specified last in the
             * notificationCommands.xml file
             * 
             * And the message body will get set to whichever is set last
             * (PARAM_NUM_MSG or PARAM_TEXT_MSG)
             */
        if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch())) {
            LOG.debug("Found: PARAM_EMAIL");
            jm.setTo(arg.getValue());
        } else if (NotificationManager.PARAM_PAGER_EMAIL.equals(arg.getSwitch())) {
            LOG.debug("Found: PARAM_PAGER_EMAIL");
            jm.setTo(arg.getValue());
        } else if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch())) {
            LOG.debug("Found: PARAM_SUBJECT");
            jm.setSubject(arg.getValue());
        } else if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch())) {
            LOG.debug("Found: PARAM_NUM_MSG");
            jm.setMessageText(arg.getValue());
        } else if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch())) {
            LOG.debug("Found: PARAM_TEXT_MSG");
            jm.setMessageText(arg.getValue());
        }
    }
    return jm;
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument) JavaMailer(org.opennms.javamail.JavaMailer)

Aggregations

JavaMailer (org.opennms.javamail.JavaMailer)6 JavaMailerException (org.opennms.javamail.JavaMailerException)4 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)2 PollStatus (org.opennms.netmgt.poller.PollStatus)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Properties (java.util.Properties)1 Folder (javax.mail.Folder)1 MessagingException (javax.mail.MessagingException)1 Store (javax.mail.Store)1 Argument (org.opennms.netmgt.model.notifd.Argument)1