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();
}
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));
}
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");
}
}
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;
}
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;
}
Aggregations