Search in sources :

Example 6 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class MockDatabase method getOutages.

public Collection<Outage> getOutages(String criteria, Object... values) {
    String critSql = (criteria == null ? "" : " and " + criteria);
    final List<Outage> outages = new LinkedList<>();
    Querier loadExisting = new Querier(this, "select * from outages, ifServices, ipInterface, node, service where outages.ifServiceId = ifServices.id and ifServices.ipInterfaceId = ipInterface.id and ipInterface.nodeId = node.nodeId and ifServices.serviceId = service.serviceId" + critSql) {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            Outage outage = new Outage(rs.getInt("nodeId"), rs.getString("ipAddr"), rs.getInt("serviceId"));
            outage.setServiceName(rs.getString("serviceName"));
            outage.setLostEvent(rs.getInt("svcLostEventID"), rs.getTimestamp("ifLostService"));
            boolean open = (rs.getObject("ifRegainedService") == null);
            if (!open) {
                outage.setRegainedEvent(rs.getInt("svcRegainedEventID"), rs.getTimestamp("ifRegainedService"));
            }
            outages.add(outage);
        }
    };
    loadExisting.execute(values);
    return outages;
}
Also used : Querier(org.opennms.core.utils.Querier) SingleResultQuerier(org.opennms.core.utils.SingleResultQuerier) MockPathOutage(org.opennms.netmgt.mock.MockPathOutage) Outage(org.opennms.netmgt.mock.Outage) ResultSet(java.sql.ResultSet) LinkedList(java.util.LinkedList)

Example 7 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class PassiveStatusKeeper method onInit.

/**
 * <p>onInit</p>
 */
@Override
protected void onInit() {
    if (m_initialized)
        return;
    checkPreRequisites();
    createMessageSelectorAndSubscribe();
    m_statusTable = new HashMap<PassiveStatusKey, PollStatus>();
    String sql = "select node.nodeLabel AS nodeLabel, ipInterface.ipAddr AS ipAddr, service.serviceName AS serviceName " + "FROM outages " + "JOIN ifServices ON outages.ifServiceId = ifServices.id " + "JOIN ipInterface ON ifServices.ipInterfaceId = ipInterface.id " + "JOIN node ON ipInterface.nodeId = node.nodeId " + "JOIN service ON ifServices.serviceId = service.serviceId " + "WHERE outages.ifRegainedService is NULL";
    Querier querier = new Querier(m_dataSource, sql) {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            PassiveStatusKey key = new PassiveStatusKey(rs.getString("nodeLabel"), rs.getString("ipAddr"), rs.getString("serviceName"));
            m_statusTable.put(key, PollStatus.down());
        }
    };
    querier.execute();
    m_initialized = true;
}
Also used : Querier(org.opennms.core.utils.Querier) PollStatus(org.opennms.netmgt.poller.PollStatus) ResultSet(java.sql.ResultSet)

Example 8 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class MockDatabaseIT method testOutage.

public void testOutage() {
    final MockService svc = m_network.getService(1, "192.168.1.1", "ICMP");
    Event svcLostEvent = MockEventUtil.createNodeLostServiceEvent("TEST", svc);
    m_db.writeEvent(svcLostEvent);
    m_db.createOutage(svc, svcLostEvent);
    assertEquals(1, m_db.countOutagesForService(svc));
    Querier querier = new Querier(m_db, "select node.nodeid as nodeid, ipinterface.ipaddr as ipaddr, ifservices.serviceid as serviceid from outages, ifservices, ipinterface, node where outages.ifserviceid = ifservices.id and ifservices.ipinterfaceid = ipinterface.id and ipinterface.nodeid = node.nodeid") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            int nodeId = rs.getInt("nodeId");
            String ipAddr = rs.getString("ipAddr");
            int serviceId = rs.getInt("serviceId");
            assertEquals(nodeId, svc.getNodeId());
            assertEquals(ipAddr, svc.getIpAddr());
            assertEquals(serviceId, svc.getSvcId());
        }
    };
    querier.execute();
    assertEquals(1, querier.getCount());
}
Also used : Querier(org.opennms.core.utils.Querier) ResultSet(java.sql.ResultSet) MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event)

Example 9 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class MockDatabaseIT method testNodeQuery.

public void testNodeQuery() {
    Querier querier = new Querier(m_db, "select * from node") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            int nodeId = rs.getInt("nodeId");
            String label = rs.getString("nodeLabel");
            MockNode node = m_network.getNode(nodeId);
            assertNotNull(node);
            assertEquals(nodeId, node.getNodeId());
            assertEquals(label, node.getLabel());
        }
    };
    querier.execute();
    assertEquals(m_network.getNodeCount(), querier.getCount());
}
Also used : Querier(org.opennms.core.utils.Querier) ResultSet(java.sql.ResultSet) MockNode(org.opennms.netmgt.mock.MockNode)

Example 10 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class MockDatabaseIT method testServiceQuery.

public void testServiceQuery() {
    Querier querier = new Querier(m_db, "select node.nodeid as nodeId, ipinterface.ipaddr as ipAddr, ifServices.status as status, ifServices.serviceId as serviceId, service.serviceName as serviceName from ifServices, ipinterface, node, service where ifServices.serviceId = service.serviceId and ipinterface.id = ifServices.ipInterfaceId and node.nodeid = ipinterface.nodeid;") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            int nodeId = rs.getInt("nodeId");
            String ipAddr = rs.getString("ipAddr");
            int serviceId = rs.getInt("serviceId");
            String serviceName = rs.getString("serviceName");
            String status = rs.getString("status");
            MockService svc = m_network.getService(nodeId, ipAddr, serviceName);
            assertNotNull(svc);
            assertEquals("Assertion failed: " + svc, svc.getNodeId(), nodeId);
            assertEquals("Assertion failed: " + svc, svc.getIpAddr(), ipAddr);
            assertEquals("Assertion failed: " + svc, svc.getSvcName(), serviceName);
            assertEquals("Assertion failed: " + svc, svc.getSvcId(), serviceId);
            assertEquals("Assertion failed: " + svc, svc.getMgmtStatus().toDbString(), status);
        }
    };
    querier.execute();
    assertEquals(m_network.getServiceCount(), querier.getCount());
}
Also used : Querier(org.opennms.core.utils.Querier) ResultSet(java.sql.ResultSet) MockService(org.opennms.netmgt.mock.MockService)

Aggregations

Querier (org.opennms.core.utils.Querier)14 ResultSet (java.sql.ResultSet)12 SingleResultQuerier (org.opennms.core.utils.SingleResultQuerier)7 SQLException (java.sql.SQLException)3 RowProcessor (org.opennms.core.utils.RowProcessor)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 MockNode (org.opennms.netmgt.mock.MockNode)2 MockService (org.opennms.netmgt.mock.MockService)2 Event (org.opennms.netmgt.xml.event.Event)2 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Notification (org.opennms.netmgt.config.notifications.Notification)1 MockInterface (org.opennms.netmgt.mock.MockInterface)1 MockPathOutage (org.opennms.netmgt.mock.MockPathOutage)1 Outage (org.opennms.netmgt.mock.Outage)1 PollStatus (org.opennms.netmgt.poller.PollStatus)1 Tticket (org.opennms.netmgt.xml.event.Tticket)1