Search in sources :

Example 11 with OnmsSnmpInterface

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

the class UpsertIT method testUpdate.

@Test
@JUnitTemporaryDatabase
public void testUpdate() {
    String oldIfName = "eth0";
    String newIfName = "newIf0";
    assertEquals(1, countIfs(m_populator.getNode1().getId(), 2, oldIfName));
    assertEquals(0, countIfs(m_populator.getNode1().getId(), 2, newIfName));
    // add non existent snmpiface
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface();
    snmpIface.setIfIndex(2);
    snmpIface.setIfName(newIfName);
    m_upsertService.upsert(m_populator.getNode1().getId(), snmpIface, 0);
    assertEquals(0, countIfs(m_populator.getNode1().getId(), 2, oldIfName));
    assertEquals(1, countIfs(m_populator.getNode1().getId(), 2, newIfName));
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 12 with OnmsSnmpInterface

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

the class DemandPollServiceTest method testPollMonitoredService.

public void testPollMonitoredService() throws EventProxyException {
    final int expectedResultId = m_pollStore.getExpectedId();
    // anticipate a call to the dao save with a pollResult
    m_demandPollDao.save(isA(DemandPoll.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            DemandPoll poll = (DemandPoll) getCurrentArguments()[0];
            m_pollStore.save(poll);
            return null;
        }
    });
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    expect(m_monitoredServiceDao.get(1, addr("192.168.1.1"), 1, 3)).andReturn(monSvc);
    m_pollerService.poll(monSvc, expectedResultId);
    replay(m_demandPollDao);
    replay(m_monitoredServiceDao);
    replay(m_pollerService);
    DemandPoll result = m_demandPollService.pollMonitoredService(1, addr("192.168.1.1"), 1, 3);
    verify(m_demandPollDao);
    verify(m_monitoredServiceDao);
    verify(m_pollerService);
    assertNotNull("Null is an invalid response from pollMonitoredService", result);
    assertEquals("Expected Id to be set by dao", expectedResultId, result.getId().intValue());
}
Also used : DemandPoll(org.opennms.netmgt.model.DemandPoll) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 13 with OnmsSnmpInterface

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

the class PollContextIT method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("cisco2691").setForeignSource("linkd").setForeignId("cisco2691").setSysObjectId(".1.3.6.1.4.1.9.1.122").setType(NodeType.ACTIVE);
    OnmsSnmpInterface null0 = new OnmsSnmpInterface(nb.getCurrentNode(), 4);
    null0.setIfSpeed(10000000l);
    null0.setPoll("P");
    null0.setIfType(6);
    null0.setCollectionEnabled(false);
    null0.setIfOperStatus(2);
    null0.setIfDescr("Null0");
    nb.addInterface("10.1.4.2", null0).setIsSnmpPrimary("P").setIsManaged("M");
    OnmsSnmpInterface fa0 = new OnmsSnmpInterface(nb.getCurrentNode(), 2);
    fa0.setIfSpeed(100000000l);
    fa0.setPoll("P");
    fa0.setIfType(6);
    fa0.setCollectionEnabled(false);
    fa0.setIfOperStatus(1);
    fa0.setIfDescr("FastEthernet0");
    nb.addInterface("10.1.5.1", fa0).setIsSnmpPrimary("S").setIsManaged("M");
    OnmsSnmpInterface eth0 = new OnmsSnmpInterface(nb.getCurrentNode(), 1);
    eth0.setIfSpeed(100000000l);
    eth0.setPoll("P");
    eth0.setIfType(6);
    eth0.setCollectionEnabled(false);
    eth0.setIfOperStatus(1);
    eth0.setIfDescr("Ethernet0");
    nb.addInterface("10.1.7.1", eth0).setIsSnmpPrimary("S").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("cisco1700").setForeignSource("linkd").setForeignId("cisco1700").setSysObjectId(".1.3.6.1.4.1.9.1.200").setType(NodeType.ACTIVE);
    OnmsSnmpInterface eth1 = new OnmsSnmpInterface(nb.getCurrentNode(), 2);
    eth1.setIfSpeed(100000000l);
    eth1.setPoll("P");
    eth1.setIfType(6);
    eth1.setCollectionEnabled(false);
    eth1.setIfOperStatus(1);
    eth1.setIfDescr("Ethernet1");
    nb.addInterface("10.1.5.2", eth1).setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    m_nodeDao.flush();
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Before(org.junit.Before)

Example 14 with OnmsSnmpInterface

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

the class NodeDaoIT method simulateScan.

private void simulateScan(Date timestamp) {
    OnmsNode n = getNodeDao().get(getNode1().getId());
    assertEquals(4, n.getIpInterfaces().size());
    assertEquals(4, n.getSnmpInterfaces().size());
    OnmsIpInterface iface = n.getIpInterfaceByIpAddress("192.168.1.1");
    assertNotNull(iface);
    iface.setIpLastCapsdPoll(timestamp);
    OnmsSnmpInterface snmpIface = n.getSnmpInterfaceWithIfIndex(1);
    assertNotNull(snmpIface);
    snmpIface.setLastCapsdPoll(timestamp);
    getNodeDao().saveOrUpdate(n);
    getNodeDao().flush();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 15 with OnmsSnmpInterface

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

the class DefaultUpsertService method upsert.

@Override
public OnmsSnmpInterface upsert(final int nodeId, final OnmsSnmpInterface snmpInterface, final int sleep) {
    UpsertTemplate<OnmsSnmpInterface, SnmpInterfaceDao> upzerter = new UpsertTemplate<OnmsSnmpInterface, SnmpInterfaceDao>(m_transactionManager, m_snmpInterfaceDao) {

        @Override
        public OnmsSnmpInterface query() {
            OnmsSnmpInterface dbSnmpIface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(nodeId, snmpInterface.getIfIndex());
            sleep(sleep);
            return dbSnmpIface;
        }

        @Override
        public OnmsSnmpInterface doUpdate(OnmsSnmpInterface dbSnmpIface) {
            // update the interface that was found
            LOG.debug("nodeId = {}, ifIndex = {}, dbSnmpIface = {}", nodeId, snmpInterface.getIfIndex(), dbSnmpIface);
            dbSnmpIface.mergeSnmpInterfaceAttributes(snmpInterface);
            LOG.info("Updating SnmpInterface {}", dbSnmpIface);
            m_snmpInterfaceDao.update(dbSnmpIface);
            m_snmpInterfaceDao.flush();
            return dbSnmpIface;
        }

        @Override
        public OnmsSnmpInterface doInsert() {
            // add the interface to the node, if it wasn't found
            final OnmsNode dbNode = m_nodeDao.get(nodeId);
            // for performance reasons we don't add the snmp interface to the node so we avoid loading all the interfaces
            // setNode only sets the node in the interface
            snmpInterface.setNode(dbNode);
            LOG.info("Saving SnmpInterface {}", snmpInterface);
            m_snmpInterfaceDao.save(snmpInterface);
            m_snmpInterfaceDao.flush();
            return snmpInterface;
        }
    };
    return upzerter.execute();
}
Also used : UpsertTemplate(org.opennms.netmgt.dao.support.UpsertTemplate) OnmsNode(org.opennms.netmgt.model.OnmsNode) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

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