Search in sources :

Example 26 with OnmsSnmpInterface

use of org.opennms.netmgt.model.OnmsSnmpInterface 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)

Example 27 with OnmsSnmpInterface

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

the class ProvisionerIT method testPopulateWithIpv6SnmpAndNodeScan.

// fail if we take more than five minutes
@Test(timeout = 300000)
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "10.1.15.245", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "10.3.20.23", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "2001:0470:e2f1:cafe:16c1:7cff:12d6:7bb9", resource = "classpath:/snmpwalk-demo.properties") })
public void testPopulateWithIpv6SnmpAndNodeScan() throws Exception {
    final ForeignSource fs = new ForeignSource();
    fs.setName("matt:");
    fs.addDetector(new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector"));
    m_foreignSourceRepository.putDefaultForeignSource(fs);
    importFromResource("classpath:/requisition_then_scanv6.xml", Boolean.TRUE.toString());
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    // Verify ipinterface count
    assertEquals(1, getInterfaceDao().countAll());
    // Verify ifservices count
    assertEquals(1, getMonitoredServiceDao().countAll());
    // Verify service count
    assertEquals(1, getServiceTypeDao().countAll());
    // Verify snmpInterface count
    assertEquals(1, getSnmpInterfaceDao().countAll());
    runPendingScans();
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    // Verify ipinterface count
    assertEquals("Unexpected number of IP interfaces found: " + getInterfaceDao().findAll(), 3, getInterfaceDao().countAll());
    // Verify ifservices count - discover snmp service on other if
    assertEquals("Unexpected number of services found: " + getMonitoredServiceDao().findAll(), 3, getMonitoredServiceDao().countAll());
    // Verify service count
    assertEquals("Unexpected number of service types found: " + getServiceTypeDao().findAll(), 1, getServiceTypeDao().countAll());
    // Verify snmpInterface count
    assertEquals("Unexpected number of SNMP interfaces found: " + getSnmpInterfaceDao().findAll(), 6, getSnmpInterfaceDao().countAll());
    // Ensure that collection is on for all ip interfaces
    for (OnmsIpInterface iface : getInterfaceDao().findAll()) {
        OnmsSnmpInterface snmpIface = iface.getSnmpInterface();
        assertNotNull("Expected an snmp interface associated with " + iface.getIpAddress(), snmpIface);
        assertTrue("Expected snmp interface associated with " + iface.getIpAddress() + " to have collection enabled.", snmpIface.isCollectionEnabled());
    }
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 28 with OnmsSnmpInterface

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

the class MatchingIpInterfacePolicy method act.

/**
 * {@inheritDoc}
 */
@Override
public OnmsIpInterface act(OnmsIpInterface iface) {
    OnmsSnmpInterface snmpiface = iface.getSnmpInterface();
    switch(m_action) {
        case DO_NOT_PERSIST:
            LOG.debug("NOT Persisting {} according to policy", iface);
            return null;
        case MANAGE:
            LOG.debug("Managing {} according to policy", iface);
            iface.setIsManaged("M");
            return iface;
        case UNMANAGE:
            LOG.debug("Unmanaging {} according to policy", iface);
            iface.setIsManaged("U");
            return iface;
        case ENABLE_SNMP_POLL:
            LOG.debug("SNMP polling {} according to policy", iface);
            snmpiface.setPoll("P");
            iface.setSnmpInterface(snmpiface);
            return iface;
        case DISABLE_SNMP_POLL:
            LOG.debug("Disable SNMP polling {} according to policy", iface);
            snmpiface.setPoll("N");
            iface.setSnmpInterface(snmpiface);
            return iface;
        case DISABLE_COLLECTION:
            LOG.debug("Disabled collection for {} according to policy", iface);
            snmpiface.setCollectionEnabled(false);
            iface.setSnmpInterface(snmpiface);
            return iface;
        case ENABLE_COLLECTION:
            LOG.debug("Enabled collection for {} according to policy", iface);
            snmpiface.setCollectionEnabled(true);
            iface.setSnmpInterface(snmpiface);
            return iface;
        default:
            return iface;
    }
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 29 with OnmsSnmpInterface

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

the class DefaultPollContext method update.

/**
 * {@inheritDoc}
 */
@Override
public void update(OnmsSnmpInterface snmpinterface) {
    OnmsSnmpInterface dbSnmpInterface = getSnmpInterfaceDao().findByNodeIdAndIfIndex(snmpinterface.getNode().getId(), snmpinterface.getIfIndex());
    if (dbSnmpInterface == null) {
        log().debug("updating SnmpInterface: no interface found on db for: " + snmpinterface.toString());
    } else {
        dbSnmpInterface.setIfOperStatus(snmpinterface.getIfOperStatus());
        dbSnmpInterface.setIfAdminStatus(snmpinterface.getIfAdminStatus());
        dbSnmpInterface.setLastSnmpPoll(snmpinterface.getLastSnmpPoll());
        log().debug("updating SnmpInterface: " + dbSnmpInterface.toString());
        getSnmpInterfaceDao().update(dbSnmpInterface);
    }
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 30 with OnmsSnmpInterface

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

the class PollableSnmpInterface method doPoll.

// end Run method
private void doPoll(SnmpPollInterfaceMonitor pollMonitor, List<SnmpMinimalPollInterface> mifaces) {
    LOG.info("doPoll: input interfaces number: {}", mifaces.size());
    mifaces = pollMonitor.poll(getAgentConfig(), mifaces);
    boolean refresh = false;
    Date now = getDate();
    if (mifaces != null) {
        LOG.info("doPoll: PollerMonitor return interfaces number: {}", mifaces.size());
        for (SnmpMinimalPollInterface miface : mifaces) {
            LOG.debug("Working on interface with ifindex: {}", miface.getIfindex());
            LOG.debug("Interface PollStatus is {}", miface.getStatus().getStatusName());
            if (miface.getStatus().isUp()) {
                OnmsSnmpInterface iface = m_snmpinterfaces.get(Integer.valueOf(miface.getIfindex()));
                LOG.debug("Previuos status Admin/Oper: {}/{}", iface.getIfAdminStatus(), iface.getIfOperStatus());
                LOG.debug("Current status Admin/Oper: {}/{}", miface.getAdminstatus(), miface.getOperstatus());
                // If the interface is Admin Up, and the interface is Operational Down, we generate an alarm.
                if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_UP && miface.getOperstatus() == SnmpMinimalPollInterface.IF_DOWN && iface.getIfOperStatus() == SnmpMinimalPollInterface.IF_UP) {
                    sendOperDownEvent(iface);
                }
                // if was previuos down in alarm table
                if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_UP && miface.getOperstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfOperStatus() == SnmpMinimalPollInterface.IF_DOWN) {
                    sendOperUpEvent(iface);
                }
                if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_DOWN && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_UP) {
                    sendAdminDownEvent(iface);
                }
                if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_DOWN && miface.getOperstatus() != SnmpMinimalPollInterface.IF_UP) {
                    sendAdminUpEvent(iface);
                }
                if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_DOWN && miface.getOperstatus() == SnmpMinimalPollInterface.IF_UP) {
                    sendAdminUpEvent(iface);
                    sendOperUpEvent(iface);
                }
                iface.setIfAdminStatus(Integer.valueOf(miface.getAdminstatus()));
                iface.setIfOperStatus(Integer.valueOf(miface.getOperstatus()));
                iface.setLastSnmpPoll(now);
                // Save Data to Database
                try {
                    update(iface);
                } catch (Throwable e) {
                    LOG.warn("Failing updating Interface {} {}", iface.getIfName(), e.getLocalizedMessage());
                    refresh = true;
                }
            } else {
                LOG.debug("No {} data available for interface.", getContext().getServiceName());
            }
        // End if status OK
        }
        if (refresh)
            getParent().getParent().refresh(getParent().getNodeid());
    } else {
        LOG.error("the monitor return null object");
    }
// end If not null
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Date(java.util.Date)

Aggregations

OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)73 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)39 OnmsNode (org.opennms.netmgt.model.OnmsNode)38 Test (org.junit.Test)17 InetAddress (java.net.InetAddress)16 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)10 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)9 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)8 LinkedHashSet (java.util.LinkedHashSet)5 LinkedList (java.util.LinkedList)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Before (org.junit.Before)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 IpNetToMedia (org.opennms.netmgt.model.IpNetToMedia)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)4