Search in sources :

Example 11 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class AbstractSlackCompatibleNotificationStrategy method buildMessage.

protected String buildMessage(List<Argument> args) {
    String subject = null;
    String body = null;
    for (Argument arg : args) {
        if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch())) {
            subject = arg.getValue();
        } else if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch())) {
            body = arg.getValue();
        }
    }
    final StringBuilder bldr = new StringBuilder();
    if ("".equals(subject) || "RESOLVED: ".equals(subject)) {
        subject = null;
    } else {
        bldr.append(decorateMessageSubject(subject));
    }
    if ("".equals(body) || "RESOLVED: ".equals(body)) {
        body = null;
    } else {
        bldr.append(decorateMessageBody(body));
    }
    return bldr.toString();
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument)

Example 12 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class BSFNotificationStrategyIT method canUseNodeInScript.

/**
 * Verifies that we can invoke a BSH script and that
 * the an instance of the appropriate OnmsNode object is
 * passed to the script.
 */
@Test
public void canUseNodeInScript() throws IOException {
    // Create a simple BSH script that verifies the node bean
    File notifyBsh = tempFolder.newFile("notify.bsh");
    FileUtils.write(notifyBsh, "results.put(\"status\", node.id == 1 ? \"OK\" : \"NOT_OK\");");
    List<Argument> arguments = new ArrayList<>();
    // Point to our script
    arguments.add(new Argument("file-name", null, notifyBsh.getAbsolutePath(), false));
    // Reference node 1
    arguments.add(new Argument(NotificationManager.PARAM_NODE, null, "1", false));
    // Should succeed
    assertEquals(0, bsfNotificationStrategy.send(arguments));
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 13 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class BSFNotificationStrategy method undeclareBeans.

private static void undeclareBeans(BSFNotificationStrategy obj) {
    undeclareBean("logger");
    undeclareBean("bsf_notif_strategy");
    undeclareBean("notif_params");
    undeclareBean("node_label");
    undeclareBean("foreign_source");
    undeclareBean("foreign_id");
    undeclareBean("node_assets");
    undeclareBean("node_categories");
    undeclareBean("node");
    for (Argument arg : obj.m_arguments) {
        if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch()))
            undeclareBean("text_message");
        if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch()))
            undeclareBean("numeric_message");
        if (NotificationManager.PARAM_NODE.equals(arg.getSwitch()))
            undeclareBean("node_id");
        if (NotificationManager.PARAM_INTERFACE.equals(arg.getSwitch()))
            undeclareBean("ip_addr");
        if (NotificationManager.PARAM_SERVICE.equals(arg.getSwitch()))
            undeclareBean("svc_name");
        if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch()))
            undeclareBean("subject");
        if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch()))
            undeclareBean("email");
        if (NotificationManager.PARAM_PAGER_EMAIL.equals(arg.getSwitch()))
            undeclareBean("pager_email");
        if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch()))
            undeclareBean("xmpp_address");
        if (NotificationManager.PARAM_TEXT_PAGER_PIN.equals(arg.getSwitch()))
            undeclareBean("text_pin");
        if (NotificationManager.PARAM_NUM_PAGER_PIN.equals(arg.getSwitch()))
            undeclareBean("numeric_pin");
        if (NotificationManager.PARAM_WORK_PHONE.equals(arg.getSwitch()))
            undeclareBean("work_phone");
        if (NotificationManager.PARAM_HOME_PHONE.equals(arg.getSwitch()))
            undeclareBean("home_phone");
        if (NotificationManager.PARAM_MOBILE_PHONE.equals(arg.getSwitch()))
            undeclareBean("mobile_phone");
        if (NotificationManager.PARAM_TUI_PIN.equals(arg.getSwitch()))
            undeclareBean("phone_pin");
        if (NotificationManager.PARAM_MICROBLOG_USERNAME.equals(arg.getSwitch()))
            undeclareBean("microblog_username");
    }
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument)

Example 14 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class HttpNotificationStrategy method getUrlAsPrefix.

private String getUrlAsPrefix() {
    String url = null;
    for (Argument arg : getArgsByPrefix("url")) {
        LOG.debug("Found url switch: {} with value: {}", arg.getSwitch(), arg.getValue());
        url = arg.getValue();
    }
    return url;
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument)

Example 15 with Argument

use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.

the class HttpNotificationStrategy method getNotificationValue.

private String getNotificationValue(final String notificationManagerParamString) {
    String message = "no notification text message defined for the \"" + notificationManagerParamString + "\" switch.";
    for (Iterator<Argument> it = m_arguments.iterator(); it.hasNext(); ) {
        Argument arg = it.next();
        if (arg.getSwitch().equals(notificationManagerParamString))
            message = arg.getValue();
    }
    LOG.debug("getNotificationValue: {}", message);
    return message;
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument)

Aggregations

Argument (org.opennms.netmgt.model.notifd.Argument)29 ArrayList (java.util.ArrayList)12 NotificationStrategy (org.opennms.netmgt.model.notifd.NotificationStrategy)8 Test (org.junit.Test)7 Ignore (org.junit.Ignore)3 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)3 JSONObject (org.json.simple.JSONObject)2 NodeDao (org.opennms.netmgt.dao.api.NodeDao)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Date (java.util.Date)1 NameValuePair (org.apache.http.NameValuePair)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 JavaMailer (org.opennms.javamail.JavaMailer)1 AsteriskOriginator (org.opennms.netmgt.asterisk.utils.AsteriskOriginator)1 MockNotification (org.opennms.netmgt.mock.MockNotification)1 NotificationAnticipator (org.opennms.netmgt.mock.NotificationAnticipator)1 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)1