expandNotifParms( resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId)) parmMap.put( NotificationManager.PARAM_NUM_MSG, expandNotifParms( resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId)) expandNotifParms( resolutionPrefix, Collections.singletonMap("noticeid", String.valueOf(notifId)) notification = getNotification(rs.getObject("notifConfigName").toString()); } catch (IOException e) { addNotificationParams(parmMap, notification);
// makes a factory with the built-in clean theme // themes are customizeable NotificationFactory factory = new NotificationFactory(ThemePackagePresets.cleanLight()); // factories build notifications using a theme, while managers handle how // how they appear on the screen // this manager just simple pops up the notification in the specified location // other managers do sliding, queues, etc. NotificationManager plain = new SimpleManager(Location.NORTHEAST); // creates a text notification; you can also have progress bar Notifications, // icon Notifications, Notifications that ask for user feedback, etc. TextNotification notification = factory.buildTextNotification("This is a title", "This is a subtitle"); notification.setCloseOnClick(true); // the notification will disappear after 2 seconds, or after you click it plain.addNotification(notification, Time.seconds(2));
/** * <p>saveCurrent</p> * * @throws java.io.IOException if any. * @throws java.lang.ClassNotFoundException if any. */ public synchronized void saveCurrent() throws IOException, ClassNotFoundException { m_notifications.setHeader(rebuildHeader()); // Marshal to a string first, then write the string to the file. This // way the original configuration // isn't lost if the XML from the marshal is hosed. final String xmlString = JaxbUtils.marshal(m_notifications); saveXML(xmlString); update(); }
/** * <p>getNotification</p> * * @param name a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.config.notifications.Notification} object. * @throws java.io.IOException if any. */ public Notification getNotification(final String name) throws IOException { update(); return getNotifications().get(name); }
/** * <p>removeNotification</p> * * @param name a {@link java.lang.String} object. * @throws java.io.IOException if any. * @throws java.lang.ClassNotFoundException if any. */ public synchronized void removeNotification(final String name) throws IOException, ClassNotFoundException { m_notifications.removeNotification(getNotification(name)); saveCurrent(); }
mapsToNotice = getNotificationManager().hasUei(event.getUei()); } catch (Throwable e) { LOG.error("Couldn't map uei {} to a notification entry, not scheduling notice.", event.getUei(), e); notifications = getNotificationManager().getNotifForEvent(event); } catch (Throwable e) { LOG.error("Couldn't get notification mapping for event {}, not scheduling notice.", event.getUei(), e); noticeId = getNotificationManager().getNoticeId(); } catch (Throwable e) { LOG.error("Failed to get a unique id # for notification, exiting this notification", e); getNotificationManager().insertNotice(noticeId, paramMap, queueID, notification); } catch (SQLException e) { LOG.error("Failed to enter notification into database, exiting this notification", e);
/** * */ protected Map<String, String> buildParameterMap(Notification notification, Event event, int noticeId) { Map<String, String> paramMap = new HashMap<String, String>(); NotificationManager.addNotificationParams(paramMap, notification); // expand the event parameters for the messages // call the notif expansion method before the event expansion because // event expansion will // throw away any expansion strings it doesn't recognize! paramMap.put("noticeid", Integer.toString(noticeId)); // Replace the %noticeid% param String textMessage = NotificationManager.expandNotifParms((nullSafeTextMsg(notification)), paramMap); String numericMessage = NotificationManager.expandNotifParms((nullSafeNumerMsg(notification, noticeId)), paramMap); String subjectLine = NotificationManager.expandNotifParms((nullSafeSubj(notification, noticeId)), paramMap); Map<String, Map<String, String>> decodeMap = getVarbindsDecodeMap(event.getUei()); nullSafeExpandedPut(NotificationManager.PARAM_TEXT_MSG, textMessage, event, paramMap, decodeMap); nullSafeExpandedPut(NotificationManager.PARAM_NUM_MSG, numericMessage, event, paramMap, decodeMap); nullSafeExpandedPut(NotificationManager.PARAM_SUBJECT, subjectLine, event, paramMap, decodeMap); paramMap.put(NotificationManager.PARAM_NODE, event.hasNodeid() ? String.valueOf(event.getNodeid()) : ""); paramMap.put(NotificationManager.PARAM_INTERFACE, event.getInterface()); paramMap.put(NotificationManager.PARAM_SERVICE, event.getService()); paramMap.put("eventID", String.valueOf(event.getDbid())); paramMap.put("eventUEI", event.getUei()); m_eventUtil.expandMapValues(paramMap, event); return Collections.unmodifiableMap(paramMap); }
Notification notice = getNotification(oldName); if (notice != null) { notice.setWriteable(newNotice.getWriteable()); notice.addParameter(newParam); saveCurrent(); addNotification(newNotice);
String expandResult = NotificationManager.expandNotifParms("%foo%", new TreeMap<String,String>()); assertEquals("%foo%", expandResult); expandResult = NotificationManager.expandNotifParms("%foo%", Collections.singletonMap("foo", "bar")); assertEquals("%foo%", expandResult); expandResult = NotificationManager.expandNotifParms("Notice #%noticeid% RESOLVED: ", Collections.singletonMap("noticeid", "999")); assertEquals("Notice #999 RESOLVED: ", expandResult); expandResult = NotificationManager.expandNotifParms("RESOLVED: ", Collections.singletonMap("noticeid", "999")); assertEquals("RESOLVED: ", expandResult); expandResult = NotificationManager.expandNotifParms("Notice %noticeid%: Disk threshold exceeded on %nodelabel%: %parm[all]%.", new TreeMap<String,String>()); assertEquals("Notice %noticeid%: Disk threshold exceeded on %nodelabel%: %parm[all]%.", expandResult); notifications = m_notificationManager.getNotifForEvent(null); assertNull(notifications); notifications = m_notificationManager.getNotifForEvent(bldr.getEvent()); assertNotNull(notifications); assertEquals(1, notifications.length); expandResult = NotificationManager.expandNotifParms("Notice #%noticeid%: Disk threshold exceeded on %nodelabel%: %parm[all]%.", paramMap); assertEquals("Notice #9999: Disk threshold exceeded on %nodelabel%: %parm[all]%.", expandResult);
getNotificationManager().getEvent(Integer.parseInt(parmMap.get("eventID")))); String queueID = getNotificationManager().getQueueForNotification(notifId); getNotificationManager().forEachUserNotification(notifId, ackNotifProcessor);
update(); List<Notification> notifList = new ArrayList<>(); boolean matchAll = getConfigManager().getNotificationMatch(); if (nodeInterfaceServiceValid(curNotif, event)) { boolean parmsmatched = getConfigManager().matchNotificationParameters(event, curNotif);
/** * <p>getNotifications</p> * * @return a {@link java.util.Map} object. * @throws java.io.IOException if any. */ public Map<String, Notification> getNotifications() throws IOException { update(); Map<String, Notification> newMap = new HashMap<String, Notification>(); for (final Notification notif : m_notifications.getNotifications()) { newMap.put(notif.getName(), notif); } return Collections.unmodifiableMap(newMap); }
boolean noticeSupressed = false; Notification[] notifications = null; mapsToNotice = getNotificationManager().hasUei(event.getUei()); notifications = getNotificationManager().getNotifForEvent(event);
@Before @Override public void setUp() throws Exception { super.setUp(); m_notif = m_notificationManager.getNotification("nodeDown"); MockNode node = m_network.getNode(1); Event nodeDownEvent = node.createDownEvent(); m_params = m_eventProcessor.buildParameterMap(m_notif, nodeDownEvent, 1); m_commands = new String[]{ "email" }; }
LOG.debug("Acknowledging event {} {}:{}:{}", curAck.getAcknowledge(), event.getNodeid(), event.getInterface(), event.getService()); Collection<Integer> notifIDs = getNotificationManager().acknowledgeNotice(event, curAck.getAcknowledge(), curAck.getMatches().toArray(new String[0])); processed = true; try { return; Collection<Integer> notifIDs = getNotificationManager().acknowledgeNoticeBasedOnAlarms(event); try {
m_notificationManager.forEachUserNotification(notifId.intValue(), rp);
@Test public void testRebuildParameterMap() throws Exception { MockInterface iface = m_network.getInterface(1, "192.168.1.1"); Date downDate = new Date(); anticipateNotificationsForGroup("interface 192.168.1.1 down.", "All services are down on interface 192.168.1.1", "InitialGroup", downDate, 0); //bring node down now Event event = iface.createDownEvent(downDate); m_eventMgr.sendEventToListeners(event); sleep(1000); Collection<Integer> notifIds = m_db.findNoticesForEvent(event); Notification[] notification = m_notificationManager.getNotifForEvent(event); int index = 0; for (Integer notifId : notifIds) { Map<String, String> originalMap = m_eventProcessor.buildParameterMap(notification[index], event, notifId.intValue()); Map<String, String> resolutionMap = new HashMap<String, String>(originalMap); resolutionMap.put(NotificationManager.PARAM_SUBJECT, "RESOLVED: "+resolutionMap.get(NotificationManager.PARAM_SUBJECT)); resolutionMap.put(NotificationManager.PARAM_TEXT_MSG, "RESOLVED: "+resolutionMap.get(NotificationManager.PARAM_TEXT_MSG)); resolutionMap.put(NotificationManager.PARAM_NUM_MSG, "RESOLVED: "+resolutionMap.get(NotificationManager.PARAM_NUM_MSG)); Map<String, String> rebuiltMap = m_notifd.getBroadcastEventProcessor().rebuildParameterMap(notifId.intValue(), "RESOLVED: ", m_notifd.getConfigManager().getConfiguration().getNumericSkipResolutionPrefix()); assertEquals(resolutionMap, rebuiltMap); index++; } }
/** * Trip a notification and see if the %noticeid% token gets expanded to a numeric * value in the subject and text message * * @author Jeff Gehlbach <jeffg@jeffg.org> */ @Test public void testExpandNoticeId_Bug1745() throws Exception { MockService svc = m_network.getService(1, "192.168.1.1", "ICMP"); Event event = MockEventUtil.createServiceEvent("Test", "uei.opennms.org/test/noticeIdExpansion", svc, null); // We need to know what noticeID to expect -- whatever the NotificationManager // gives us, the next notice to come out will have noticeID n+1. This isn't // foolproof, but it should work within the confines of JUnit as long as all // previous cases have torn down the mock Notifd. String antNID = Integer.toString(m_notificationManager.getNoticeId() + 1); Date testDate = new Date(); long finishedNotifs = anticipateNotificationsForGroup("notification '" + antNID + "'", "Notification '" + antNID + "'", "InitialGroup", testDate, 0); MockEventUtil.setEventTime(event, testDate); m_eventMgr.sendEventToListeners(event); verifyAnticipated(finishedNotifs, 1000); }
/** * 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); }
/** * <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; }