Search in sources :

Example 11 with OnmsIpInterface

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

the class DefaultPollingContext method getNodeIpAddress.

/*
     * Return the IP address of the first interface on the node
     */
protected InetAddress getNodeIpAddress(OnmsNode node) {
    final Criteria criteria = new Criteria(OnmsIpInterface.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", node.getId()));
    List<OnmsIpInterface> matchingIfaces = getIpInterfaceDao().findMatching(criteria);
    return matchingIfaces.get(0).getIpAddress();
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria)

Example 12 with OnmsIpInterface

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

the class DefaultResourceDaoTest method createIpInterface.

private OnmsIpInterface createIpInterface() throws UnknownHostException {
    OnmsIpInterface ip = new OnmsIpInterface();
    ip.setIpAddress(InetAddressUtils.addr("192.168.1.1"));
    return ip;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 13 with OnmsIpInterface

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

the class BasePersisterTest method setUp.

@Before
public void setUp() throws Exception {
    MockUtil.println("------------ Begin Test " + m_testName.getMethodName() + " --------------------------");
    MockLogAppender.setupLogging();
    m_fileAnticipator = new FileAnticipator();
    m_rrdStrategy = new JRobinRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
    m_intf = new OnmsIpInterface();
    m_node = new OnmsNode();
    m_node.setId(1);
    m_intf.setId(25);
    m_intf.setNode(m_node);
    m_intf.setIpAddress(InetAddressUtils.addr("1.1.1.1"));
    m_ifDao = m_easyMockUtils.createMock(IpInterfaceDao.class);
    m_serviceParams = new ServiceParameters(new HashMap<String, Object>());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) HashMap(java.util.HashMap) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) FileAnticipator(org.opennms.test.FileAnticipator) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Before(org.junit.Before)

Example 14 with OnmsIpInterface

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

the class PollerServiceTest method testPoll.

public void testPoll() throws EventProxyException {
    final int expectedPolldId = 7;
    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);
    final OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    m_eventProxy.send(isA(Event.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            Event event = (Event) getCurrentArguments()[0];
            assertEquals("Incorrect uei for demandPollService event", EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI, event.getUei());
            assertEquals("Incorrect nodeid for demandPollService event", monSvc.getNodeId().longValue(), event.getNodeid().longValue());
            assertEquals("Incorrect ipadr for demandPollService event", InetAddressUtils.str(monSvc.getIpAddress()), event.getInterface());
            assertEquals("Incorrect ifIndex for demandPollService event", monSvc.getIfIndex(), Integer.valueOf(event.getIfIndex()));
            assertEquals("Incorrect service for demandPollService event", monSvc.getServiceType().getName(), event.getService());
            EventUtils.requireParm(event, EventConstants.PARM_DEMAND_POLL_ID);
            assertEquals(expectedPolldId, EventUtils.getIntParm(event, EventConstants.PARM_DEMAND_POLL_ID, -1));
            return null;
        }
    });
    replay(m_eventProxy);
    m_pollerService.poll(monSvc, expectedPolldId);
    verify(m_eventProxy);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Event(org.opennms.netmgt.xml.event.Event) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 15 with OnmsIpInterface

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

the class DaoWebOutageRepositoryIT method createNodeEventAndOutage.

protected void createNodeEventAndOutage(String location, String label, String ip, String svc) {
    OnmsMonitoringLocation onmsMonitoringLocation = m_dbPopulator.getMonitoringLocationDao().get(location);
    if (onmsMonitoringLocation == null) {
        onmsMonitoringLocation = new OnmsMonitoringLocation();
        onmsMonitoringLocation.setLocationName(location);
        onmsMonitoringLocation.setLatitude(1.0f);
        onmsMonitoringLocation.setLongitude(1.0f);
        onmsMonitoringLocation.setMonitoringArea(location);
        onmsMonitoringLocation.setPriority(1L);
        m_dbPopulator.getMonitoringLocationDao().save(onmsMonitoringLocation);
    }
    List<OnmsNode> nodes = m_dbPopulator.getNodeDao().findByLabel(label);
    OnmsNode node = (nodes.size() == 1 ? nodes.get(0) : null);
    if (node == null) {
        node = new OnmsNode(m_dbPopulator.getMonitoringLocationDao().get(location), label);
        node.setForeignSource(location);
        node.setForeignId(label);
        m_dbPopulator.getNodeDao().save(node);
    }
    int nodeId = m_dbPopulator.getNodeDao().findByForeignId(location, label).getId();
    OnmsIpInterface ipInterface = m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip);
    if (ipInterface == null) {
        ipInterface = new OnmsIpInterface(addr(ip), node);
    }
    OnmsMonitoredService monitoredService = ipInterface.getMonitoredServiceByServiceType(svc);
    if (monitoredService == null) {
        monitoredService = new OnmsMonitoredService(m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip), m_dbPopulator.getServiceTypeDao().findByName(svc));
        m_dbPopulator.getMonitoredServiceDao().save(monitoredService);
    }
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
    event.setEventUei("uei.opennms.org/" + location + "/" + label);
    event.setEventTime(new Date());
    event.setEventSource(location + "/" + label);
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.CLEARED.getId());
    event.setEventLog("Y");
    event.setEventDisplay("N");
    m_dbPopulator.getEventDao().save(event);
    m_dbPopulator.getEventDao().flush();
    OnmsOutage outage = new OnmsOutage(new Date(), event, monitoredService);
    outage.setServiceLostEvent(event);
    m_dbPopulator.getOutageDao().save(outage);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11