Search in sources :

Example 81 with OnmsIpInterface

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

the class PersistRegexSelectorStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
    String localhost = InetAddress.getLocalHost().getHostAddress();
    NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("myNode");
    builder.addInterface(localhost).setIsManaged("M").setIsSnmpPrimary("P");
    OnmsNode node = builder.getCurrentNode();
    node.setId(1);
    OnmsIpInterface ipInterface = node.getIpInterfaces().iterator().next();
    EasyMock.expect(ipInterfaceDao.load(1)).andReturn(ipInterface).anyTimes();
    EasyMock.replay(ipInterfaceDao);
    Package pkg = new Package();
    pkg.setName("junitTestPackage");
    Filter filter = new Filter();
    filter.setContent("IPADDR != '0.0.0.0'");
    pkg.setFilter(filter);
    Service service = new Service();
    service.setName("SNMP");
    pkg.addService(service);
    Map<String, Object> map = new TreeMap<String, Object>();
    List<org.opennms.netmgt.config.collectd.Parameter> params = pkg.getService("SNMP").getParameters();
    for (org.opennms.netmgt.config.collectd.Parameter p : params) {
        map.put(p.getKey(), p.getValue());
    }
    map.put("collection", "default");
    serviceParams = new ServiceParameters(map);
    LocationAwareSnmpClient locationAwareSnmpClient = new LocationAwareSnmpClientRpcImpl(new MockRpcClientFactory());
    PlatformTransactionManager ptm = new MockPlatformTransactionManager();
    SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(1, ipInterfaceDao, ptm);
    OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, serviceParams, new MockDataCollectionConfigDao(), locationAwareSnmpClient);
    org.opennms.netmgt.config.datacollection.ResourceType rt = new org.opennms.netmgt.config.datacollection.ResourceType();
    rt.setName("myResourceType");
    StorageStrategy storageStrategy = new StorageStrategy();
    storageStrategy.setClazz("org.opennms.netmgt.collection.support.IndexStorageStrategy");
    rt.setStorageStrategy(storageStrategy);
    PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
    persistenceSelectorStrategy.setClazz("org.opennms.netmgt.collectd.PersistRegexSelectorStrategy");
    Parameter param = new Parameter();
    param.setKey(PersistRegexSelectorStrategy.MATCH_EXPRESSION);
    param.setValue("#name matches '^agalue.*$'");
    persistenceSelectorStrategy.addParameter(param);
    rt.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
    GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, snmpCollection, rt);
    resourceA = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.1"));
    AttributeGroupType groupType = new AttributeGroupType("mib2-interfaces", AttributeGroupType.IF_TYPE_ALL);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.2.3.4.5.6.7.8.9.2.1");
    mibObject.setInstance("1");
    mibObject.setAlias("name");
    mibObject.setType("string");
    StringAttributeType attributeType = new StringAttributeType(resourceType, snmpCollection.getName(), mibObject, groupType);
    SnmpValue snmpValue = new Snmp4JValueFactory().getOctetString("agalue rules!".getBytes());
    resourceA.setAttributeValue(attributeType, snmpValue);
    resourceB = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.2"));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) Snmp4JValueFactory(org.opennms.netmgt.snmp.snmp4j.Snmp4JValueFactory) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) LocationAwareSnmpClientRpcImpl(org.opennms.netmgt.snmp.proxy.common.LocationAwareSnmpClientRpcImpl) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) MockDataCollectionConfigDao(org.opennms.netmgt.dao.mock.MockDataCollectionConfigDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) Service(org.opennms.netmgt.config.collectd.Service) TreeMap(java.util.TreeMap) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) MockRpcClientFactory(org.opennms.core.rpc.mock.MockRpcClientFactory) LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Filter(org.opennms.netmgt.config.collectd.Filter) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Parameter(org.opennms.netmgt.config.datacollection.Parameter) MibObject(org.opennms.netmgt.config.datacollection.MibObject) Package(org.opennms.netmgt.config.collectd.Package) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Before(org.junit.Before)

Example 82 with OnmsIpInterface

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

the class SnmpCollectorIT method setUp.

@Before
public void setUp() throws Exception {
    MockServiceCollector.setDelegate(null);
    MockLogAppender.setupLogging();
    m_rrdStrategy = new JRobinRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
    m_resourceStorageDao.setRrdDirectory(snmpRrdDirectory.getParentFile());
    m_testHostName = InetAddressUtils.str(InetAddress.getLocalHost());
    OnmsIpInterface iface = null;
    OnmsNode testNode = null;
    Collection<OnmsNode> testNodes = m_nodeDao.findByLabel(TEST_NODE_LABEL);
    if (testNodes == null || testNodes.size() < 1) {
        NetworkBuilder builder = new NetworkBuilder();
        builder.addNode(TEST_NODE_LABEL).setId(1).setSysObjectId(".1.3.6.1.4.1.1588.2.1.1.1");
        builder.addSnmpInterface(1).setIfName("lo0").setPhysAddr("00:11:22:33:44");
        builder.addSnmpInterface(2).setIfName("gif0").setPhysAddr("00:11:22:33:45").setIfType(55);
        builder.addSnmpInterface(3).setIfName("stf0").setPhysAddr("00:11:22:33:46").setIfType(57);
        builder.addSnmpInterface(6).setIfName("fw0").setPhysAddr("44:33:22:11:00").setIfType(144).setCollectionEnabled(true).addIpInterface(m_testHostName).setIsSnmpPrimary("P");
        testNode = builder.getCurrentNode();
        assertNotNull(testNode);
        m_nodeDao.save(testNode);
        m_nodeDao.flush();
    } else {
        testNode = testNodes.iterator().next();
    }
    Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
    assertEquals(1, ifaces.size());
    iface = ifaces.iterator().next();
    SnmpPeerFactory.setInstance(m_snmpPeerFactory);
    SnmpCollector collector = new SnmpCollector();
    collector.initialize();
    m_collectionSpecification = CollectorTestUtils.createCollectionSpec("SNMP", collector, "default");
    m_collectionAgent = DefaultSnmpCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
    m_agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.getLocalHostAddress());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) File(java.io.File) Before(org.junit.Before)

Example 83 with OnmsIpInterface

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

the class DefaultCategoryStatusServiceTest method testGetCategoriesStatus.

public void testGetCategoriesStatus() {
    View view = new View();
    Section section = new Section();
    section.setSectionName("Section One");
    section.addCategory("Category One");
    OnmsOutage outage = new OnmsOutage();
    Collection<OnmsOutage> outages = new ArrayList<>();
    outage.setId(300);
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("superLabel");
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    // iface.setId(9);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    outage.setMonitoredService(monSvc);
    outages.add(outage);
    view.addSection(section);
    List<String> services = new ArrayList<>();
    services.add("HTTP");
    // ServiceSelector selector = new ServiceSelector("isHTTP",(List<String>) services);
    expect(viewDisplayDao.getView()).andReturn(view);
    expect(categoryDao.getCategoryByLabel("Category One")).andReturn(createCategoryFromLabel("Category One"));
    expect(outageDao.matchingCurrentOutages(isA(ServiceSelector.class))).andReturn(outages);
    replay(categoryDao);
    replay(viewDisplayDao);
    replay(outageDao);
    Collection<StatusSection> statusSections = categoryStatusService.getCategoriesStatus();
    verify(viewDisplayDao);
    verify(categoryDao);
    verify(outageDao);
    assertEquals("Wrong Number of StatusSections", view.getSections().size(), statusSections.size());
    for (StatusSection statusSection : statusSections) {
        assertEquals("StatusSection Name Does Not Match", "Section One", statusSection.getName());
        Collection<StatusCategory> statusCategorys = statusSection.getCategories();
        for (StatusCategory statusCategory : statusCategorys) {
            assertEquals("StatusCategoryName does not match", "Category One", statusCategory.getLabel());
            // assertEquals("Category Comment Does not match","Category One Comment",statusCategory.getComment());
            assertTrue("Nodes >= 1", statusCategory.getNodes().size() >= 1);
            for (StatusNode statusNode : statusCategory.getNodes()) {
                assertEquals("Label does not match", "superLabel", statusNode.getLabel());
            }
        }
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) StatusNode(org.opennms.web.svclayer.catstatus.model.StatusNode) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) ArrayList(java.util.ArrayList) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) View(org.opennms.netmgt.config.viewsdisplay.View) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) Section(org.opennms.netmgt.config.viewsdisplay.Section) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) StatusCategory(org.opennms.web.svclayer.catstatus.model.StatusCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType)

Example 84 with OnmsIpInterface

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

the class DefaultCategoryStatusService method createCategory.

private StatusCategory createCategory(String category) {
    Collection<OnmsOutage> outages;
    CategoryBuilder categoryBuilder = new CategoryBuilder();
    StatusCategory statusCategory = new StatusCategory();
    Category categoryDetail = m_categoryConfigDao.getCategoryByLabel(category);
    // statusCategory.setComment(categoryDetail.getCategoryComment());
    statusCategory.setLabel(category);
    ServiceSelector selector = new ServiceSelector(categoryDetail.getRule(), getServicesForCategory(categoryDetail));
    outages = m_outageDao.matchingCurrentOutages(selector);
    for (OnmsOutage outage : outages) {
        OnmsMonitoredService monitoredService = outage.getMonitoredService();
        OnmsServiceType serviceType = monitoredService.getServiceType();
        OnmsIpInterface ipInterface = monitoredService.getIpInterface();
        final String ipAddress = InetAddressUtils.str(ipInterface.getIpAddress());
        categoryBuilder.addOutageService(monitoredService.getNodeId(), ipAddress, ipAddress, ipInterface.getNode().getLabel(), serviceType.getName());
    }
    for (StatusNode node : categoryBuilder.getNodes()) {
        statusCategory.addNode(node);
    }
    return statusCategory;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) StatusCategory(org.opennms.web.svclayer.catstatus.model.StatusCategory) Category(org.opennms.netmgt.config.categories.Category) StatusCategory(org.opennms.web.svclayer.catstatus.model.StatusCategory) StatusNode(org.opennms.web.svclayer.catstatus.model.StatusNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 85 with OnmsIpInterface

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

the class NetworkElementFactory method getInterfaceArrayWithSnmpData.

private Interface[] getInterfaceArrayWithSnmpData(List<OnmsIpInterface> ipIfaces) {
    List<Interface> intfs = new LinkedList<>();
    for (OnmsIpInterface iface : ipIfaces) {
        Interface intf = new Interface(iface);
        if (iface.getSnmpInterface() != null) {
            OnmsSnmpInterface snmpIface = iface.getSnmpInterface();
            intf.createSnmpInterface(snmpIface);
        }
        intfs.add(intf);
    }
    Collections.sort(intfs, INTERFACE_COMPARATOR);
    return intfs.toArray(new Interface[intfs.size()]);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) LinkedList(java.util.LinkedList)

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