use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method getParmsForEventId.
public static Map<String, String> getParmsForEventId(int eventId) throws SQLException {
final Connection conn = DataSourceFactory.getInstance().getConnection();
final DBUtils d = new DBUtils(EventFactory.class, conn);
final Map<String, String> result = Maps.newHashMap();
try {
PreparedStatement stmt = conn.prepareStatement("SELECT name, value FROM event_parameters WHERE eventid = ?");
d.watch(stmt);
stmt.setInt(1, eventId);
ResultSet rs = stmt.executeQuery();
d.watch(rs);
while (rs.next()) {
result.put(rs.getString("name"), rs.getString("value"));
}
} finally {
d.cleanUp();
}
return result;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method unacknowledge.
/**
* Unacknowledge events that match the given filter criteria.
*
* @param filters an array of org$opennms$web$filter$Filter objects.
* @throws java.sql.SQLException if any.
*/
public static void unacknowledge(Filter[] filters) throws SQLException {
if (filters == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
final StringBuilder update = new StringBuilder("UPDATE EVENTS SET EVENTACKUSER=NULL, EVENTACKTIME=NULL WHERE");
update.append(getAcknowledgeTypeClause(AcknowledgeType.ACKNOWLEDGED));
for (Filter filter : filters) {
update.append(" AND");
update.append(filter.getParamSql());
}
final DBUtils d = new DBUtils(EventFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement(update.toString());
d.watch(stmt);
int parameterIndex = 1;
for (Filter filter : filters) {
parameterIndex += filter.bindParam(stmt, parameterIndex);
}
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method unacknowledge.
/**
* Unacknowledge a list of events.
*
* @param eventIds an array of int.
* @throws java.sql.SQLException if any.
*/
public static void unacknowledge(int[] eventIds) throws SQLException {
if (eventIds == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
if (eventIds.length > 0) {
final StringBuilder update = new StringBuilder("UPDATE EVENTS SET EVENTACKUSER=NULL, EVENTACKTIME=NULL");
update.append(" WHERE EVENTID IN (");
update.append(eventIds[0]);
for (int i = 1; i < eventIds.length; i++) {
update.append(",");
update.append(eventIds[i]);
}
update.append(")");
DBUtils d = new DBUtils(EventFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement(update.toString());
d.watch(stmt);
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method getEventCountBySeverity.
/**
* Count the number of events for a given acknowledgement type.
*
* @return An array of event counts. Each index of the array corresponds to
* the event severity for the counts (indeterminate is 1, critical
* is 7, etc).
* @param ackType a {@link org.opennms.web.event.AcknowledgeType} object.
* @param filters an array of org$opennms$web$filter$Filter objects.
* @throws java.sql.SQLException if any.
*/
public static int[] getEventCountBySeverity(AcknowledgeType ackType, Filter[] filters) throws SQLException {
if (ackType == null || filters == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
int[] eventCounts = new int[8];
final Connection conn = DataSourceFactory.getInstance().getConnection();
final DBUtils d = new DBUtils(EventFactory.class, conn);
try {
final StringBuilder select = new StringBuilder("SELECT EVENTSEVERITY, COUNT(*) AS EVENTCOUNT FROM EVENTS LEFT OUTER JOIN NODE USING (NODEID) LEFT OUTER JOIN SERVICE USING (SERVICEID) WHERE ");
select.append(getAcknowledgeTypeClause(ackType));
for (Filter filter : filters) {
select.append(" AND");
select.append(filter.getParamSql());
}
select.append(" AND EVENTDISPLAY='Y'");
select.append(" GROUP BY EVENTSEVERITY");
final PreparedStatement stmt = conn.prepareStatement(select.toString());
d.watch(stmt);
int parameterIndex = 1;
for (Filter filter : filters) {
parameterIndex += filter.bindParam(stmt, parameterIndex);
}
final ResultSet rs = stmt.executeQuery();
d.watch(rs);
while (rs.next()) {
int severity = rs.getInt("EVENTSEVERITY");
int eventCount = rs.getInt("EVENTCOUNT");
eventCounts[severity] = eventCount;
}
} finally {
d.cleanUp();
}
return eventCounts;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class EventFactory method acknowledge.
/**
* Acknowledge with the given username and the given time all events that
* match the given filter criteria.
*
* @param filters an array of org$opennms$web$filter$Filter objects.
* @param user a {@link java.lang.String} object.
* @param time a java$util$Date object.
* @throws java.sql.SQLException if any.
*/
public static void acknowledge(Filter[] filters, String user, Date time) throws SQLException {
if (filters == null || user == null || time == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
final StringBuilder update = new StringBuilder("UPDATE EVENTS SET EVENTACKUSER=?, EVENTACKTIME=? WHERE");
update.append(getAcknowledgeTypeClause(AcknowledgeType.UNACKNOWLEDGED));
for (Filter filter : filters) {
update.append(" AND");
update.append(filter.getParamSql());
}
final DBUtils d = new DBUtils(EventFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement(update.toString());
d.watch(stmt);
stmt.setString(1, user);
stmt.setTimestamp(2, new Timestamp(time.getTime()));
int parameterIndex = 3;
for (Filter filter : filters) {
parameterIndex += filter.bindParam(stmt, parameterIndex);
}
stmt.executeUpdate();
} finally {
d.cleanUp();
}
}
Aggregations