Search in sources :

Example 51 with OnmsIpInterface

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

the class InterfaceSnmpResourceType method getNodeResources.

private List<OnmsResource> getNodeResources(ResourcePath parent, Set<String> intfNames, OnmsNode node) {
    ArrayList<OnmsResource> resources = new ArrayList<>();
    Set<OnmsSnmpInterface> snmpInterfaces = node.getSnmpInterfaces();
    Map<String, OnmsSnmpInterface> intfMap = new HashMap<String, OnmsSnmpInterface>();
    for (OnmsSnmpInterface snmpInterface : snmpInterfaces) {
        for (String key : getKeysFor(snmpInterface)) {
            if (!intfMap.containsKey(key)) {
                intfMap.put(key, snmpInterface);
            }
        }
    }
    for (String intfName : intfNames) {
        String key = getKeyFor(intfName);
        OnmsSnmpInterface snmpInterface = intfMap.get(key);
        String label;
        Long ifSpeed = null;
        String ifSpeedFriendly = null;
        if (snmpInterface == null) {
            label = intfName + " (*)";
        } else {
            final StringBuilder descr = new StringBuilder();
            final StringBuilder parenString = new StringBuilder();
            if (snmpInterface.getIfAlias() != null) {
                parenString.append(snmpInterface.getIfAlias());
            }
            // Append all of the IP addresses on this ifindex
            for (OnmsIpInterface ipif : snmpInterface.getIpInterfaces()) {
                String ipaddr = InetAddressUtils.str(ipif.getIpAddress());
                if (!"0.0.0.0".equals(ipaddr)) {
                    if (parenString.length() > 0) {
                        parenString.append(", ");
                    }
                    parenString.append(ipaddr);
                }
            }
            if ((snmpInterface.getIfSpeed() != null) && (snmpInterface.getIfSpeed() != 0)) {
                ifSpeed = snmpInterface.getIfSpeed();
                ifSpeedFriendly = SIUtils.getHumanReadableIfSpeed(ifSpeed);
                if (parenString.length() > 0) {
                    parenString.append(", ");
                }
                parenString.append(ifSpeedFriendly);
            }
            if (snmpInterface.getIfName() != null) {
                descr.append(snmpInterface.getIfName());
            } else if (snmpInterface.getIfDescr() != null) {
                descr.append(snmpInterface.getIfDescr());
            } else {
                /*
                     * Should never reach this point, since ifLabel is based on
                     * the values of ifName and ifDescr but better safe than sorry.
                     */
                descr.append(intfName);
            }
            /* Add the extended information in parenthesis after the ifLabel,
                 * if such information was found.
                 */
            if (parenString.length() > 0) {
                descr.append(" (");
                descr.append(parenString);
                descr.append(")");
            }
            label = descr.toString();
        }
        OnmsResource resource = getResourceByParentPathAndInterface(parent, intfName, label, ifSpeed, ifSpeedFriendly);
        if (snmpInterface != null) {
            Set<OnmsIpInterface> ipInterfaces = snmpInterface.getIpInterfaces();
            if (ipInterfaces.size() > 0) {
                int id = ipInterfaces.iterator().next().getId();
                resource.setLink("element/interface.jsp?ipinterfaceid=" + id);
            } else {
                int ifIndex = snmpInterface.getIfIndex();
                if (ifIndex > -1) {
                    resource.setLink("element/snmpinterface.jsp?node=" + node.getNodeId() + "&ifindex=" + ifIndex);
                }
            }
            resource.setEntity(snmpInterface);
        } else {
            LOG.debug("populateResourceList: snmpInterface is null");
        }
        LOG.debug("populateResourceList: adding resource toString {}", resource.toString());
        resources.add(resource);
    }
    return resources;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 52 with OnmsIpInterface

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

the class AvailabilityDatabasePopulatorIT method testAvailabilityDatabase.

/**
 * @throws Exception
 */
@Test
@Transactional
public void testAvailabilityDatabase() throws Exception {
    List<OnmsNode> nodes = m_nodeDao.findAll();
    for (OnmsNode node : nodes) {
        m_nodeDao.initialize(node);
        // TODO: Is this necessary?
        m_nodeDao.initialize(node.getLocation());
    }
    for (OnmsNode node : nodes) {
        System.err.println("NODE " + node.toString());
    }
    List<OnmsIpInterface> ifs = m_ipInterfaceDao.findAll();
    for (OnmsIpInterface iface : ifs) {
        System.err.println("INTERFACE " + iface.toString());
    }
    Assert.assertEquals("node DB count", 2, m_nodeDao.countAll());
    Assert.assertEquals("service DB count", 3, m_serviceTypeDao.countAll());
    Assert.assertEquals("IP interface DB count", 3, m_ipInterfaceDao.countAll());
    Assert.assertEquals("outages DB Count", 6, m_outageDao.countAll());
    final OnmsIpInterface oneHundredDotOne = m_ipInterfaceDao.findByNodeIdAndIpAddress(1, "192.168.100.1");
    try {
        List<OnmsMonitoredService> stmt = m_template.query("SELECT ifServices.serviceid, service.servicename FROM ifServices, ipInterface, node, service WHERE ifServices.ipInterfaceId = ipInterface.id AND ipInterface.nodeId = node.nodeId " + "AND ipinterface.ipaddr = '192.168.100.1' AND ipinterface.isManaged ='M' AND " + "ifServices.serviceid = service.serviceid AND ifservices.status = 'A' AND node.nodeid = 1 AND node.nodetype = 'A'", new RowMapper<OnmsMonitoredService>() {

            @Override
            public OnmsMonitoredService mapRow(ResultSet rs, int rowNum) throws SQLException {
                OnmsMonitoredService retval = new OnmsMonitoredService(oneHundredDotOne, m_serviceTypeDao.findByName(rs.getString("servicename")));
                return retval;
            }
        });
        // ResultSet srs = stmt.executeQuery("SELECT ipInterface.ipaddr, ipInterface.nodeid FROM ipInterface WHERE ipInterface.ipaddr = '192.168.100.1'" );
        Assert.assertTrue("interface results for 192.168.100.2", stmt.size() > 0);
        Assert.assertEquals(new Integer(1), stmt.get(0).getServiceId());
    } catch (Exception e) {
        LOG.error("unable to execute SQL", e);
        throw e;
    }
/*
		Assert.assertEquals("node DB count", 2, m_db.countRows("select * from node"));
		Assert.assertEquals("service DB count", 3,
				m_db.countRows("select * from service"));
		Assert.assertEquals("ipinterface DB count", 3,
				m_db.countRows("select * from ipinterface"));
		Assert.assertEquals("interface services DB count", 3,
				m_db.countRows("select * from ifservices"));
		// Assert.assertEquals("outages DB count", 3, m_db.countRows("select * from
		// outages"));
		Assert.assertEquals(
				"ip interface DB count where ipaddr = 192.168.100.1",
				1,
				m_db.countRows("select * from ipinterface where ipaddr = '192.168.100.1'"));
		Assert.assertEquals(
				"number of interfaces returned from IPLIKE",
				3,
				m_db.countRows("select * from ipinterface where iplike(ipaddr,'192.168.100.*')"));
		 */
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ResultSet(java.sql.ResultSet) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with OnmsIpInterface

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

the class PollerBackEndTest method testSaveResponseTimeDataWithLocaleThatUsesCommasForDecimals.

public void testSaveResponseTimeDataWithLocaleThatUsesCommasForDecimals() throws Exception {
    Properties p = new Properties();
    p.setProperty("org.opennms.netmgt.ConfigFileConstants", "ERROR");
    MockLogAppender.setupLogging(p);
    Locale.setDefault(Locale.FRENCH);
    // Make sure we actually have a valid test
    NumberFormat nf = NumberFormat.getInstance();
    assertEquals("ensure that the newly set default locale (" + Locale.getDefault() + ") uses ',' as the decimal marker", "1,5", nf.format(1.5));
    OnmsMonitoredService svc = new OnmsMonitoredService();
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setName("HTTP");
    svc.setServiceType(svcType);
    OnmsIpInterface intf = new OnmsIpInterface();
    intf.setIpAddress(InetAddressUtils.addr("1.2.3.4"));
    svc.setIpInterface(intf);
    Package pkg = new Package();
    Service pkgService = new Service();
    pkgService.setName("HTTP");
    addParameterToService(pkgService, "ds-name", "http");
    addParameterToService(pkgService, "rrd-repository", "/foo");
    pkg.addService(pkgService);
    Rrd rrd = new Rrd();
    rrd.setStep(300);
    rrd.addRra("bogusRRA");
    pkg.setRrd(rrd);
    // TODO: Figure out why these mock calls aren't being invoked
    // expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object());
    // m_rrdStrategy.createFile(isA(Object.class));
    // expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object());
    // m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), endsWith(":1.5"));
    // m_rrdStrategy.closeFile(isA(Object.class));
    expect(m_pollerConfig.getServiceInPackage("HTTP", pkg)).andReturn(m_httpSvcConfig);
    expect(m_pollerConfig.parameters(m_httpSvcConfig)).andReturn(m_httpSvcConfig.getParameters()).atLeastOnce();
    m_mocks.replayAll();
    m_backEnd.saveResponseTimeData("Tuvalu", svc, 1.5, pkg);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Rrd(org.opennms.netmgt.config.poller.Rrd) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Service(org.opennms.netmgt.config.poller.Service) Package(org.opennms.netmgt.config.poller.Package) Properties(java.util.Properties) NumberFormat(java.text.NumberFormat) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 54 with OnmsIpInterface

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

the class BSFNorthbounderIT method testNorthbounder.

/**
 * Test northbounder.
 *
 * @throws Exception the exception
 */
@Test
public void testNorthbounder() throws Exception {
    // Setup test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Servers-MacOS");
    node.setForeignId("1");
    node.setId(1);
    node.setLabel("my-test-server");
    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");
    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("my-test-server");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.getIpInterfaces().add(onmsIf);
    // Setup test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(100);
    onmsAlarm.setNode(node);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    OnmsEvent event = new OnmsEvent();
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
    onmsAlarm.setLastEvent(event);
    onmsAlarm.setLogMsg("Test log message");
    onmsAlarm.setDescription("Test description");
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(2, alarm.getEventParametersCollection().size());
    Assert.assertTrue(nbi.accepts(alarm));
    nbi.forwardAlarms(Lists.newArrayList(alarm));
    nbi.stop();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 55 with OnmsIpInterface

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

the class DroolsNorthbounderIT method testNorthbounder.

/**
 * Test northbounder.
 *
 * @throws Exception the exception
 */
@Test
public void testNorthbounder() throws Exception {
    // Setup test node
    OnmsNode node = new OnmsNode();
    node.setForeignSource("Servers-MacOS");
    node.setForeignId("1");
    node.setId(1);
    node.setLabel("my-test-server");
    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");
    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("my-test-server");
    onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
    node.getIpInterfaces().add(onmsIf);
    // Setup test alarm
    OnmsAlarm onmsAlarm = new OnmsAlarm();
    onmsAlarm.setId(100);
    onmsAlarm.setNode(node);
    onmsAlarm.setIpAddr(address);
    onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
    OnmsEvent event = new OnmsEvent();
    event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "alarmId", "10", "Int32"), new OnmsEventParameter(event, "alarmMessage", "this is a test", "string")));
    onmsAlarm.setLastEvent(event);
    onmsAlarm.setLogMsg("Test log message");
    onmsAlarm.setDescription("Test description");
    NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
    Assert.assertEquals(2, alarm.getEventParametersCollection().size());
    Assert.assertTrue(nbi.accepts(alarm));
    nbi.forwardAlarms(Lists.newArrayList(alarm));
    nbi.stop();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) InetAddress(java.net.InetAddress) Test(org.junit.Test)

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