use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.
the class AsteriskOriginateNotificationStrategy method buildOriginator.
private AsteriskOriginator buildOriginator(final List<Argument> arguments) throws AsteriskOriginatorException {
final AsteriskOriginator ao = new AsteriskOriginator();
for (final Argument arg : arguments) {
final String argSwitch = arg.getSwitch();
final String argValue = arg.getValue();
if (NotificationManager.PARAM_WORK_PHONE.equals(argSwitch)) {
LOG.debug("Found: PARAM_WORK_PHONE => {}", argValue);
ao.setLegAExtension(argValue);
} else if (NotificationManager.PARAM_HOME_PHONE.equals(argSwitch)) {
LOG.debug("Found: PARAM_HOME_PHONE => {}", argValue);
ao.setLegAExtension(argValue);
} else if (NotificationManager.PARAM_MOBILE_PHONE.equals(argSwitch)) {
LOG.debug("Found: PARAM_MOBILE_PHONE => {}", argValue);
ao.setLegAExtension(argValue);
} else if (NotificationManager.PARAM_SUBJECT.equals(argSwitch)) {
LOG.debug("Found: PARAM_SUBJECT => {}", argValue);
ao.setSubject(argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NOTIFY_SUBJECT, argValue);
} else if (NotificationManager.PARAM_TEXT_MSG.equals(argSwitch)) {
LOG.debug("Found: PARAM_TEXT_MSG => {}", argValue);
ao.setMessageText(argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NOTIFY_BODY, argValue);
} else if (NotificationManager.PARAM_TUI_PIN.equals(argSwitch)) {
LOG.debug("Found: PARAM_TUI_PIN => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_USER_PIN, argValue);
} else if (NotificationManager.PARAM_DESTINATION.equals(argSwitch)) {
LOG.debug("Found: PARAM_DESTINATION => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_USERNAME, argValue);
} else if (NotificationManager.PARAM_NODE.equals(argSwitch)) {
LOG.debug("Found: PARAM_NODE => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODEID, argValue);
try {
final NodeDao nodeDao = BeanUtils.getBean("notifdContext", "nodeDao", NodeDao.class);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODELABEL, nodeDao.get(argValue).getLabel());
} catch (final Throwable t) {
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_NODELABEL, null);
}
} else if (NotificationManager.PARAM_INTERFACE.equals(argSwitch)) {
LOG.debug("Found: PARAM_INTERFACE => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_INTERFACE, argValue);
} else if (NotificationManager.PARAM_SERVICE.equals(argSwitch)) {
LOG.debug("Found: PARAM_SERVICE => {}", argValue);
ao.setChannelVariable(BaseOnmsAgiScript.VAR_OPENNMS_SERVICE, argValue);
} else {
LOG.debug("Unconsumed arg: {} => {}", String.valueOf(argSwitch), String.valueOf(argValue));
}
}
return ao;
}
use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.
the class MockNotificationStrategy method send.
/* (non-Javadoc)
* @see org.opennms.netmgt.notifd.NotificationStrategy#send(java.util.List)
*/
@Override
public int send(List<Argument> arguments) {
MockUtil.println("Message sent with arguments:" + arguments);
MockNotification notification = new MockNotification();
Iterator<Argument> it = arguments.iterator();
while (it.hasNext()) {
Argument arg = it.next();
if (arg.getSwitch().equals(NotificationManager.PARAM_SUBJECT)) {
notification.setSubject(arg.getValue());
} else if (arg.getSwitch().equals(NotificationManager.PARAM_EMAIL)) {
notification.setEmail(arg.getValue());
} else if (arg.getSwitch().equals(NotificationManager.PARAM_TEXT_MSG)) {
notification.setTextMsg(arg.getValue());
}
}
notification.setExpectedTime(System.currentTimeMillis());
NotificationAnticipator anticipator = getAnticipator();
if (anticipator != null) {
anticipator.notificationReceived(notification);
} else {
throw new NullPointerException("anticipator is null");
}
return 0;
}
use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.
the class BSFNotificationStrategy method declareBeans.
private static void declareBeans(BSFNotificationStrategy obj) throws BSFException {
// Retrieve the parameters before accessing them
obj.retrieveParams();
Integer nodeId;
try {
nodeId = Integer.valueOf(obj.m_notifParams.get(NotificationManager.PARAM_NODE));
} catch (NumberFormatException nfe) {
nodeId = null;
}
OnmsNode node = null;
OnmsAssetRecord assets = null;
final List<String> categories = new ArrayList<>();
String nodeLabel = null;
String foreignSource = null;
String foreignId = null;
if (nodeId != null) {
final BeanFactoryReference bf = BeanUtils.getBeanFactory("notifdContext");
final NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
try {
// Redeclare the node id as final
final int theNodeId = nodeId;
node = transTemplate.execute(new TransactionCallback<OnmsNode>() {
@Override
public OnmsNode doInTransaction(final TransactionStatus status) {
final OnmsNode node = nodeDao.get(theNodeId);
// Retrieve the categories in the context of the transaction
if (node != null) {
for (OnmsCategory cat : node.getCategories()) {
categories.add(cat.getName());
}
}
return node;
}
});
if (node == null) {
LOG.error("Could not find a node with id: {}", theNodeId);
} else {
nodeLabel = node.getLabel();
assets = node.getAssetRecord();
foreignSource = node.getForeignSource();
foreignId = node.getForeignId();
}
} catch (final RuntimeException e) {
LOG.error("Error while retrieving node with id {}", nodeId, e);
}
}
s_bsfManager.declareBean("bsf_notif_strategy", obj, BSFNotificationStrategy.class);
s_bsfManager.declareBean("logger", LOG, Logger.class);
s_bsfManager.declareBean("notif_params", obj.m_notifParams, Map.class);
s_bsfManager.declareBean("node_label", nodeLabel, String.class);
s_bsfManager.declareBean("foreign_source", foreignSource, String.class);
s_bsfManager.declareBean("foreign_id", foreignId, String.class);
s_bsfManager.declareBean("node_assets", assets, OnmsAssetRecord.class);
s_bsfManager.declareBean("node_categories", categories, List.class);
s_bsfManager.declareBean("node", node, OnmsNode.class);
for (Argument arg : obj.m_arguments) {
if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch()))
s_bsfManager.declareBean("text_message", arg.getValue(), String.class);
if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch()))
s_bsfManager.declareBean("numeric_message", arg.getValue(), String.class);
if (NotificationManager.PARAM_NODE.equals(arg.getSwitch()))
s_bsfManager.declareBean("node_id", arg.getValue(), String.class);
if (NotificationManager.PARAM_INTERFACE.equals(arg.getSwitch()))
s_bsfManager.declareBean("ip_addr", arg.getValue(), String.class);
if (NotificationManager.PARAM_SERVICE.equals(arg.getSwitch()))
s_bsfManager.declareBean("svc_name", arg.getValue(), String.class);
if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch()))
s_bsfManager.declareBean("subject", arg.getValue(), String.class);
if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch()))
s_bsfManager.declareBean("email", arg.getValue(), String.class);
if (NotificationManager.PARAM_PAGER_EMAIL.equals(arg.getSwitch()))
s_bsfManager.declareBean("pager_email", arg.getValue(), String.class);
if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch()))
s_bsfManager.declareBean("xmpp_address", arg.getValue(), String.class);
if (NotificationManager.PARAM_TEXT_PAGER_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("text_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_NUM_PAGER_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("numeric_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_WORK_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("work_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_HOME_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("home_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_MOBILE_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("mobile_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_TUI_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("phone_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_MICROBLOG_USERNAME.equals(arg.getSwitch()))
s_bsfManager.declareBean("microblog_username", arg.getValue(), String.class);
}
}
use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.
the class HttpNotificationStrategy method getPostArguments.
private List<NameValuePair> getPostArguments() {
List<Argument> args = getArgsByPrefix("post-");
List<NameValuePair> retval = new ArrayList<>();
for (Argument arg : args) {
String argSwitch = arg.getSwitch().substring("post-".length());
if (arg.getValue() == null) {
arg.setValue("");
}
retval.add(new BasicNameValuePair(argSwitch, getValue(arg.getValue())));
}
return retval;
}
use of org.opennms.netmgt.model.notifd.Argument in project opennms by OpenNMS.
the class XMPPNotificationStrategy method send.
/*
* (non-Javadoc)
*
* @see org.opennms.netmgt.notifd.NotificationStrategy#send(java.util.List)
*/
/**
* {@inheritDoc}
*/
@Override
public int send(List<Argument> arguments) {
try {
String[] parsedArgs = this.parseArguments(arguments);
if (parsedArgs[XMPP_TO] == null || "".equals(parsedArgs[XMPP_TO])) {
final StringBuilder argumentString = new StringBuilder();
boolean first = true;
for (Argument argument : arguments) {
if (!first)
argumentString.append(", ");
first = false;
argumentString.append(argument == null ? "[null]" : "\"" + argument.toString() + "\"");
}
LOG.warn("Blank XMPP address on notification: {}", argumentString);
return 1;
}
XMPPNotificationManager xmppManager = XMPPNotificationManager.getInstance();
xmppManager.sendMessage(parsedArgs[XMPP_TO], parsedArgs[XMPP_MESSAGE]);
} catch (Throwable e) {
LOG.error(e.getMessage());
return 1;
}
return 0;
}
Aggregations