Search in sources :

Example 6 with JmsNorthbounderConfigDao

use of org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao in project opennms by OpenNMS.

the class JmsNorthBounderTest method testObjectMessage.

@Test
public void testObjectMessage() throws Exception {
    String xml = objectMessageConfigXml();
    Resource resource = new ByteArrayResource(xml.getBytes());
    JmsNorthbounderConfigDao dao = new JmsNorthbounderConfigDao();
    dao.setConfigResource(resource);
    dao.afterPropertiesSet();
    JmsNorthbounderConfig config = dao.getConfig();
    List<JmsDestination> destinations = config.getDestinations();
    List<JmsNorthbounder> nbis = new LinkedList<JmsNorthbounder>();
    for (JmsDestination jmsDestination : destinations) {
        JmsNorthbounder nbi = new JmsNorthbounder(config, m_jmsNorthbounderConnectionFactory, jmsDestination);
        //nbi.setNodeDao(m_nodeDao);
        nbi.afterPropertiesSet();
        nbis.add(nbi);
    }
    List<NorthboundAlarm> alarms = new LinkedList<NorthboundAlarm>();
    OnmsNode node = new OnmsNode(null, NODE_LABEL);
    node.setForeignSource("TestGroup");
    node.setForeignId("2");
    node.setId(m_nodeDao.getNextNodeId());
    OnmsIpInterface ip = new OnmsIpInterface("127.0.0.1", node);
    InetAddress ia = null;
    try {
        ia = InetAddress.getByName("127.0.0.1");
    } catch (UnknownHostException e) {
    }
    m_nodeDao.save(node);
    m_nodeDao.flush();
    // TX via NBIs
    for (JmsNorthbounder nbi : nbis) {
        String eventparms = "syslogmessage=Dec 22 2015 20:12:57.1 UTC :  %UC_CTI-3-CtiProviderOpenFailure: %[CTIconnectionId%61232238][ Login User Id%61pguser][Reason code.%61-1932787616][UNKNOWN_PARAMNAME:IPAddress%61172.17.12.73][UNKNOWN_PARAMNAME:IPv6Address%61][App ID%61Cisco CTIManager][Cluster ID%61SplkCluster][Node ID%61splkcucm6p]: CTI application failed to open provider%59 application startup failed(string,text);severity=Error(string,text);timestamp=Dec 22 14:13:21(string,text);process=229250(string,text);service=local7(string,text)";
        OnmsEvent event = new OnmsEvent(5, "uei.uei.org/uei", new Date(), "eventhost", "eventsource", ia, null, "eventssnmphost", null, "eventsnmp", eventparms, new Date(), "eventdescr", "eventloggroup", "eventlogmsg", 4, null, null, 0, "operinstruct", null, null, null, null, "tticketid", 1, null, null, null, null, null, null, null, node, null, null, null);
        OnmsAlarm alarm = new OnmsAlarm(9, event.getEventUei(), null, 1, 4, new Date(), event);
        alarm.setNode(node);
        alarm.setDescription(event.getEventDescr());
        alarm.setApplicationDN("applicationDN");
        alarm.setLogMsg(event.getEventLogMsg());
        alarm.setManagedObjectInstance("managedObjectInstance");
        alarm.setManagedObjectType("managedObjectType");
        alarm.setOssPrimaryKey("ossPrimaryKey");
        alarm.setQosAlarmState("qosAlarmState");
        alarm.setTTicketId("tticketId");
        alarm.setReductionKey("reductionKey");
        alarm.setClearKey("clearKey");
        alarm.setOperInstruct("operInstruct");
        alarm.setFirstEventTime(new Date(0));
        alarm.setAlarmType(1);
        alarm.setIpAddr(ia);
        alarm.setEventParms(eventparms);
        alarm.setX733AlarmType(NorthboundAlarm.x733AlarmType.get(1).name());
        alarm.setX733ProbableCause(NorthboundAlarm.x733ProbableCause.get(1).getId());
        NorthboundAlarm a = new NorthboundAlarm(alarm);
        alarms.add(a);
        nbi.forwardAlarms(alarms);
    }
    Thread.sleep(100);
    // Let's become a consumer and receive the message
    Message m = m_template.receive("ObjectTestQueue");
    Assert.assertNotNull(m);
    Object response = ((ObjectMessage) m).getObject();
    Assert.assertNotNull(response);
    Assert.assertTrue("message\n'" + response + "'\n not a NorthboundAlarm\n'" + "'.", (response instanceof NorthboundAlarm));
    String rk = ((NorthboundAlarm) response).getAlarmKey();
    Assert.assertEquals("received alarm has incorrect reduction key: " + rk, "reductionKey", rk);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) UnknownHostException(java.net.UnknownHostException) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsNorthbounderConfig(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) JmsNorthbounderConfigDao(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) ByteArrayResource(org.springframework.core.io.ByteArrayResource) LinkedList(java.util.LinkedList) Date(java.util.Date) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) JmsNorthbounder(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounder) ObjectMessage(javax.jms.ObjectMessage) JmsDestination(org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 JmsNorthbounderConfig (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig)6 JmsNorthbounderConfigDao (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao)6 ByteArrayResource (org.springframework.core.io.ByteArrayResource)6 Resource (org.springframework.core.io.Resource)6 JmsDestination (org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination)5 InetAddress (java.net.InetAddress)4 LinkedList (java.util.LinkedList)4 Message (javax.jms.Message)4 ObjectMessage (javax.jms.ObjectMessage)4 TextMessage (javax.jms.TextMessage)4 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)4 JmsNorthbounder (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounder)4 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 UnknownHostException (java.net.UnknownHostException)3 Date (java.util.Date)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 LinkedHashSet (java.util.LinkedHashSet)1