Search in sources :

Example 51 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 52 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)

Example 53 with OnmsSnmpInterface

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

the class InsAbstractSession method getIfAlias.

/**
     * @param nodeid
     * @param ifindex
     * @return
     */
protected String getIfAlias(final int nodeid, final int ifindex) {
    LOG.debug("getting ifalias for nodeid: {} and ifindex: {}", nodeid, ifindex);
    setCriteria("nodeid = " + nodeid + " AND snmpifindex = " + ifindex);
    BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
    final SnmpInterfaceDao snmpInterfaceDao = BeanUtils.getBean(bf, "snmpInterfaceDao", SnmpInterfaceDao.class);
    final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
    final OnmsSnmpInterface iface = transTemplate.execute(new TransactionCallback<OnmsSnmpInterface>() {

        public OnmsSnmpInterface doInTransaction(final TransactionStatus status) {
            return snmpInterfaceDao.findByNodeIdAndIfIndex(nodeid, ifindex);
        }
    });
    if (iface == null) {
        return "-1";
    } else {
        final String ifAlias = iface.getIfAlias();
        LOG.debug("ifalias found: {}", ifAlias);
        return ifAlias;
    }
}
Also used : BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) TransactionStatus(org.springframework.transaction.TransactionStatus)

Example 54 with OnmsSnmpInterface

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

the class SnmpCollectorITCase method createAgent.

protected void createAgent(int ifIndex, PrimaryType ifCollType) {
    m_node = new OnmsNode();
    m_node.setSysObjectId(".1.2.3.4.5.6.7");
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(m_node, ifIndex);
    m_iface = new OnmsIpInterface();
    m_iface.setId(123);
    m_iface.setIpAddress(myLocalHost());
    m_iface.setIsSnmpPrimary(ifCollType);
    m_iface.setSnmpInterface(snmpIface);
    m_node.addIpInterface(m_iface);
    EasyMock.expect(m_ifaceDao.load(m_iface.getId())).andReturn(m_iface).anyTimes();
    m_easyMockUtils.replayAll();
    m_agent = DefaultCollectionAgent.create(m_iface.getId(), m_ifaceDao, new MockPlatformTransactionManager());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager)

Example 55 with OnmsSnmpInterface

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

the class SnmpIfCollectorIT method createSnmpInterface.

private OnmsEntity createSnmpInterface(final int ifIndex, final int ifType, final String ifName, final boolean collectionEnabled) {
    final OnmsSnmpInterface m_snmpIface = new OnmsSnmpInterface();
    m_snmpIface.setIfIndex(ifIndex);
    m_snmpIface.setIfType(ifType);
    m_snmpIface.setIfName(ifName);
    m_snmpIface.setCollectionEnabled(collectionEnabled);
    m_node.addSnmpInterface(m_snmpIface);
    return m_snmpIface;
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Aggregations

OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)65 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)34 OnmsNode (org.opennms.netmgt.model.OnmsNode)30 Test (org.junit.Test)14 InetAddress (java.net.InetAddress)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)7 Transactional (org.springframework.transaction.annotation.Transactional)6 LinkedList (java.util.LinkedList)5 LinkedHashSet (java.util.LinkedHashSet)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)4 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Before (org.junit.Before)3 IpNetToMedia (org.opennms.netmgt.model.IpNetToMedia)3 BufferedReader (java.io.BufferedReader)2