Search in sources :

Example 1 with JdbcFilterDao

use of org.opennms.netmgt.filter.JdbcFilterDao in project opennms by OpenNMS.

the class JdbcFilterDaoIT method testAfterPropertiesSetNoNodeDao.

@Test
public void testAfterPropertiesSetNoNodeDao() throws Exception {
    JdbcFilterDao dao = new JdbcFilterDao();
    dao.setDataSource(m_dataSource);
    InputStream is = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml");
    dao.setDatabaseSchemaConfigFactory(new DatabaseSchemaConfigFactory(is));
    is.close();
    // The nodeDao isn't required because this ends up getting used outside of a Spring context quite a bit
    dao.afterPropertiesSet();
}
Also used : InputStream(java.io.InputStream) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) Test(org.junit.Test)

Example 2 with JdbcFilterDao

use of org.opennms.netmgt.filter.JdbcFilterDao in project opennms by OpenNMS.

the class JdbcFilterDaoIT method testAfterPropertiesSetNoSchemaFactory.

@Test
public void testAfterPropertiesSetNoSchemaFactory() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    JdbcFilterDao dao = new JdbcFilterDao();
    dao.setDataSource(m_dataSource);
    ta.anticipate(new IllegalStateException("property databaseSchemaConfigFactory cannot be null"));
    try {
        dao.afterPropertiesSet();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) Test(org.junit.Test)

Example 3 with JdbcFilterDao

use of org.opennms.netmgt.filter.JdbcFilterDao in project opennms by OpenNMS.

the class NotificationManagerIT method setUp.

@Before
public void setUp() throws Exception {
    // Initialize Filter DAO
    DatabaseSchemaConfigFactory.init();
    JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
    jdbcFilterDao.setDataSource(m_dataSource);
    jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
    jdbcFilterDao.afterPropertiesSet();
    FilterDaoFactory.setInstance(jdbcFilterDao);
    m_configManager = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
    m_notificationManager = new NotificationManagerImpl(m_configManager, m_dataSource);
    OnmsNode node;
    OnmsIpInterface ipInterface;
    OnmsMonitoredService service;
    OnmsServiceType serviceType;
    OnmsCategory category1 = new OnmsCategory("CategoryOne");
    m_categoryDao.save(category1);
    OnmsCategory category2 = new OnmsCategory("CategoryTwo");
    m_categoryDao.save(category2);
    OnmsCategory category3 = new OnmsCategory("CategoryThree");
    m_categoryDao.save(category3);
    OnmsCategory category4 = new OnmsCategory("CategoryFour");
    m_categoryDao.save(category4);
    m_categoryDao.flush();
    // node 1
    serviceType = new OnmsServiceType("HTTP");
    m_serviceTypeDao.save(serviceType);
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 1");
    node.addCategory(category1);
    node.addCategory(category2);
    node.addCategory(category3);
    ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
    service = new OnmsMonitoredService(ipInterface, serviceType);
    m_nodeDao.save(node);
    // node 2
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 2");
    node.addCategory(category1);
    node.addCategory(category2);
    node.addCategory(category4);
    m_nodeDao.save(node);
    ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
    m_ipInterfaceDao.save(ipInterface);
    service = new OnmsMonitoredService(ipInterface, serviceType);
    m_serviceDao.save(service);
    ipInterface = new OnmsIpInterface(addr("0.0.0.0"), node);
    m_ipInterfaceDao.save(ipInterface);
    // node 3
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 3");
    m_nodeDao.save(node);
    ipInterface = new OnmsIpInterface(addr("192.168.1.2"), node);
    m_ipInterfaceDao.save(ipInterface);
    service = new OnmsMonitoredService(ipInterface, serviceType);
    m_serviceDao.save(service);
    // node 4 has an interface, but no services
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 4");
    m_nodeDao.save(node);
    ipInterface = new OnmsIpInterface(addr("192.168.1.3"), node);
    m_ipInterfaceDao.save(ipInterface);
    // node 5 has no interfaces
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 5");
    m_nodeDao.save(node);
    m_nodeDao.flush();
    m_ipInterfaceDao.flush();
    m_serviceDao.flush();
    m_serviceTypeDao.flush();
    m_categoryDao.flush();
}
Also used : MockNotifdConfigManager(org.opennms.netmgt.config.mock.MockNotifdConfigManager) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Example 4 with JdbcFilterDao

use of org.opennms.netmgt.filter.JdbcFilterDao in project opennms by OpenNMS.

the class ThresholdingVisitorIT method testReloadThreshdConfig.

/*
     * Use case A:
     * 
     * I have 5 nodes. The current threshd-config matches 2 of them. The new threshd-config will match the other 2, by
     * adding a new threshold package. For example: n1 y n2 belongs to category CAT1, n2, n3 y n4 belongs to category CAT2.
     * The initial configuration is related with CAT1 and the new package is related with CAT2. In both cases, n5 should
     * never match any threshold package.
     * 
     * Use case B:
     * 
     * I have a package with SNMP thresholds. Then update the package by adding HTTP thresholds. The test node should
     * support both services.
     * 
     * IMPORTANT:
     *     The reload should be do it first, then notify all visitors (I think this is the current behavior)
     *     The reload should not be executed inside the visitor because every collector thread has their own visitor.
     */
@Test
public void testReloadThreshdConfig() throws Exception {
    String baseIpAddress = "10.0.0.";
    // Initialize Mock Network
    MockNetwork network = new MockNetwork();
    network.setCriticalService("ICMP");
    for (int i = 1; i <= 5; i++) {
        String ipAddress = baseIpAddress + i;
        network.addNode(i, "testNode-" + ipAddress);
        network.addInterface(ipAddress);
        network.setIfAlias("eth0");
        network.addService("ICMP");
        network.addService("SNMP");
        if (i == 5) {
            // Adding HTTP on node 5
            network.addService("HTTP");
        }
    }
    network.addPathOutage(1, InetAddressUtils.addr("192.168.1.1"), "ICMP");
    MockDatabase db = new MockDatabase();
    db.populate(network);
    db.update("insert into categories (categoryid, categoryname) values (?, ?)", 10, "CAT1");
    db.update("insert into categories (categoryid, categoryname) values (?, ?)", 11, "CAT2");
    for (int i = 1; i <= 5; i++) {
        db.update("update snmpinterface set snmpifname=?, snmpifdescr=? where id=?", "eth0", "eth0", i);
        db.update("update node set nodesysoid=? where nodeid=?", ".1.3.6.1.4.1.9.1.222", i);
    }
    for (int i = 1; i <= 2; i++) {
        db.update("insert into category_node values (?, ?)", 10, i);
    }
    for (int i = 3; i <= 5; i++) {
        db.update("insert into category_node values (?, ?)", 11, i);
    }
    DataSourceFactory.setInstance(db);
    // Initialize Filter DAO
    System.setProperty("opennms.home", "src/test/resources");
    DatabaseSchemaConfigFactory.init();
    JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
    jdbcFilterDao.setDataSource(db);
    jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
    jdbcFilterDao.afterPropertiesSet();
    FilterDaoFactory.setInstance(jdbcFilterDao);
    // Initialize Factories
    initFactories("/threshd-configuration-reload-use-case-a.xml", "/test-thresholds-reload-use-cases.xml");
    // Initialize Thresholding Visitors
    System.err.println("-----------------------------------------------------------------------------------");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("thresholding-enabled", "true");
    ServiceParameters svcParams = new ServiceParameters(params);
    List<ThresholdingVisitor> visitors = new ArrayList<ThresholdingVisitor>();
    for (int i = 1; i <= 5; i++) {
        String ipAddress = baseIpAddress + i;
        ThresholdingVisitor visitor = ThresholdingVisitor.create(i, ipAddress, "SNMP", getRepository(), svcParams, m_resourceStorageDao);
        assertNotNull(visitor);
        visitors.add(visitor);
        if (i == 5) {
            ThresholdingVisitor httpVisitor = ThresholdingVisitor.create(i, ipAddress, "HTTP", getRepository(), svcParams, m_resourceStorageDao);
            assertNotNull(httpVisitor);
            visitors.add(httpVisitor);
        }
    }
    System.err.println("-----------------------------------------------------------------------------------");
    // Check Visitors
    for (int i = 0; i < 2; i++) {
        // Nodes n1 and n2 has thresholds defined on one threshold group.
        assertTrue(visitors.get(i).hasThresholds());
        assertEquals(1, visitors.get(i).getThresholdGroups().size());
    }
    for (int i = 2; i < 6; i++) {
        // Nodes n3, n4 and n5 should not have thresholds defined.
        assertFalse(visitors.get(i).hasThresholds());
        assertEquals(0, visitors.get(i).getThresholdGroups().size());
    }
    // Re-Initialize Factories
    initFactories("/threshd-configuration-reload-use-case-b.xml", "/test-thresholds-reload-use-cases.xml");
    // Reload state on each visitor
    System.err.println("-----------------------------------------------------------------------------------");
    for (ThresholdingVisitor visitor : visitors) {
        visitor.reload();
    }
    System.err.println("-----------------------------------------------------------------------------------");
    // Check Visitors
    for (int i = 0; i < 6; i++) {
        assertTrue(visitors.get(i).hasThresholds());
        assertEquals(1, visitors.get(i).getThresholdGroups().size());
        if (i == 5) {
            assertEquals("web-services", visitors.get(i).getThresholdGroups().get(0).getName());
        }
    }
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MockDatabase(org.opennms.core.test.db.MockDatabase) MibObject(org.opennms.netmgt.config.datacollection.MibObject) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) Test(org.junit.Test)

Example 5 with JdbcFilterDao

use of org.opennms.netmgt.filter.JdbcFilterDao in project opennms by OpenNMS.

the class ThresholdingVisitorIT method runTestForBug3554.

private void runTestForBug3554() throws Exception {
    MockLogAppender.resetEvents();
    System.err.println("----------------------------------------------------------------------------------- begin test");
    String baseIpAddress = "10.0.0.";
    int numOfNodes = 5;
    // Initialize Mock Network
    MockNetwork network = new MockNetwork();
    network.setCriticalService("ICMP");
    for (int i = 1; i <= numOfNodes; i++) {
        String ipAddress = baseIpAddress + i;
        network.addNode(i, "testNode-" + ipAddress);
        network.addInterface(ipAddress);
        network.setIfAlias("eth0");
        network.addService("ICMP");
        network.addService("SNMP");
    }
    network.addPathOutage(1, InetAddressUtils.addr("192.168.1.1"), "ICMP");
    MockDatabase db = new MockDatabase();
    db.populate(network);
    db.update("insert into categories (categoryid, categoryname) values (?, ?)", 10, "IPRA");
    db.update("insert into categories (categoryid, categoryname) values (?, ?)", 11, "NAS");
    for (int i = 1; i <= numOfNodes; i++) {
        db.update("update snmpinterface set snmpifname=?, snmpifdescr=? where id=?", "eth0", "eth0", i);
        db.update("update node set nodesysoid=? where nodeid=?", ".1.3.6.1.4.1.9.1.222", i);
        db.update("insert into category_node values (?, ?)", 10, i);
        db.update("insert into category_node values (?, ?)", 11, i);
    }
    DataSourceFactory.setInstance(db);
    // Initialize Filter DAO
    System.setProperty("opennms.home", "src/test/resources");
    DatabaseSchemaConfigFactory.init();
    JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
    jdbcFilterDao.setDataSource(db);
    jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
    jdbcFilterDao.afterPropertiesSet();
    FilterDaoFactory.setInstance(jdbcFilterDao);
    // Initialize Factories
    initFactories("/threshd-configuration-bug3554.xml", "/test-thresholds-bug3554.xml");
    // Initialize Thresholding Visitors
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("thresholding-enabled", "true");
    ServiceParameters svcParams = new ServiceParameters(params);
    for (int i = 1; i <= numOfNodes; i++) {
        System.err.println("----------------------------------------------------------------------------------- visitor #" + i);
        String ipAddress = baseIpAddress + i;
        ThresholdingVisitor visitor = ThresholdingVisitor.create(1, ipAddress, "SNMP", getRepository(), svcParams, m_resourceStorageDao);
        assertNotNull(visitor);
        // mib2, cisco, ciscoIPRA, ciscoNAS
        assertEquals(4, visitor.getThresholdGroups().size());
    }
    System.err.println("----------------------------------------------------------------------------------- end");
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) HashMap(java.util.HashMap) MockDatabase(org.opennms.core.test.db.MockDatabase) MibObject(org.opennms.netmgt.config.datacollection.MibObject) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao)

Aggregations

JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)8 Test (org.junit.Test)5 InputStream (java.io.InputStream)3 DatabaseSchemaConfigFactory (org.opennms.netmgt.config.DatabaseSchemaConfigFactory)3 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 MockDatabase (org.opennms.core.test.db.MockDatabase)2 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)2 MibObject (org.opennms.netmgt.config.datacollection.MibObject)2 MockNetwork (org.opennms.netmgt.mock.MockNetwork)2 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)2 ArrayList (java.util.ArrayList)1 MockNotifdConfigManager (org.opennms.netmgt.config.mock.MockNotifdConfigManager)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)1