Search in sources :

Example 36 with OnmsSnmpInterface

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

the class IpAddrTable method updateIpInterfaceData.

/**
 * <p>updateIpInterfaceData</p>
 *
 * @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
 * @param ipAddr a {@link java.lang.String} object.
 */
public void updateIpInterfaceData(OnmsNode node, String ipAddr) {
    OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
    if (ipIf == null) {
        ipIf = new OnmsIpInterface(ipAddr, node);
    }
    InetAddress inetAddr = ipIf.getIpAddress();
    Integer ifIndex = getIfIndex(inetAddr);
    // if we've found an ifIndex for this interface
    if (ifIndex != null) {
        // first look to see if an snmpIf was created already
        OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);
        if (snmpIf == null) {
            // if not then create one
            snmpIf = new OnmsSnmpInterface(node, ifIndex);
        }
        final InetAddress mask = getNetMask(inetAddr);
        if (mask != null) {
            ipIf.setNetMask(mask);
        }
        snmpIf.setCollectionEnabled(true);
        ipIf.setSnmpInterface(snmpIf);
    }
    ipIf.setIpHostName(ipAddr);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) InetAddress(java.net.InetAddress)

Example 37 with OnmsSnmpInterface

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

the class IpAddressTable method updateIpInterfaceData.

/**
 * <p>updateIpInterfaceData</p>
 *
 * @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
 * @param ipAddr a {@link java.lang.String} object.
 */
public void updateIpInterfaceData(final OnmsNode node, final String ipAddr) {
    OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
    if (ipIf == null) {
        ipIf = new OnmsIpInterface(ipAddr, node);
    }
    final InetAddress inetAddr = ipIf.getIpAddress();
    final Integer ifIndex = getIfIndex(inetAddr);
    // if we've found an ifIndex for this interface
    if (ifIndex != null) {
        // first look to see if an snmpIf was created already
        OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);
        if (snmpIf == null) {
            // if not then create one
            snmpIf = new OnmsSnmpInterface(node, ifIndex);
        }
        final InetAddress mask = getNetMask(inetAddr);
        if (mask != null) {
            ipIf.setNetMask(mask);
        }
        snmpIf.setCollectionEnabled(true);
        ipIf.setSnmpInterface(snmpIf);
    }
    ipIf.setIpHostName(ipAddr);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) InetAddress(java.net.InetAddress)

Example 38 with OnmsSnmpInterface

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

the class DefaultNodeListService method createModelForNodes.

private static NodeListModel createModelForNodes(NodeListCommand command, Collection<OnmsNode> onmsNodes) {
    int interfaceCount = 0;
    List<NodeModel> displayNodes = new LinkedList<>();
    for (OnmsNode node : onmsNodes) {
        List<OnmsIpInterface> displayInterfaces = new LinkedList<>();
        List<OnmsSnmpInterface> displaySnmpInterfaces = new LinkedList<>();
        if (command.getListInterfaces()) {
            if (command.hasSnmpParm() && command.getSnmpParmMatchType().equals("contains")) {
                String parmValueMatchString = (".*" + command.getSnmpParmValue().toLowerCase().replaceAll("([\\W])", "\\\\$0").replaceAll("\\\\%", ".*").replaceAll("_", ".") + ".*");
                if (command.getSnmpParm().equals("ifAlias")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfAlias() != null && snmpIntf.getIfAlias().toLowerCase().matches(parmValueMatchString)) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifName")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfName() != null && snmpIntf.getIfName().toLowerCase().matches(parmValueMatchString)) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifDescr")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfDescr() != null && snmpIntf.getIfDescr().toLowerCase().matches(parmValueMatchString)) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                }
            } else if (command.hasSnmpParm() && command.getSnmpParmMatchType().equals("equals")) {
                if (command.getSnmpParm().equals("ifAlias")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfAlias() != null && snmpIntf.getIfAlias().equalsIgnoreCase(command.getSnmpParmValue())) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifName")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfName() != null && snmpIntf.getIfName().equalsIgnoreCase(command.getSnmpParmValue())) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                } else if (command.getSnmpParm().equals("ifDescr")) {
                    for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                        if (snmpIntf != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getIfDescr() != null && snmpIntf.getIfDescr().equalsIgnoreCase(command.getSnmpParmValue())) {
                            displaySnmpInterfaces.add(snmpIntf);
                        }
                    }
                }
            } else if (command.hasMaclike()) {
                String macLikeStripped = command.getMaclike().toLowerCase().replaceAll("[:-]", "");
                for (OnmsSnmpInterface snmpIntf : node.getSnmpInterfaces()) {
                    if (snmpIntf.getPhysAddr() != null && !"D".equals(snmpIntf.getCollect()) && snmpIntf.getPhysAddr().toLowerCase().contains(macLikeStripped)) {
                        displaySnmpInterfaces.add(snmpIntf);
                    }
                }
            } else {
                for (OnmsIpInterface intf : node.getIpInterfaces()) {
                    if (!"D".equals(intf.getIsManaged()) && !"0.0.0.0".equals(InetAddressUtils.str(intf.getIpAddress()))) {
                        displayInterfaces.add(intf);
                    }
                }
            }
        }
        Collections.sort(displayInterfaces, IP_INTERFACE_COMPARATOR);
        Collections.sort(displaySnmpInterfaces, SNMP_INTERFACE_COMPARATOR);
        displayNodes.add(new NodeListModel.NodeModel(node, displayInterfaces, displaySnmpInterfaces));
        interfaceCount += displayInterfaces.size();
        interfaceCount += displaySnmpInterfaces.size();
    }
    return new NodeListModel(displayNodes, interfaceCount);
}
Also used : NodeModel(org.opennms.web.svclayer.model.NodeListModel.NodeModel) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) NodeModel(org.opennms.web.svclayer.model.NodeListModel.NodeModel) NodeListModel(org.opennms.web.svclayer.model.NodeListModel) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) LinkedList(java.util.LinkedList)

Example 39 with OnmsSnmpInterface

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

the class PollContextIT method testCriterias.

/*
     * This test has been designed to verify the workaround for using the IP address on the SNMP
     * Interface based Criteria, because in 1.8, the ipaddr was a valid column of the snmpinterface
     * table, and that column has been removed in order to promote the usage of the ipinterface table.
     */
@Test
public void testCriterias() throws Exception {
    Assert.assertNotNull(m_pollContext);
    OnmsNode node = m_nodeDao.findByForeignId("linkd", "cisco2691");
    Assert.assertNotNull(node);
    List<OnmsIpInterface> ipInterfaces = m_pollContext.getPollableNodes();
    Assert.assertNotNull(ipInterfaces);
    Assert.assertEquals(2, ipInterfaces.size());
    // Primary Interface
    ipInterfaces = m_pollContext.getPollableNodesByIp("10.1.4.2");
    Assert.assertNotNull(ipInterfaces);
    Assert.assertEquals(1, ipInterfaces.size());
    // Secondary Interface
    ipInterfaces = m_pollContext.getPollableNodesByIp("10.1.5.1");
    Assert.assertNotNull(ipInterfaces);
    Assert.assertEquals(0, ipInterfaces.size());
    // Because the criteria is an SQL restriction, the access to ipinterface table is through the
    // internal alias created by hibernate, in this case ipinterfac1_.
    String criteria = "snmpifdescr like '%Ethernet%' and ipinterfac1_.ipaddr like '10.1.5.%'";
    List<OnmsSnmpInterface> snmpInterfaces = m_pollContext.get(node.getId(), criteria);
    Assert.assertNotNull(snmpInterfaces);
    Assert.assertEquals(1, snmpInterfaces.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Test(org.junit.Test)

Example 40 with OnmsSnmpInterface

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

the class CollectionResourceWrapperIT method testInterfaceResource.

@Test
public void testInterfaceResource() throws Exception {
    // Set Defaults
    String ipAddress = "10.0.0.1";
    String ifName = "eth0";
    int ifIndex = 2;
    // Initialize Database
    MockNetwork network = new MockNetwork();
    network.setCriticalService("ICMP");
    network.addNode(1, "testNode");
    network.addInterface(ipAddress);
    network.setIfAlias(ifName);
    network.setIfIndex(ifIndex);
    network.addService("ICMP");
    network.addService("SNMP");
    network.addService("HTTP");
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    // Create Mock Collection Agent
    SnmpCollectionAgent agent = createCollectionAgent();
    // Create SnmpIfData
    OnmsNode node = new OnmsNode();
    node.setId(agent.getNodeId());
    node.setLabel("testNode");
    node.setForeignSource(agent.getForeignSource());
    node.setForeignId(agent.getForeignId());
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, ifIndex);
    snmpIface.setIfDescr(ifName);
    snmpIface.setIfName(ifName);
    snmpIface.setIfAlias(ifName);
    snmpIface.setIfSpeed(10000000l);
    snmpIface.setPhysAddr("001122334455");
    SnmpIfData ifData = new SnmpIfData(snmpIface);
    // Creating IfResourceType
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    IfResourceType resourceType = new IfResourceType(agent, collection);
    // Creating Resource
    SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData);
    SnmpAttribute attribute = addAttributeToCollectionResource(resource, "ifInOctets", AttributeType.COUNTER, "ifIndex", "5000");
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    attributes.put(attribute.getName(), attribute);
    // Create Wrapper
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    // Validations
    Assert.assertEquals(node.getId().intValue(), wrapper.getNodeId());
    // Should be the address of the SNMP Agent (Bug 3808)
    Assert.assertEquals("127.0.0.1", wrapper.getHostAddress());
    Assert.assertEquals("eth0-001122334455", wrapper.getIfLabel());
    Assert.assertEquals("if", wrapper.getResourceTypeName());
    Assert.assertEquals("SNMP", wrapper.getServiceName());
    Assert.assertEquals(true, wrapper.isAnInterfaceResource());
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getInstance());
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
    // IfLabel is called only once
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
    // IfLabel is called only once
    Assert.assertEquals(Integer.toString(ifIndex), wrapper.getIfIndex());
    // IfLabel is called only once
    Assert.assertEquals("eth0", wrapper.getIfInfoValue("snmpifname"));
    Assert.assertEquals("eth0-001122334455", wrapper.getInstanceLabel());
    Assert.assertEquals("nodeSource[JUnit:T001].interfaceSnmp[eth0-001122334455]", wrapper.getResourceId().toString());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpIfData(org.opennms.netmgt.collectd.SnmpIfData) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) MockNetwork(org.opennms.netmgt.mock.MockNetwork) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) MockDatabase(org.opennms.core.test.db.MockDatabase) IfInfo(org.opennms.netmgt.collectd.IfInfo) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) Test(org.junit.Test)

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