Search in sources :

Example 16 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode 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<JmsNorthbounder>();
    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<NorthboundAlarm>();
    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
                String eventparms = "foreignSource=fabric(string,text);foreignId=space-0256012012000038(string,text);reason=Aborting node scan : Agent timed out while scanning the system table(string,text);" + ".1.3.6.1.4.1.2636.3.18.1.7.1.2.732=207795895(TimeTicks,text)";
                onmsAlarm.setEventParms(eventparms);
            }
            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<String>();
    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) OnmsNode(org.opennms.netmgt.model.OnmsNode) 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) 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) JmsDestination(org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination) InetAddress(java.net.InetAddress) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 17 with OnmsNode

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

the class JmsNorthBounderTest method testAlarmMappings.

@Test
public void testAlarmMappings() throws Exception {
    String xml = generateMappingConfigXml();
    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.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.setAlarmType(1);
        alarm.setFirstEventTime(new Date(0));
        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);
        alarm.setCounter(2);
        NorthboundAlarm b = new NorthboundAlarm(alarm);
        alarms.add(a);
        alarms.add(b);
        nbi.forwardAlarms(alarms);
    }
    Thread.sleep(100);
    // Let's become a consumer and receive the message
    Message m = m_template.receive("MappingTestQueue");
    String escapedResponse = "ackUser:  appDn: applicationDN logMsg: eventlogmsg objectInstance: managedObjectInstance objectType: managedObjectType ossKey: ossPrimaryKey\n" + " ossState: qosAlarmState ticketId: tticketId alarmUei: uei.uei.org/uei alarmKey: reductionKey clearKey: clearKey description: eventdescr operInstruct: operInstruct ackTime: \n" + " alarmType: PROBLEM count: 1 alarmId: 9 ipAddr: 127.0.0.1 lastOccurrence:  nodeId: 1\n" + " nodeLabel: schlazor distPoller: 00000000-0000-0000-0000-000000000000 ifService:  severity: WARNING ticketState:  x733AlarmType: other\n" + " x733ProbableCause: other firstOccurrence: " + StringUtils.iso8601LocalOffsetString(new Date(0)) + " lastOccurrence  eventParmsXml: <eventParms>\n" + "    <parm name=\"syslogmessage\" value=\"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\" type=\"string\"/>\n" + "    <parm name=\"severity\" value=\"Error\" type=\"string\"/>\n" + "    <parm name=\"timestamp\" value=\"Dec 22 14:13:21\" type=\"string\"/>\n" + "    <parm name=\"process\" value=\"229250\" type=\"string\"/>\n" + "    <parm name=\"service\" value=\"local7\" type=\"string\"/>\n" + "</eventParms>";
    String response = ((TextMessage) m).getText();
    Assert.assertEquals("Contents of message\n'" + response + "'\n not equals\n'" + escapedResponse + "'.", response, escapedResponse);
    // ensure only 1 message received since same reduction key
    m_template.setReceiveTimeout(JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT);
    m = m_template.receive("MappingTestQueue");
    Assert.assertNull(m);
}
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) JmsDestination(org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination) InetAddress(java.net.InetAddress) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 18 with OnmsNode

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

the class VacuumdIT method setUp.

@Before
public void setUp() throws Exception {
    m_network.createStandardNetwork();
    InputStream is = ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/vacuumd/vacuumd-configuration.xml");
    try {
        VacuumdConfigFactory.setInstance(new VacuumdConfigFactory(is));
    } finally {
        IOUtils.closeQuietly(is);
    }
    m_eventdIpcMgr.setEventWriter(m_database);
    EventExpander expander = new EventExpander(new MetricRegistry());
    expander.setEventConfDao(new EmptyEventConfDao());
    m_eventdIpcMgr.setEventExpander(expander);
    Vacuumd.destroySingleton();
    m_vacuumd = Vacuumd.getSingleton();
    m_vacuumd.setEventManager(m_eventdIpcMgr);
    m_vacuumd.init();
    // Insert some empty nodes to avoid foreign-key violations on subsequent events/alarms
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "default-1");
    node.setId(1);
    m_nodeDao.save(node);
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "default-2");
    node.setId(2);
    m_nodeDao.save(node);
    m_nodeDao.flush();
    MockUtil.println("------------ Finished setup for: " + this.getClass().getName() + " --------------------------");
}
Also used : VacuumdConfigFactory(org.opennms.netmgt.config.VacuumdConfigFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) EventExpander(org.opennms.netmgt.eventd.EventExpander) InputStream(java.io.InputStream) MetricRegistry(com.codahale.metrics.MetricRegistry) EmptyEventConfDao(org.opennms.netmgt.dao.mock.MockEventIpcManager.EmptyEventConfDao) Before(org.junit.Before)

Example 19 with OnmsNode

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

the class NodeLabelDaoImpl method retrieveLabel.

/**
     * This method queries the 'node' table for the value of the 'nodelabel' and
     * 'nodelabelsource' fields for the node with the provided nodeID. A
     * NodeLabel object is returned initialized with the retrieved values.
     *
     * @param nodeID
     *            Unique ID of node whose label info is to be retrieved
     * @param dbConnection
     *            SQL database connection
     * @return object initialized with node label & source flag
     * @throws java.sql.SQLException if any.
     * 
     * @deprecated Use a {@link NodeDao#load(Integer)} method call instead
     */
@Override
public NodeLabel retrieveLabel(final int nodeID) throws SQLException {
    OnmsNode node = nodeDao.get(nodeID);
    String nodeLabel = node.getLabel();
    NodeLabelSource nodeLabelSource = node.getLabelSource();
    return new NodeLabelDaoImpl(nodeLabel, nodeLabelSource);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) NodeLabelSource(org.opennms.netmgt.model.OnmsNode.NodeLabelSource)

Example 20 with OnmsNode

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

the class IfIndexNullIT method testNullIfIndex.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = "192.0.2.201", port = 161, resource = "classpath:/snmpTestData-null.properties"), @JUnitSnmpAgent(host = "192.0.2.204", port = 161, resource = "classpath:/snmpTestData-null.properties") })
public void testNullIfIndex() throws Exception {
    final CountDownLatch eventRecieved = anticipateEvents(1, EventConstants.PROVISION_SCAN_COMPLETE_UEI, EventConstants.PROVISION_SCAN_ABORTED_UEI);
    m_provisioner.importModelFromResource(m_resourceLoader.getResource("classpath:/tec_dump.xml"), Boolean.TRUE.toString());
    waitForEverything();
    final List<OnmsNode> nodes = getNodeDao().findAll();
    final OnmsNode node = nodes.get(0);
    eventRecieved.await();
    final NodeScan scan = m_provisioner.createNodeScan(node.getId(), node.getForeignSource(), node.getForeignId(), node.getLocation());
    runScan(scan);
    //Verify ipinterface count
    assertEquals(2, getInterfaceDao().countAll());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)438 Test (org.junit.Test)187 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)99 Transactional (org.springframework.transaction.annotation.Transactional)76 ArrayList (java.util.ArrayList)48 Date (java.util.Date)40 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)36 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)31 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)31 InetAddress (java.net.InetAddress)28 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 Before (org.junit.Before)27 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)26 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)26 File (java.io.File)24 HashMap (java.util.HashMap)23 List (java.util.List)21 Path (javax.ws.rs.Path)21 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)20