Search in sources :

Example 1 with OnmsNode

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

the class DefaultEventProcessor method process.

@Override
public void process(final Exchange exchange) throws Exception {
    final Event event = exchange.getIn().getBody(Event.class);
    // are added as message headers
    if (event.getNodeid() > 0) {
        OnmsNode node = nodeDao.get(event.getNodeid().intValue());
        if (node != null) {
            String foreignSource = node.getForeignSource();
            String foreignId = node.getForeignId();
            if (foreignSource != null && foreignId != null) {
                exchange.getIn().setHeader(EVENT_HEADER_FOREIGNSOURCE, node.getForeignSource());
                exchange.getIn().setHeader(EVENT_HEADER_FOREIGNID, node.getForeignId());
            }
        } else {
            LOG.warn("Could not find node {} in the database, cannot add requisition headers", event.getNodeid());
        }
    }
    // Marshall the Event to XML
    exchange.getIn().setBody(JaxbUtils.marshal(event), String.class);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Event(org.opennms.netmgt.xml.event.Event)

Example 2 with OnmsNode

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

the class IPServiceEdgeDaoIT method ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade.

@Test
public void ipServiceEdgesWithRelatedIpServicesAreDeletedOnCascade() throws InterruptedException {
    // Create a business service
    BusinessServiceEntity bs = new BusinessServiceEntity();
    bs.setName("Mont Cascades");
    bs.setAttribute("dc", "RDU");
    bs.setReductionFunction(m_highestSeverity);
    m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // Initially there should be no edges
    assertEquals(0, m_businessServiceEdgeDao.countAll());
    // Create an edge
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setMapFunction(m_identity);
    edge.setBusinessService(bs);
    // Grab the first monitored service from node 1
    OnmsNode node = m_databasePopulator.getNode1();
    OnmsMonitoredService ipService = node.getIpInterfaces().iterator().next().getMonitoredServices().iterator().next();
    edge.setIpService(ipService);
    m_businessServiceEdgeDao.save(edge);
    m_businessServiceEdgeDao.flush();
    bs.addEdge(edge);
    m_businessServiceDao.update(bs);
    m_businessServiceDao.flush();
    // We should have a single business service with a single IP service associated
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(1, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
    // Now delete the node
    m_nodeDao.delete(node);
    m_nodeDao.flush();
    // The business service should still be present, but the IP service should have been deleted
    // by the foreign key constraint
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(0, m_businessServiceDao.get(bs.getId()).getIpServiceEdges().size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) OnmsNode(org.opennms.netmgt.model.OnmsNode) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 3 with OnmsNode

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

the class BusinessServiceManagerImpl method getNodeEntity.

private OnmsNode getNodeEntity(Integer nodeId) {
    Objects.requireNonNull(nodeId);
    final OnmsNode entity = nodeDao.get(nodeId);
    if (entity == null) {
        throw new NoSuchElementException("OnmsNode with id " + nodeId);
    }
    return entity;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with OnmsNode

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

the class CollectorComplianceTest method canCollectUsingMinionWorkflow.

@Test
public void canCollectUsingMinionWorkflow() throws CollectionInitializationException, CollectionException {
    Assume.assumeTrue(runsOnMinion);
    // create the agent
    OnmsNode node = mock(OnmsNode.class);
    when(node.getId()).thenReturn(1);
    OnmsIpInterface iface = mock(OnmsIpInterface.class);
    when(iface.getNode()).thenReturn(node);
    when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
    IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
    when(ifaceDao.load(1)).thenReturn(iface);
    PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
    final SnmpCollectionAgent agent = DefaultCollectionAgent.create(1, ifaceDao, transMgr);
    // init() should execute without any exceptions
    final ServiceCollector opennmsCollector = getCollector();
    initialize(opennmsCollector);
    // getEffectiveLocation() should return the original location
    final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    assertEquals("Location cannot be altered.", targetLocation, opennmsCollector.getEffectiveLocation(targetLocation));
    // getRuntimeAttributes() should return a valid map
    final Map<String, Object> requiredParams = getRequiredParameters();
    final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams));
    // marshalParameters() should marshal all parameters to strings
    final Map<String, Object> allParms = new HashMap<>();
    allParms.putAll(requiredParams);
    allParms.putAll(runtimeAttrs);
    final Map<String, String> marshaledParms = opennmsCollector.marshalParameters(Collections.unmodifiableMap(allParms));
    beforeMinion();
    // create a separate instance of the collector
    final ServiceCollector minionCollector = getNewCollector();
    // unmarshalParameters() should unmarshal all parameters from strings
    final Map<String, Object> unmarshaledParms = minionCollector.unmarshalParameters(Collections.unmodifiableMap(marshaledParms));
    // collect() should return a valid collection set
    final CollectionAgentDTO agentDTO = new CollectionAgentDTO(agent);
    final CollectionSet collectionSet = minionCollector.collect(agentDTO, Collections.unmodifiableMap(unmarshaledParms));
    assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    afterMinion();
    // the collection set should be marshalable
    JaxbUtils.marshal(collectionSet);
    // getRrdRepository() should return a valid repository
    assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) Test(org.junit.Test)

Example 5 with OnmsNode

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

the class CollectorComplianceTest method canCollectUsingOpenNMSWorkflow.

@Test
public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException {
    // create the agent
    OnmsNode node = mock(OnmsNode.class);
    OnmsIpInterface iface = mock(OnmsIpInterface.class);
    when(iface.getNode()).thenReturn(node);
    when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
    IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
    when(ifaceDao.load(1)).thenReturn(iface);
    PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
    final SnmpCollectionAgent agent = DefaultCollectionAgent.create(1, ifaceDao, transMgr);
    // init() should execute without any exceptions
    final ServiceCollector opennmsCollector = getCollector();
    initialize(opennmsCollector);
    // getEffectiveLocation() should execute without any exceptions
    // in this context there are no requirements on its return value
    final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    opennmsCollector.getEffectiveLocation(targetLocation);
    // getRuntimeAttributes() should return a valid map
    final Map<String, Object> requiredParams = getRequiredParameters();
    final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams));
    // collect() should return a valid collection set
    final Map<String, Object> allParms = new HashMap<>();
    allParms.putAll(requiredParams);
    allParms.putAll(runtimeAttrs);
    final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms));
    assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    // getRrdRepository() should return a valid repository
    assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

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