Search in sources :

Example 16 with DBUtils

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

the class SetCriticalPathServlet method setCriticalPath.

private static void setCriticalPath(int node, String criticalIp, String criticalSvc) throws SQLException {
    deleteCriticalPath(node);
    final DBUtils d = new DBUtils(SetCriticalPathServlet.class);
    try {
        Connection conn = DataSourceFactory.getInstance().getConnection();
        d.watch(conn);
        PreparedStatement stmt = conn.prepareStatement(SQL_SET_CRITICAL_PATH);
        d.watch(stmt);
        stmt.setInt(1, node);
        stmt.setString(2, criticalIp);
        stmt.setString(3, criticalSvc);
        stmt.executeUpdate();
    } finally {
        d.cleanUp();
    }
}
Also used : DBUtils(org.opennms.core.utils.DBUtils) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 17 with DBUtils

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

the class SnmpGetNodesServlet method getAllNodes.

private List<SnmpManagedNode> getAllNodes(HttpSession userSession) throws SQLException {
    Connection connection = null;
    List<SnmpManagedNode> allNodes = new ArrayList<SnmpManagedNode>();
    int lineCount = 0;
    final DBUtils d = new DBUtils(getClass());
    try {
        connection = DataSourceFactory.getInstance().getConnection();
        d.watch(connection);
        int snmpServNum = 0;
        Statement servstmt = connection.createStatement();
        d.watch(servstmt);
        ResultSet snmpserv = servstmt.executeQuery(SNMP_SERVICE_QUERY);
        d.watch(snmpserv);
        if (snmpserv != null) {
            while (snmpserv.next()) {
                snmpServNum = snmpserv.getInt(1);
            }
        }
        this.log("DEBUG: The SNMP service number is: " + snmpServNum);
        PreparedStatement stmt = connection.prepareStatement(NODE_QUERY);
        d.watch(stmt);
        stmt.setInt(1, snmpServNum);
        ResultSet nodeSet = stmt.executeQuery();
        d.watch(nodeSet);
        if (nodeSet != null) {
            while (nodeSet.next()) {
                SnmpManagedNode newNode = new SnmpManagedNode();
                newNode.setNodeID(nodeSet.getInt(1));
                newNode.setNodeLabel(nodeSet.getString(2));
                allNodes.add(newNode);
            }
        }
        userSession.setAttribute("lineNodeItems.snmpmanage.jsp", Integer.valueOf(lineCount));
    } finally {
        d.cleanUp();
    }
    return allNodes;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) DBUtils(org.opennms.core.utils.DBUtils) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 18 with DBUtils

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

the class ServiceNoticeUpdateServlet method updateService.

/**
     */
private void updateService(final int nodeID, final String interfaceIP, final int serviceID, final String notifyFlag) throws ServletException {
    Connection connection = null;
    final DBUtils d = new DBUtils(getClass());
    try {
        connection = DataSourceFactory.getInstance().getConnection();
        d.watch(connection);
        final PreparedStatement stmt = connection.prepareStatement(UPDATE_SERVICE);
        d.watch(stmt);
        stmt.setString(1, notifyFlag);
        stmt.setInt(2, nodeID);
        stmt.setString(3, interfaceIP);
        stmt.setInt(4, serviceID);
        stmt.executeUpdate();
    // close off the db connection
    } catch (final SQLException e) {
        try {
            if (connection != null) {
                connection.rollback();
            }
        } catch (final SQLException sqlEx) {
            throw new ServletException("Couldn't roll back update to service " + serviceID + " on interface " + interfaceIP + " notify as " + notifyFlag + " in the database.", sqlEx);
        }
        throw new ServletException("Error when updating to service " + serviceID + " on interface " + interfaceIP + " notify as " + notifyFlag + " in the database.", e);
    } finally {
        d.cleanUp();
    }
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DBUtils(org.opennms.core.utils.DBUtils) PreparedStatement(java.sql.PreparedStatement)

Example 19 with DBUtils

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

the class NotificationWizardServlet method deleteCriticalPath.

private void deleteCriticalPath(final int node, final Connection conn) throws SQLException {
    final DBUtils d = new DBUtils(getClass());
    try {
        PreparedStatement stmt = conn.prepareStatement(SQL_DELETE_CRITICAL_PATH);
        d.watch(stmt);
        stmt.setInt(1, node);
        stmt.execute();
    } finally {
        d.cleanUp();
    }
}
Also used : DBUtils(org.opennms.core.utils.DBUtils) PreparedStatement(java.sql.PreparedStatement)

Example 20 with DBUtils

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

the class SnmpManageNodesServlet method doPost.

/** {@inheritDoc} */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(false);
    List<SnmpManagedInterface> allInterfaces = getManagedInterfacesFromSession(userSession);
    // the node being modified
    String nodeIdString = request.getParameter("node");
    int currNodeId = WebSecurityUtils.safeParseInt(nodeIdString);
    String primeInt = null;
    for (final SnmpManagedInterface testInterface : allInterfaces) {
        if (testInterface.getNodeid() == currNodeId && PrimaryType.PRIMARY.getCode().equals(testInterface.getStatus())) {
            // Get the IP address of the primary SNMP interface
            primeInt = NetworkElementFactory.getInstance(this.getServletContext()).getIpPrimaryAddress(currNodeId);
        }
    }
    final DBUtils d = new DBUtils(getClass());
    try {
        Connection connection = DataSourceFactory.getInstance().getConnection();
        d.watch(connection);
        try {
            connection.setAutoCommit(false);
            PreparedStatement stmt = connection.prepareStatement(UPDATE_INTERFACE);
            d.watch(stmt);
            for (SnmpManagedInterface curInterface : allInterfaces) {
                String option = request.getParameter("collect-" + curInterface.getIfIndex());
                LOG.debug("option = {}", option);
                stmt.setString(1, option);
                stmt.setInt(2, curInterface.getSnmpInterfaceId());
                stmt.execute();
            }
            connection.commit();
        } finally {
            // close off the db connection
            connection.setAutoCommit(true);
        }
    } catch (SQLException e) {
        throw new ServletException(e);
    } finally {
        d.cleanUp();
    }
    // send the event to restart SNMP Collection
    if (primeInt != null) {
        sendSNMPRestartEvent(currNodeId, primeInt);
    }
    // forward the request for proper display
    // TODO This will redirect to the node page, but the URL will be admin/changeCollectStatus. Needs fixed.
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/element/node.jsp?node=" + currNodeId);
    dispatcher.forward(request, response);
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) HttpSession(javax.servlet.http.HttpSession) DBUtils(org.opennms.core.utils.DBUtils) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

DBUtils (org.opennms.core.utils.DBUtils)77 Connection (java.sql.Connection)68 PreparedStatement (java.sql.PreparedStatement)64 ResultSet (java.sql.ResultSet)50 SQLException (java.sql.SQLException)17 ArrayList (java.util.ArrayList)14 Timestamp (java.sql.Timestamp)12 Statement (java.sql.Statement)10 Filter (org.opennms.web.filter.Filter)9 ServletException (javax.servlet.ServletException)5 FilterParseException (org.opennms.netmgt.filter.api.FilterParseException)5 IfIndexFilter (org.opennms.web.event.filter.IfIndexFilter)5 InterfaceFilter (org.opennms.web.event.filter.InterfaceFilter)5 NodeFilter (org.opennms.web.event.filter.NodeFilter)5 ServiceFilter (org.opennms.web.event.filter.ServiceFilter)5 SeverityFilter (org.opennms.web.event.filter.SeverityFilter)5 Date (java.util.Date)4 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)3 InetAddress (java.net.InetAddress)3 RequestDispatcher (javax.servlet.RequestDispatcher)3