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();
}
}
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;
}
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();
}
}
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();
}
}
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);
}
Aggregations