use of org.opennms.web.filter.Filter 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 {
StringBuffer select = new StringBuffer("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.web.filter.Filter 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.");
}
StringBuffer update = new StringBuffer("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.web.filter.Filter 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.");
}
StringBuffer update = new StringBuffer("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();
}
}
use of org.opennms.web.filter.Filter in project opennms by OpenNMS.
the class AlarmRepositoryIT method testSortAndSearchBySameProperty.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testSortAndSearchBySameProperty() {
Filter[] filters = new Filter[] { new NodeNameLikeFilter("node") };
AlarmCriteria sorted = new AlarmCriteria(filters, SortStyle.NODE, AcknowledgeType.UNACKNOWLEDGED, 100, 0);
OnmsAlarm[] alarms = m_alarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(sorted));
assertTrue("Failed to sort with style " + SortStyle.NODE, alarms.length > 0);
}
use of org.opennms.web.filter.Filter in project opennms by OpenNMS.
the class EventController method acknowledge.
/**
* Acknowledge the events specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
public ModelAndView acknowledge(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] eventIdStrings = request.getParameterValues("event");
String action = request.getParameter("actionCode");
if (eventIdStrings == null) {
throw new MissingParameterException("event", new String[] { "event", "actionCode" });
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "event", "actionCode" });
}
List<Filter> filters = new ArrayList<Filter>();
filters.add(new EventIdListFilter(WebSecurityUtils.safeParseInt(eventIdStrings)));
EventCriteria criteria = new EventCriteria(filters.toArray(new Filter[0]));
LOG.debug("criteria = {}, action = {}", criteria, action);
if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
m_webEventRepository.acknowledgeMatchingEvents(request.getRemoteUser(), new Date(), criteria);
} else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
m_webEventRepository.unacknowledgeMatchingEvents(criteria);
} else {
throw new ServletException("Unknown acknowledge action: " + action);
}
return getRedirectView(request);
}
Aggregations