Search in sources :

Example 51 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmQueueTest method createAlarm.

/**
 * Creates the alarm.
 *
 * @return the northbound alarm
 */
private NorthboundAlarm createAlarm() {
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setId(++alarmNumber);
    alarm.setUei("uei.opennms.org/test/httpNorthBounder");
    return new NorthboundAlarm(alarm);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm)

Example 52 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class BSFNorthbounderIT method testNorthbounder.

/**
 * Test northbounder.
 *
 * @throws Exception the exception
 */
@Test
public void testNorthbounder() throws Exception {
    // Setup test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Servers-MacOS");
    node.setForeignId("1");
    node.setId(1);
    node.setLabel("my-test-server");
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName("my-test-server");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.getIpInterfaces().add(onmsIf);
    // Setup test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(100);
    onmsAlarm.setNode(node);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    OnmsEvent event = new OnmsEvent();
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
    onmsAlarm.setLastEvent(event);
    onmsAlarm.setLogMsg("Test log message");
    onmsAlarm.setDescription("Test description");
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(2, alarm.getEventParametersCollection().size());
    Assert.assertTrue(nbi.accepts(alarm));
    nbi.forwardAlarms(Lists.newArrayList(alarm));
    nbi.stop();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 53 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class DroolsNorthbounderIT method testNorthbounder.

/**
 * Test northbounder.
 *
 * @throws Exception the exception
 */
@Test
public void testNorthbounder() throws Exception {
    // Setup test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Servers-MacOS");
    node.setForeignId("1");
    node.setId(1);
    node.setLabel("my-test-server");
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName("my-test-server");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.getIpInterfaces().add(onmsIf);
    // Setup test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(100);
    onmsAlarm.setNode(node);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    OnmsEvent event = new OnmsEvent();
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
    onmsAlarm.setLastEvent(event);
    onmsAlarm.setLogMsg("Test log message");
    onmsAlarm.setDescription("Test description");
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(2, alarm.getEventParametersCollection().size());
    Assert.assertTrue(nbi.accepts(alarm));
    nbi.forwardAlarms(Lists.newArrayList(alarm));
    nbi.stop();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 54 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class HttpNorthBounderTest method testForwardAlarms.

/**
 * Test forward alarms.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
@JUnitHttpServer(port = 10342)
public void testForwardAlarms() throws InterruptedException {
    HttpNorthbounder nb = new HttpNorthbounder();
    HttpNorthbounderConfig config = new HttpNorthbounderConfig("localhost");
    config.setMethod(HttpMethod.POST);
    config.setPath("/jms/post");
    config.setPort(Integer.valueOf(10342));
    nb.setConfig(config);
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setId(1);
    alarm.setUei("uei.opennms.org/test/httpNorthBounder");
    NorthboundAlarm a = new NorthboundAlarm(alarm);
    nb.onAlarm(a);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 55 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class JmsNorthBounderTest method testForwardAlarms.

/**
 * This tests forwarding of 7 alarms, one for each OpenNMS severity to
 * verify the LOG_LEVEL agrees with the Severity based on our algorithm.
 *
 * @throws Exception the exception
 */
@Test
public void testForwardAlarms() throws Exception {
    String xml = generateConfigXml();
    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<>();
    for (JmsDestination jmsDestination : destinations) {
        JmsNorthbounder nbi = new JmsNorthbounder(config, m_jmsNorthbounderConnectionFactory, jmsDestination);
        nbi.afterPropertiesSet();
        nbis.add(nbi);
    }
    int j = 7;
    List<NorthboundAlarm> alarms = new LinkedList<>();
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), NODE_LABEL);
    node.setForeignSource("TestGroup");
    node.setForeignId("1");
    node.setId(m_nodeDao.getNextNodeId());
    OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
    snmpInterface.setId(1);
    snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
    snmpInterface.setIfDescr("en1");
    snmpInterface.setIfName("en1/0");
    snmpInterface.setPhysAddr("00:00:00:00:00:01");
    Set<OnmsIpInterface> ipInterfaces = new LinkedHashSet<OnmsIpInterface>(j);
    InetAddress address = InetAddress.getByName("10.0.1.1");
    OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
    onmsIf.setSnmpInterface(snmpInterface);
    onmsIf.setId(1);
    onmsIf.setIfIndex(1);
    onmsIf.setIpHostName(NODE_LABEL);
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    ipInterfaces.add(onmsIf);
    node.setIpInterfaces(ipInterfaces);
    m_nodeDao.save(node);
    m_nodeDao.flush();
    // TX via NBIs
    for (JmsNorthbounder nbi : nbis) {
        for (int i = 1; i <= j; ++i) {
            OnmsAlarm onmsAlarm = new OnmsAlarm();
            onmsAlarm.setId(i);
            onmsAlarm.setUei("uei.opennms.org/test/jmsNorthBounder");
            onmsAlarm.setNode(node);
            onmsAlarm.setSeverityId(i);
            onmsAlarm.setIpAddr(InetAddress.getByName("127.0.0.1"));
            onmsAlarm.setCounter(i);
            onmsAlarm.setLogMsg("Node Down");
            onmsAlarm.setX733AlarmType(NorthboundAlarm.x733AlarmType.get(i).name());
            onmsAlarm.setX733ProbableCause(NorthboundAlarm.x733ProbableCause.get(i).getId());
            if (i < j) {
                // Do not add parameters to the last alarm for
                // testing NMS-6383
                OnmsEvent event = new OnmsEvent();
                event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "foreignSource", "fabric", "string"), new OnmsEventParameter(event, "foreignId", "space-0256012012000038", "string"), new OnmsEventParameter(event, "reason", "Aborting node scan : Agent timed out while scanning the system table", "string"), new OnmsEventParameter(event, ".1.3.6.1.4.1.2636.3.18.1.7.1.2.732", "207795895", "TimeTicks")));
                onmsAlarm.setLastEvent(event);
            }
            NorthboundAlarm a = new NorthboundAlarm(onmsAlarm);
            Assert.assertFalse(nbi.accepts(a));
            onmsAlarm.setUei("uei.opennms.org/nodes/nodeDown");
            a = new NorthboundAlarm(onmsAlarm);
            Assert.assertTrue(nbi.accepts(a));
            alarms.add(a);
        }
        nbi.forwardAlarms(alarms);
    }
    Thread.sleep(100);
    // Let's become a consumer and receive the messages!
    List<String> messages = new LinkedList<>();
    Message m = m_template.receive("OpenNMSAlarmQueue");
    while (m != null) {
        Assert.assertTrue(m instanceof TextMessage);
        messages.add(((TextMessage) m).getText());
        m = m_template.receive("OpenNMSAlarmQueue");
    }
    Assert.assertTrue("Log messages sent: 7, Log messages received: " + messages.size(), 7 == messages.size());
    for (String message : messages) {
        System.out.println(message);
    }
    int i = 0;
    for (String message : messages) {
        Assert.assertTrue("ALARM ID:" + (i + 1), message.contains("ALARM ID:" + (i + 1) + " "));
        Assert.assertTrue(message.contains("NODE:" + NODE_LABEL));
        i++;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) 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) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) JmsDestination(org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination) OnmsNode(org.opennms.netmgt.model.OnmsNode) JmsNorthbounderConfigDao(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) ByteArrayResource(org.springframework.core.io.ByteArrayResource) LinkedList(java.util.LinkedList) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) JmsNorthbounder(org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounder) InetAddress(java.net.InetAddress) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7