Search in sources :

Example 21 with MockNetwork

use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.

the class NotificationsITCase method createMockNetwork.

protected MockNetwork createMockNetwork() {
    MockNetwork network = new MockNetwork();
    network.createStandardNetwork();
    return network;
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork)

Example 22 with MockNetwork

use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.

the class PassiveStatusKeeperIT method createMockNetwork.

private void createMockNetwork() {
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface("192.168.1.1");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addInterface("192.168.1.2");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addNode(2, "Server");
    m_network.addInterface("192.168.1.3");
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_network.addNode(3, "Firewall");
    m_network.addInterface("192.168.1.4");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addInterface("192.168.1.5");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addNode(100, "localhost");
    m_network.addInterface("127.0.0.1");
    m_network.addService("PSV");
    m_network.addService("PSV2");
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork)

Example 23 with MockNetwork

use of org.opennms.netmgt.mock.MockNetwork 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)

Example 24 with MockNetwork

use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.

the class EventTranslatorIT method createMockNetwork.

private void createMockNetwork() {
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface("192.168.1.1");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addInterface("192.168.1.2");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addNode(2, "Server");
    m_network.addInterface("192.168.1.3");
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_network.addNode(3, "Firewall");
    m_network.addInterface("192.168.1.4");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addInterface("192.168.1.5");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addNode(100, "localhost");
    m_network.addInterface("127.0.0.1");
    m_network.addService("PSV");
    m_network.addService("PSV2");
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork)

Example 25 with MockNetwork

use of org.opennms.netmgt.mock.MockNetwork in project opennms by OpenNMS.

the class LatencyStoringServiceMonitorAdaptorPersistenceTest method persistAndVerifyLatencySamples.

private void persistAndVerifyLatencySamples(String locationName, Path pathToResourceInResponseTime) throws Exception {
    PollStatus pollStatus = PollStatus.get(PollStatus.SERVICE_AVAILABLE, 42.1);
    // For the purposes of this test, it's important the attributes are not added in lexicographical order
    Map<String, Number> props = new LinkedHashMap<String, Number>(pollStatus.getProperties());
    props.put("ping1", Integer.valueOf(1));
    props.put("loss", Integer.valueOf(2));
    props.put("median", Integer.valueOf(3));
    pollStatus.setProperties(props);
    ServiceMonitor serviceMonitor = new FixedServiceMonitor(pollStatus);
    Package pkg = new Package();
    MockNetwork mockNetwork = new MockNetwork();
    mockNetwork.createStandardNetwork();
    MockPollerConfig pollerConfig = new MockPollerConfig(mockNetwork);
    pollerConfig.setRRAList(pkg, Lists.newArrayList("RRA:AVERAGE:0.5:1:2016"));
    LatencyStoringServiceMonitorAdaptor lssma = new LatencyStoringServiceMonitorAdaptor(pollerConfig, pkg, m_persisterFactory, m_resourceStorageDao);
    MonitoredService monitoredService = new MockMonitoredService(3, "Firewall", locationName, InetAddress.getByName("192.168.1.5"), "SMTP");
    Map<String, Object> params = Maps.newHashMap();
    params.put("rrd-repository", getResponseTimeRoot().getAbsolutePath());
    params.put("rrd-base-name", "smtp-base");
    EasyMock.expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".jrb").atLeastOnce();
    m_rrdStrategy.createDefinition(EasyMock.eq("192.168.1.5"), EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime).toString()), EasyMock.eq("smtp-base"), EasyMock.anyInt(), EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().andReturn(null).once();
    m_rrdStrategy.createFile(EasyMock.anyObject());
    EasyMock.expectLastCall().once();
    m_rrdStrategy.openFile(EasyMock.eq(getResponseTimeRoot().toPath().resolve(pathToResourceInResponseTime.resolve("smtp-base.jrb")).toString()));
    EasyMock.expectLastCall().andReturn(null).once();
    // This is the important bit, the order of the values should match the order there were inserted above
    m_rrdStrategy.updateFile(EasyMock.isNull(), EasyMock.eq("192.168.1.5"), EasyMock.endsWith(":42.1:1:2:3"));
    EasyMock.expectLastCall().once();
    EasyMock.replay(m_rrdStrategy);
    // Trigger the poll
    lssma.handlePollResult(monitoredService, params, serviceMonitor.poll(monitoredService, params));
    // Verify
    EasyMock.verify(m_rrdStrategy);
    // Reset
    EasyMock.reset(m_rrdStrategy);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) LinkedHashMap(java.util.LinkedHashMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) AbstractServiceMonitor(org.opennms.netmgt.poller.support.AbstractServiceMonitor) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) Package(org.opennms.netmgt.config.poller.Package)

Aggregations

MockNetwork (org.opennms.netmgt.mock.MockNetwork)25 Before (org.junit.Before)11 MockDatabase (org.opennms.core.test.db.MockDatabase)8 Test (org.junit.Test)6 MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)6 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)4 OutageAnticipator (org.opennms.netmgt.mock.OutageAnticipator)4 PollableNetwork (org.opennms.netmgt.poller.pollables.PollableNetwork)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)3 LocationAwarePingClient (org.opennms.netmgt.icmp.proxy.LocationAwarePingClient)3 MockNode (org.opennms.netmgt.mock.MockNode)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 FileInputStream (java.io.FileInputStream)2 MibObject (org.opennms.netmgt.config.datacollection.MibObject)2 Package (org.opennms.netmgt.config.poller.Package)2 JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1