use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class AcknowledgmentRestService method acknowledge.
/**
* <p>acknowledgeAlarm</p>
*
* @param alarmId a {@link java.lang.String} object.
* @param action a {@link java.lang.String} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response acknowledge(@Context final SecurityContext securityContext, MultivaluedMap<String, String> formParams) {
String alarmId = formParams.getFirst("alarmId");
String notifId = formParams.getFirst("notifId");
String action = formParams.getFirst("action");
String ackUser = formParams.getFirst("ackUser");
if (action == null) {
action = "ack";
}
if (ackUser == null) {
ackUser = securityContext.getUserPrincipal().getName();
}
AlarmRestService.assertUserEditCredentials(securityContext, ackUser);
OnmsAcknowledgment ack = null;
if (alarmId == null && notifId == null) {
return getBadRequestResponse("You must supply either an alarmId or notifId");
} else if (alarmId != null && notifId != null) {
return getBadRequestResponse("You cannot supply both an alarmId and a notifId");
} else if (alarmId != null) {
final Integer numericAlarmId = getNumericValue(alarmId);
if (numericAlarmId == null) {
return getBadRequestResponse("The alarmId has to be an integer value");
}
final OnmsAlarm alarm = m_alarmDao.get(numericAlarmId);
if (alarm == null) {
return Response.notModified().build();
}
ack = new OnmsAcknowledgment(alarm, ackUser);
} else if (notifId != null) {
final Integer numericNotifId = getNumericValue(notifId);
if (numericNotifId == null) {
return getBadRequestResponse("The notifId has to be an integer value");
}
final OnmsNotification notification = m_notificationDao.get(numericNotifId);
if (notification == null) {
return Response.notModified().build();
}
ack = new OnmsAcknowledgment(notification, ackUser);
}
if ("ack".equals(action)) {
ack.setAckAction(AckAction.ACKNOWLEDGE);
} else if ("unack".equals(action)) {
ack.setAckAction(AckAction.UNACKNOWLEDGE);
} else if ("clear".equals(action)) {
ack.setAckAction(AckAction.CLEAR);
} else if ("esc".equals(action)) {
ack.setAckAction(AckAction.ESCALATE);
} else {
return getBadRequestResponse("Must supply the action parameter, set to either 'ack, 'unack', 'clear', or 'esc'");
}
m_ackDao.processAck(ack);
return Response.ok(ack).build();
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class SurveillanceViewNotificationTable method refreshDetails.
/**
* {@inheritDoc}
*/
@Override
public void refreshDetails(final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories) {
if (m_future != null && !m_future.isDone()) {
return;
}
m_future = getSurveillanceViewService().getExecutorService().submit(new Callable<List<Notification>>() {
@Override
public List<Notification> call() throws Exception {
/**
* create the custom severity map
*/
Map<OnmsNotification, String> customSeverity = new HashMap<>();
/**
* retrieve the matching notifications
*/
List<OnmsNotification> onmsNotifications = getSurveillanceViewService().getNotificationsForCategories(rowCategories, colCategories, customSeverity);
/**
* create the notifications list
*/
List<Notification> notifications = new ArrayList<>();
for (OnmsNotification onmsNotification : onmsNotifications) {
notifications.add(new Notification(onmsNotification.getNotifyId(), onmsNotification.getNodeId(), onmsNotification.getNodeLabel(), onmsNotification.getPageTime(), onmsNotification.getRespondTime(), onmsNotification.getAnsweredBy(), onmsNotification.getTextMsg(), onmsNotification.getServiceType() != null ? onmsNotification.getServiceType().getName() : "", customSeverity.get(onmsNotification)));
}
return notifications;
}
});
m_future.addListener(new Runnable() {
@Override
public void run() {
try {
final List<Notification> notifications = m_future.get();
getUI().access(new Runnable() {
@Override
public void run() {
/**
* empty the bean container
*/
m_beanItemContainer.removeAllItems();
/**
* add items to container
*/
if (notifications != null && !notifications.isEmpty()) {
for (Notification notification : notifications) {
m_beanItemContainer.addItem(notification);
}
}
/**
* sort the items
*/
sort(new Object[] { "pageTime" }, new boolean[] { false });
/**
* refresh the table
*/
refreshRowCache();
}
});
} catch (InterruptedException e) {
LOG.error("Interrupted", e);
} catch (ExecutionException e) {
LOG.error("Exception in task", e.getCause());
}
}
}, MoreExecutors.sameThreadExecutor());
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class NotificationDaoIT method testNotificationSave.
@Test
@Transactional
public void testNotificationSave() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(7);
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/NotificationDaoTest");
// OnmsAlarm alarm = new OnmsAlarm();
// event.setAlarm(alarm);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
event.setIpAddr(iface.getIpAddress());
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/NotificationDaoTest", newEvent.getEventUei());
OnmsNotification notification = new OnmsNotification();
notification.setEvent(newEvent);
notification.setTextMsg("Tests are fun!");
m_notificationDao.save(notification);
OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId());
assertEquals("uei://org/opennms/test/NotificationDaoTest", newNotification.getEvent().getEventUei());
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class DaoWebNotificationRepository method getMatchingNotifications.
/** {@inheritDoc} */
@Transactional
@Override
public Notification[] getMatchingNotifications(NotificationCriteria criteria) {
List<Notification> notifications = new ArrayList<Notification>();
List<OnmsNotification> onmsNotifs = m_notificationDao.findMatching(getOnmsCriteria(criteria));
for (OnmsNotification notif : onmsNotifs) {
notifications.add(mapOnmsNotificationToNotification(notif));
}
return notifications.toArray(new Notification[0]);
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class NotificationRestService method updateNotifications.
/**
* <p>updateNotifications</p>
*
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateNotifications(@Context final SecurityContext securityContext, final MultivaluedMapImpl params) {
writeLock();
try {
Boolean ack = false;
if (params.containsKey("ack")) {
ack = "true".equals(params.getFirst("ack"));
params.remove("ack");
}
final CriteriaBuilder builder = getCriteriaBuilder(params);
for (final OnmsNotification notif : m_notifDao.findMatching(builder.toCriteria())) {
processNotifAck(securityContext, notif, ack);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
Aggregations