use of org.opennms.web.alarm.filter.AlarmCriteria in project opennms by OpenNMS.
the class AlarmRepositoryIT method testAcknowledgeUnacknowledgeAllAlarms.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testAcknowledgeUnacknowledgeAllAlarms() {
String user = "TestUser";
m_alarmRepo.acknowledgeAll(user, new Date());
int matchingAlarmCount = m_alarmRepo.countMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new AcknowledgedByFilter(user))));
assertEquals(1, matchingAlarmCount);
m_alarmRepo.unacknowledgeAll(user);
matchingAlarmCount = m_alarmRepo.countMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new AcknowledgedByFilter(user))));
assertEquals(0, matchingAlarmCount);
}
use of org.opennms.web.alarm.filter.AlarmCriteria in project opennms by OpenNMS.
the class NCSAlarmController method handleRequestInternal.
@RequestMapping(method = RequestMethod.GET)
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String display = request.getParameter("display");
// handle the style sort parameter
String sortStyleString = request.getParameter("sortby");
SortStyle sortStyle = m_defaultSortStyle;
if (sortStyleString != null) {
SortStyle temp = SortStyle.getSortStyle(sortStyleString);
if (temp != null) {
sortStyle = temp;
}
}
// handle the acknowledgment type parameter
String ackTypeString = request.getParameter("acktype");
AcknowledgeType ackType = m_defaultAcknowledgeType;
if (ackTypeString != null) {
AcknowledgeType temp = AcknowledgeType.getAcknowledgeType(ackTypeString);
if (temp != null) {
ackType = temp;
}
}
// handle the filter parameters
String[] filterStrings = request.getParameterValues("filter");
List<Filter> filterList = new ArrayList<>();
if (filterStrings != null) {
for (int i = 0; i < filterStrings.length; i++) {
Filter filter = AlarmUtil.getFilter(filterStrings[i], getServletContext());
if (filter != null) {
filterList.add(filter);
}
}
} else {
filterList.add(AlarmUtil.getFilter("parmmatchany=componentType=Service", getServletContext()));
}
// handle the optional limit parameter
String limitString = request.getParameter("limit");
int limit = "long".equals(display) ? getDefaultLongLimit() : getDefaultShortLimit();
if (limitString != null) {
try {
int newlimit = WebSecurityUtils.safeParseInt(limitString);
if (newlimit > 0) {
limit = newlimit;
}
} catch (NumberFormatException e) {
// do nothing, the default is already set
}
}
// handle the optional multiple parameter
String multipleString = request.getParameter("multiple");
int multiple = DEFAULT_MULTIPLE;
if (multipleString != null) {
try {
multiple = Math.max(0, WebSecurityUtils.safeParseInt(multipleString));
} catch (NumberFormatException e) {
}
}
// put the parameters in a convenient struct
Filter[] filters = filterList.toArray(new Filter[0]);
AlarmQueryParms parms = new AlarmQueryParms();
parms.ackType = ackType;
parms.display = display;
parms.filters = filterList;
parms.limit = limit;
parms.multiple = multiple;
parms.sortStyle = sortStyle;
AlarmCriteria queryCriteria = new AlarmCriteria(filters, sortStyle, ackType, limit, limit * multiple);
AlarmCriteria countCriteria = new AlarmCriteria(filters, ackType);
OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(AlarmUtil.getOnmsCriteria(queryCriteria));
// get the total alarm count
int alarmCount = m_webAlarmRepository.countMatchingAlarms(AlarmUtil.getOnmsCriteria(countCriteria));
ModelAndView modelAndView = new ModelAndView(getSuccessView());
modelAndView.addObject("alarms", alarms);
modelAndView.addObject("alarmCount", alarmCount);
modelAndView.addObject("parms", parms);
return modelAndView;
}
use of org.opennms.web.alarm.filter.AlarmCriteria in project opennms by OpenNMS.
the class AcknowledgeAlarmByFilterController method handleRequestInternal.
/**
* {@inheritDoc}
*
* Acknowledge the events specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
@Override
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] filterStrings = request.getParameterValues("filter");
String action = request.getParameter("actionCode");
if (filterStrings == null) {
filterStrings = new String[0];
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "filter", "actionCode" });
}
// handle the filter parameters
ArrayList<Filter> filterArray = new ArrayList<>();
for (String filterString : filterStrings) {
Filter filter = AlarmUtil.getFilter(filterString, getServletContext());
if (filter != null) {
filterArray.add(filter);
}
}
Filter[] filters = filterArray.toArray(new Filter[filterArray.size()]);
OnmsCriteria criteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters));
if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.acknowledgeMatchingAlarms(request.getRemoteUser(), new Date(), criteria);
} else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.unacknowledgeMatchingAlarms(criteria, request.getRemoteUser());
} else {
throw new ServletException("Unknown acknowledge action: " + action);
}
String redirectParms = request.getParameter("redirectParms");
String redirect = request.getParameter("redirect");
String viewName;
if (redirect != null) {
viewName = redirect;
} else {
viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
}
RedirectView view = new RedirectView(viewName, true);
return new ModelAndView(view);
}
use of org.opennms.web.alarm.filter.AlarmCriteria in project opennms by OpenNMS.
the class AlarmFeed method getFeed.
/**
* <p>getFeed</p>
*
* @return a {@link com.rometools.rome.feed.synd.SyndFeed} object.
*/
@Override
public SyndFeed getFeed() {
SyndFeed feed = new SyndFeedImpl();
feed.setTitle("Alarms");
feed.setDescription("OpenNMS Alarms");
feed.setLink(getUrlBase() + "alarm/list.htm");
List<SyndEntry> entries = new ArrayList<>();
List<Filter> filters = new ArrayList<>();
if (this.getRequest().getParameter("node") != null) {
Integer nodeId = WebSecurityUtils.safeParseInt(this.getRequest().getParameter("node"));
filters.add(new NodeFilter(nodeId, getServletContext()));
}
if (this.getRequest().getParameter("severity") != null) {
String sev = this.getRequest().getParameter("severity");
for (OnmsSeverity severity : OnmsSeverity.values()) {
if (severity.getLabel().equalsIgnoreCase(sev)) {
filters.add(new SeverityFilter(severity));
}
}
}
OnmsCriteria queryCriteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters.toArray(new Filter[] {}), SortStyle.FIRSTEVENTTIME, AcknowledgeType.BOTH, this.getMaxEntries(), AlarmCriteria.NO_OFFSET));
OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(queryCriteria);
SyndEntry entry;
for (OnmsAlarm alarm : alarms) {
entry = new SyndEntryImpl();
entry.setPublishedDate(alarm.getFirstEventTime());
if (alarm.getAckTime() != null) {
entry.setTitle(sanitizeTitle(alarm.getLogMsg()) + " (acknowledged by " + alarm.getAckUser() + ")");
entry.setUpdatedDate(alarm.getAckTime());
} else {
entry.setTitle(sanitizeTitle(alarm.getLogMsg()));
entry.setUpdatedDate(alarm.getFirstEventTime());
}
entry.setLink(getUrlBase() + "alarm/detail.htm?id=" + alarm.getId());
entry.setAuthor("OpenNMS");
SyndContent content = new SyndContentImpl();
content.setType("text/html");
content.setValue(alarm.getDescription());
entry.setDescription(content);
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
Aggregations