use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.
the class NotificationManager method replaceNotification.
/**
* <p>replaceNotification</p>
*
* @param oldName a {@link java.lang.String} object.
* @param newNotice a {@link org.opennms.netmgt.config.notifications.Notification} object.
* @throws java.io.IOException if any.
* @throws java.lang.ClassNotFoundException if any.
*/
public synchronized void replaceNotification(final String oldName, final Notification newNotice) throws IOException, ClassNotFoundException {
// In order to preserve the order of the notices, we have to replace "in place".
Notification notice = getNotification(oldName);
if (notice != null) {
notice.setWriteable(newNotice.getWriteable());
notice.setName(newNotice.getName());
notice.setDescription(newNotice.getDescription().orElse(null));
notice.setUei(newNotice.getUei());
notice.setRule(newNotice.getRule());
notice.setDestinationPath(newNotice.getDestinationPath());
notice.setNoticeQueue(newNotice.getNoticeQueue().orElse(null));
notice.setTextMessage(newNotice.getTextMessage());
notice.setSubject(newNotice.getSubject().orElse(null));
notice.setNumericMessage(newNotice.getNumericMessage().orElse(null));
notice.setStatus(newNotice.getStatus());
notice.setVarbind(newNotice.getVarbind());
// Required to avoid NMS-5948
notice.getParameters().clear();
for (Parameter parameter : newNotice.getParameters()) {
Parameter newParam = new Parameter();
newParam.setName(parameter.getName());
newParam.setValue(parameter.getValue());
notice.addParameter(newParam);
}
saveCurrent();
} else
addNotification(newNotice);
}
use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.
the class NotificationManager method updateStatus.
/**
* Sets the status on an individual notification configuration and saves to xml.
*
* @param name
* The name of the notification.
* @param status
* The status (either "on" or "off").
* @throws java.io.IOException if any.
* @throws java.lang.ClassNotFoundException if any.
*/
public synchronized void updateStatus(final String name, final String status) throws IOException, ClassNotFoundException {
if ("on".equals(status) || "off".equals(status)) {
Notification notice = getNotification(name);
notice.setStatus(status);
saveCurrent();
} else
throw new IllegalArgumentException("Status must be on|off, not " + status);
}
use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.
the class NotificationManager method rebuildParameterMap.
/**
* <p>rebuildParameterMap</p>
*
* @param notifId a int.
* @param resolutionPrefix a {@link java.lang.String} object.
* @param skipNumericPrefix a boolean.
* @return a {@link java.util.Map} object.
* @throws java.lang.Exception if any.
*/
public Map<String, String> rebuildParameterMap(final int notifId, final String resolutionPrefix, final boolean skipNumericPrefix) throws Exception {
final Map<String, String> parmMap = new HashMap<String, String>();
Querier querier = new Querier(m_dataSource, "select notifications.*, service.* from notifications left outer join service on notifications.serviceID = service.serviceID where notifyId = ?") {
@Override
public void processRow(ResultSet rs) throws SQLException {
/*
* Note, getString on results is valid for any SQL data type except the new SQL types:
* Blog, Clob, Array, Struct, Ref
* of which we have none in this table so this row processor is using getString
* to correctly align with annotated types in the map.
*/
parmMap.put(NotificationManager.PARAM_TEXT_MSG, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("textMsg"));
if (skipNumericPrefix) {
parmMap.put(NotificationManager.PARAM_NUM_MSG, rs.getString("numericMsg"));
} else {
parmMap.put(NotificationManager.PARAM_NUM_MSG, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("numericMsg"));
}
parmMap.put(NotificationManager.PARAM_SUBJECT, expandNotifParms(resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId))) + rs.getString("subject"));
parmMap.put(NotificationManager.PARAM_NODE, rs.getString("nodeID"));
parmMap.put(NotificationManager.PARAM_INTERFACE, rs.getString("interfaceID"));
parmMap.put(NotificationManager.PARAM_SERVICE, rs.getString("serviceName"));
parmMap.put("noticeid", rs.getString("notifyID"));
parmMap.put("eventID", rs.getString("eventID"));
parmMap.put("eventUEI", rs.getString("eventUEI"));
Notification notification = null;
try {
notification = getNotification(rs.getObject("notifConfigName").toString());
} catch (IOException e) {
}
if (notification != null) {
addNotificationParams(parmMap, notification);
}
}
};
querier.execute(notifId);
return parmMap;
}
use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.
the class NotificationManager method getNotificationNames.
/**
* <p>getNotificationNames</p>
*
* @return a {@link java.util.List} object.
* @throws java.io.IOException if any.
*/
public List<String> getNotificationNames() throws IOException {
update();
List<String> notificationNames = new ArrayList<>();
for (Notification curNotif : m_notifications.getNotifications()) {
notificationNames.add(curNotif.getName());
}
return notificationNames;
}
use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.
the class NotificationWizardServlet method processRule.
private String processRule(final HttpServletRequest request, final HttpSession user) {
String ruleString = request.getParameter("newRule");
ruleString = toSingleQuote(ruleString);
ruleString = stripExtraWhite(ruleString);
ruleString = stripServices(ruleString);
ruleString = checkParens(ruleString);
final StringBuilder rule = new StringBuilder(ruleString);
final String[] services = request.getParameterValues("services");
if (services != null) {
rule.append(" & ").append(" (");
for (int i = 0; i < services.length; i++) {
rule.append("is").append(services[i]);
if (i < services.length - 1) {
rule.append(" | ");
}
}
rule.append(" )");
}
final String[] notServices = request.getParameterValues("notServices");
if (notServices != null) {
rule.append(" & ").append(" (");
for (int i = 0; i < notServices.length; i++) {
rule.append("!is").append(notServices[i]);
if (i < notServices.length - 1) {
rule.append(" & ");
}
}
rule.append(" )");
}
final Map<String, Object> params = new HashMap<String, Object>();
params.put("newRule", rule.toString());
if (services != null) {
params.put("services", services);
}
if (notServices != null) {
params.put("notServices", notServices);
}
// page to redirect to, either validate or skip validation
String redirectPage = request.getParameter("nextPage");
// now lets see if the rule is syntactically valid
try {
getFilterDao().validateRule(rule.toString());
} catch (final FilterParseException e) {
// page to redirect to if the rule is invalid
params.put("mode", "failed");
redirectPage = SOURCE_PAGE_RULE;
}
// save the rule if we are bypassing validation
if (redirectPage.equals(SOURCE_PAGE_PATH)) {
final Notification newNotice = (Notification) user.getAttribute("newNotice");
newNotice.setRule(rule.toString());
}
return redirectPage + makeQueryString(params);
}
Aggregations