Search in sources :

Example 36 with OnmsNode

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

the class DragonWaveNodeSwitchingIT method testASetup.

@Test
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "192.168.255.22", resource = "classpath:/dw/walks/node3-walk.properties") })
public void testASetup() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    final InetAddress iface = InetAddressUtils.addr("192.168.255.22");
    final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("SNMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).setService("ICMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(iface).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    importResource("classpath:/dw/import/dw_test_import.xml");
    anticipator.verifyAnticipated(200000, 0, 0, 0, 0);
    final OnmsNode onmsNode = m_nodeDao.findAll().get(0);
    assertEquals(".1.3.6.1.4.1.7262.1", onmsNode.getSysObjectId());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetAddress(java.net.InetAddress) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 37 with OnmsNode

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

the class DefaultPollingContext method createApStatusEvent.

protected Event createApStatusEvent(String physAddr, Integer nodeId, String status) {
    final List<Parm> parms = new ArrayList<Parm>();
    OnmsNode node = getNodeDao().get(nodeId);
    parms.add(buildParm(EventConstants.PARM_PASSIVE_IPADDR, getNodeIpAddress(node).getHostAddress()));
    parms.add(buildParm(EventConstants.PARM_PASSIVE_NODE_LABEL, node.getLabel()));
    parms.add(buildParm(EventConstants.PARM_PASSIVE_SERVICE_NAME, getPackage().getEffectiveService().getPassiveServiceName()));
    parms.add(buildParm(EventConstants.PARM_PASSIVE_SERVICE_STATUS, status));
    parms.add(buildParm("physAddr", physAddr));
    EventBuilder bldr = new EventBuilder(PASSIVE_STATUS_UEI, "accesspointmonitord");
    bldr.setParms(parms);
    return bldr.getEvent();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) ArrayList(java.util.ArrayList) Parm(org.opennms.netmgt.xml.event.Parm)

Example 38 with OnmsNode

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

the class MinionHeartbeatMonitor method poll.

@Override
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) {
    // Minions send heartbeat every 30 seconds - we check that we can skip not more than one beat
    final int period = 2 * ParameterMap.getKeyedInteger(parameters, "period", 30 * 1000);
    // Get the minion to test whereas the minion ID is the nodes foreign ID by convention
    final OnmsNode node = nodeDao.get().get(svc.getNodeId());
    final OnmsMinion minion = minionDao.get().findById(node.getForeignId());
    // Calculate the time since the last heartbeat was received
    final long lastSeen = System.currentTimeMillis() - minion.getLastUpdated().getTime();
    final PollStatus status;
    if (lastSeen <= period) {
        status = PollStatus.available();
    } else if (ManagementFactory.getRuntimeMXBean().getUptime() < period) {
        status = PollStatus.unknown("JVM has not been started long enough to process a heartbeat.");
    } else {
        status = PollStatus.unavailable(String.format("Last heartbeat was %.2f seconds ago", lastSeen / 1000.0));
    }
    return status;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) PollStatus(org.opennms.netmgt.poller.PollStatus) OnmsMinion(org.opennms.netmgt.model.minion.OnmsMinion)

Example 39 with OnmsNode

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

the class VmwareCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    final OnmsNode onmsNode = m_nodeDao.get(agent.getNodeId());
    if (onmsNode == null) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No node found with id: %d", agent.getNodeId()));
    }
    // retrieve the assets
    final String vmwareManagementServer = onmsNode.getAssetRecord().getVmwareManagementServer();
    if (Strings.isNullOrEmpty(vmwareManagementServer)) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No management server is set on node with id %d.", onmsNode.getId()));
    }
    runtimeAttributes.put(VMWARE_MGMT_SERVER_KEY, vmwareManagementServer);
    final String vmwareManagedObjectId = onmsNode.getForeignId();
    if (Strings.isNullOrEmpty(vmwareManagedObjectId)) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No foreign id is set on node with id %d.", onmsNode.getId()));
    }
    runtimeAttributes.put(VMWARE_MGED_OBJECT_ID_KEY, vmwareManagedObjectId);
    // retrieve the collection
    final String collectionName = ParameterMap.getKeyedString(parameters, "collection", ParameterMap.getKeyedString(parameters, "vmware-collection", null));
    final VmwareCollection collection = m_vmwareDatacollectionConfigDao.getVmwareCollection(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No collection found with name '%s'.", collectionName));
    }
    runtimeAttributes.put(VMWARE_COLLECTION_KEY, collection);
    // retrieve the server configuration
    final Map<String, VmwareServer> serverMap = m_vmwareConfigDao.getServerMap();
    if (serverMap == null) {
        throw new IllegalStateException(String.format("VmwareCollector: Error getting vmware-config.xml's server map."));
    }
    final VmwareServer vmwareServer = serverMap.get(vmwareManagementServer);
    if (vmwareServer == null) {
        throw new IllegalStateException(String.format("VmwareCollector: Error getting credentials for VMware management server: %s", vmwareManagementServer));
    }
    runtimeAttributes.put(VMWARE_SERVER_KEY, vmwareServer);
    return runtimeAttributes;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection)

Example 40 with OnmsNode

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

the class DefaultResourceDaoTest method testGetTopLevelResourceNodeExistsNoChildResources.

@Test
public void testGetTopLevelResourceNodeExistsNoChildResources() throws Exception {
    OnmsNode node = createNode(2, "Node Two");
    expect(m_nodeDao.get(node.getId().toString())).andReturn(node).times(1);
    m_easyMockUtils.replayAll();
    OnmsResource resource = m_resourceDao.getResourceById(ResourceId.get("node", "2"));
    m_easyMockUtils.verifyAll();
    assertNotNull("Resource should not be null", resource);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) Test(org.junit.Test)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)496 Test (org.junit.Test)209 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)116 Transactional (org.springframework.transaction.annotation.Transactional)84 ArrayList (java.util.ArrayList)52 Date (java.util.Date)49 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)38 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)37 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)36 InetAddress (java.net.InetAddress)35 Before (org.junit.Before)32 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)31 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 HashMap (java.util.HashMap)27 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)26 File (java.io.File)25 List (java.util.List)25 Path (javax.ws.rs.Path)23