Search in sources :

Example 21 with Notification

use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.

the class BroadcastEventProcessorIT method testVarbindsdecodeNMS7598.

/**
 * Test Varbindsdecode replacement on notifications.
 *
 * @author Alejandro Galue <agalue@opennms.org>
 */
@Test
public void testVarbindsdecodeNMS7598() throws Exception {
    EventBuilder bldr = new EventBuilder("uei.opennms.org/vendor/Cisco/traps/cHsrpStateChange", "testVarbindsdecodeNMS7598");
    bldr.setNodeid(0);
    bldr.setInterface(addr("0.0.0.0"));
    bldr.addParam("cHsrpGrpStandbyState", "3");
    String templateText = "Notice #%noticeid%: new state is %parm[#1]%";
    String expectedText = "Notice #1001: new state is listen(3)";
    Notification n = new Notification();
    n.setName("cHsrpGrpStandbyState");
    n.setSubject(templateText);
    n.setNumericMessage(templateText);
    n.setTextMessage(templateText);
    Map<String, String> params = m_eventProcessor.buildParameterMap(n, bldr.getEvent(), 1001);
    Assert.assertEquals(expectedText, params.get(NotificationManager.PARAM_NUM_MSG));
    Assert.assertEquals(expectedText, params.get(NotificationManager.PARAM_TEXT_MSG));
    Assert.assertEquals(expectedText, params.get(NotificationManager.PARAM_SUBJECT));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Notification(org.opennms.netmgt.config.notifications.Notification) Test(org.junit.Test)

Example 22 with Notification

use of org.opennms.netmgt.config.notifications.Notification in project opennms by OpenNMS.

the class NotifdIT method testRebuildParameterMap.

@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++;
    }
}
Also used : MockInterface(org.opennms.netmgt.mock.MockInterface) HashMap(java.util.HashMap) Event(org.opennms.netmgt.xml.event.Event) Date(java.util.Date) Notification(org.opennms.netmgt.config.notifications.Notification) Test(org.junit.Test)

Aggregations

Notification (org.opennms.netmgt.config.notifications.Notification)22 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 ServletException (javax.servlet.ServletException)2 Parameter (org.opennms.netmgt.config.notifications.Parameter)2 Event (org.opennms.netmgt.xml.event.Event)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Calendar (java.util.Calendar)1 TreeMap (java.util.TreeMap)1 HttpSession (javax.servlet.http.HttpSession)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 Querier (org.opennms.core.utils.Querier)1 SingleResultQuerier (org.opennms.core.utils.SingleResultQuerier)1