/** * <p>pathHasTarget</p> * * @param path a {@link org.opennms.netmgt.config.destinationPaths.Path} object. * @param target a {@link java.lang.String} object. * @return a boolean. * @throws java.io.IOException if any. */ public boolean pathHasTarget(Path path, String target) throws IOException { update(); for (Target curTarget : path.getTargets()) { if (curTarget.getName().equals(target)) return true; } // default false value if target isn't found return false; }
/** * <p>getTargetList</p> * * @param index a int. * @param path a {@link org.opennms.netmgt.config.destinationPaths.Path} object. * @return an array of {@link org.opennms.netmgt.config.destinationPaths.Target} objects. * @throws java.io.IOException if any. */ public Target[] getTargetList(int index, Path path) throws IOException { update(); Target[] targets = null; // index of -1 indicates the initial targets, any other index means to // get // the targets from the Escalate object at that index if (index == -1) { targets = path.getTargets().toArray(new Target[0]); } else { targets = path.getEscalates().get(index).getTargets().toArray(new Target[0]); } return targets; }
String interval = (targets[i].getInterval().orElse(Target.DEFAULT_INTERVAL)); String targetName = targets[i].getName(); String autoNotify = null; if (targets[i].getAutoNotify().isPresent()) { autoNotify = targets[i].getAutoNotify().get(); if(autoNotify.equalsIgnoreCase("on")) { autoNotify = "Y"; tasks = makeGroupTasks(startTime, params, noticeId, targetName, targets[i].getCommands().toArray(new String[0]), targetSiblings, autoNotify, TimeConverter.convertToMillis(interval)); } else if (getUserManager().hasOnCallRole(targetName)) { tasks = makeRoleTasks(startTime, params, noticeId, targetName, targets[i].getCommands().toArray(new String[0]), targetSiblings, autoNotify, TimeConverter.convertToMillis(interval)); } else if (getUserManager().hasUser(targetName)) { NotificationTask[] userTasks = { makeUserTask(startTime, params, noticeId, targetName, targets[i].getCommands().toArray(new String[0]), targetSiblings, autoNotify) }; tasks = userTasks; } else if (targetName.indexOf('@') > -1) {
return; final String initialDelay = path.getInitialDelay().orElse(Path.DEFAULT_INITIAL_DELAY); Target[] targets = path.getTargets().toArray(new Target[0]); Escalate[] escalations = path.getEscalates().toArray(new Escalate[0]);
protected long computeInterval() throws IOException { final String interval = m_destinationPathManager.getPath("Intervals").getTargets().get(0).getInterval().orElse(Target.DEFAULT_INTERVAL); return TimeConverter.convertToMillis(interval); }
/** * <p>getTargetCommands</p> * * @param path a {@link org.opennms.netmgt.config.destinationPaths.Path} object. * @param index a int. * @param target a {@link java.lang.String} object. * @return a {@link java.util.Collection} object. * @throws java.io.IOException if any. */ public Collection<String> getTargetCommands(Path path, int index, String target) throws IOException { update(); Target[] targets = getTargetList(index, path); for (int i = 0; i < targets.length; i++) { if (targets[i].getName().equals(target)) return targets[i].getCommands(); } // default null value if target isn't found in Path return null; }
/** * */ private void processEscalations(Escalate[] escalations, List<NotificationTask> targetSiblings, NoticeQueue noticeQueue, long startTime, Map<String, String> params, int noticeId) throws IOException { for (int i = 0; i < escalations.length; i++) { Target[] targets = escalations[i].getTargets().toArray(new Target[0]); startTime += TimeConverter.convertToMillis(escalations[i].getDelay()); processTargets(targets, targetSiblings, noticeQueue, startTime, params, noticeId); } }
/** * <p>saveCurrent</p> * * @throws java.io.IOException if any. */ public synchronized void saveCurrent() throws IOException { allPaths.clearPaths(); for (Path path : m_destinationPaths.values()) { allPaths.addPath(path); } allPaths.setHeader(rebuildHeader()); // Marshal to a string first, then write the string to the file. This // way the original config // isn't lost if the XML from the marshal is hosed. StringWriter stringWriter = new StringWriter(); JaxbUtils.marshal(allPaths, stringWriter); String writerString = stringWriter.toString(); saveXML(writerString); /* * TODO: what do do about this? Should this be here? * Appears that everything is handled through the update * method when a member of field is requested. * * Delete after all Notifd tests are passing. */ //reload(); }
/** * Detemines the number of users assigned to a list of Target and Escalate * lists. Group names may be specified in these objects and the users will * have to be extracted from those groups * * @param targets * the list of Target objects * @param escalations * the list of Escalate objects * @return the total # of users assigned in each Target and Escalate * objecst. */ private int getUserCount(Target[] targets, Escalate[] escalations) throws IOException { int totalUsers = 0; for (int i = 0; i < targets.length; i++) { totalUsers += getUsersInTarget(targets[i]); } for (int j = 0; j < escalations.length; j++) { Target[] escalationTargets = escalations[j].getTargets().toArray(new Target[0]); for (int k = 0; k < escalationTargets.length; k++) { totalUsers += getUsersInTarget(escalationTargets[k]); } } return totalUsers; }
/** * */ private int getUsersInTarget(Target target) throws IOException { int count = 0; String targetName = target.getName(); if (getGroupManager().hasGroup(targetName)) { count = getGroupManager().getGroup(targetName).getUsers().size(); } else if (getUserManager().hasOnCallRole(targetName)) { count = getUserManager().countUsersWithRole(targetName); } else if (getUserManager().hasUser(targetName)) { count = 1; } else if (targetName.indexOf('@') > -1) { count = 1; } return count; }
@Test public void testMockNotificationInitialDelay() throws Exception { m_destinationPathManager.getPath("NoEscalate").setInitialDelay("1800ms"); MockNode node = m_network.getNode(1); Date downDate = new Date(new Date().getTime()+1800); long finished = anticipateNotificationsForGroup("node 1 down.", "All services are down on node 1.", "InitialGroup", downDate, 0); m_eventMgr.sendEventToListeners(node.createDownEvent(downDate)); verifyAnticipated(finished, 3000); }
/** * Removes a Path from the xml file. * * @param path * the path to remove * @exception IOException * @throws java.io.IOException if any. */ public synchronized void removePath(Path path) throws IOException { m_destinationPaths.remove(path.getName()); saveCurrent(); }
/** * */ private Header rebuildHeader() { Header header = oldHeader; header.setCreated(EventConstants.formatToString(new Date())); return header; }
/** * <p>parseXML</p> * * @param stream a {@link java.io.InputStream} object. * @throws IOException */ protected void parseXML(final InputStream stream) throws IOException { try (final InputStreamReader isr = new InputStreamReader(stream)) { allPaths = JaxbUtils.unmarshal(DestinationPaths.class, isr); oldHeader = allPaths.getHeader(); initializeDestinationPaths(); } }
@Test public void testManualAcknowledge1() throws Exception { m_destinationPathManager.getPath("NoEscalate").setInitialDelay("2000ms"); MockNode node = m_network.getNode(1); Event e = node.createDownEvent(); m_eventMgr.sendEventToListeners(e); m_db.acknowledgeNoticesForEvent(e); verifyAnticipated(0, 0, 7000); }
/** * <p>addPath</p> * * @param newPath a {@link org.opennms.netmgt.config.destinationPaths.Path} object. * @throws java.io.IOException if any. */ public synchronized void addPath(Path newPath) throws IOException { m_destinationPaths.put(newPath.getName(), newPath); saveCurrent(); }
@Test public void testAutoAcknowledge1() throws Exception { m_destinationPathManager.getPath("NoEscalate").setInitialDelay("2000ms"); MockNode node = m_network.getNode(1); Event downEvent = node.createDownEvent(); Tticket tticket = new Tticket(); tticket.setContent("777"); tticket.setState("1"); downEvent.setTticket(tticket); m_eventMgr.sendEventToListeners(downEvent); sleep(1000); Date date = new Date(); Event upEvent = node.createUpEvent(date); long endTime = anticipateNotificationsForGroup("node 1 up.", "The node which was previously down is now up.", "UpGroup", date, 0); m_eventMgr.sendEventToListeners(upEvent); verifyAnticipated(endTime, 1000, 5000); }