use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by MangoAutomation.
the class EventInstanceServiceTest method testUnackSummaryCount.
@Test
public void testUnackSummaryCount() {
long refTime = System.currentTimeMillis();
createEvents(5, 0, refTime);
List<UserEventLevelSummary> summaries = service.getUnacknowledgedSummary();
AlarmLevels alarmLevel = newVO(editUser).getAlarmLevel();
UserEventLevelSummary summary = summaries.get(alarmLevel.value());
assertEquals(5, summary.getCount());
}
use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by MangoAutomation.
the class EventManagerImpl method raiseEvent.
//
//
// Basic event management.
//
/**
* Raise Event
* @param rtnApplicable - does this event return to normal?
*/
@Override
public void raiseEvent(EventType type, long time, boolean rtnApplicable, AlarmLevels alarmLevel, TranslatableMessage message, Map<String, Object> context) {
if (state != ILifecycleState.RUNNING)
return;
long nowTimestamp = Common.timer.currentTimeMillis();
if (time > nowTimestamp) {
log.warn("Raising event in the future! type=" + type + ", message='" + message.translate(Common.getTranslations()) + "' now=" + new Date(nowTimestamp) + " event=" + new Date(time) + " deltaMs=" + (time - nowTimestamp));
}
if (alarmLevel == AlarmLevels.IGNORE)
return;
// Check if there is an event for this type already active.
EventInstance dup = get(type);
if (dup != null) {
// Check the duplicate handling.
boolean discard = canDiscard(type, message);
if (discard)
return;
// Otherwise we just continue...
} else if (!rtnApplicable) {
// Check if we've already seen this type recently.
boolean recent = isRecent(type, message);
if (recent)
return;
}
EventInstance evt = new EventInstance(type, time, rtnApplicable, alarmLevel, message, context);
evt.setReadPermission(type.getEventPermission(context, permissionService));
// Determine if the event should be suppressed (automatically acknowledged and handlers dont run)
TranslatableMessage autoAckMessage = null;
for (EventManagerListenerDefinition l : listeners) {
try {
autoAckMessage = l.autoAckEventWithMessage(evt);
} catch (Exception e) {
log.warn("Error in event manager listener, continuing", e);
}
if (autoAckMessage != null)
break;
}
for (EventManagerListenerDefinition l : listeners) {
try {
evt = l.modifyEvent(evt);
} catch (Exception e) {
log.warn("Error in event manager listener, continuing", e);
}
if (evt == null) {
return;
}
}
loadHandlers(evt);
// Check to see if we are Not Logging these
if (alarmLevel != AlarmLevels.DO_NOT_LOG) {
eventDao.saveEvent(evt);
}
// set of email addresses which have been configured to receive events over a certain level
Set<String> emailUsers = new HashSet<>();
List<Integer> userIdsToNotify = new ArrayList<>();
UserEventListener multicaster = userEventMulticaster;
for (User user : usersService.getEnabledUsers()) {
// user should be skipped.
if (type.excludeUser(user))
continue;
if (type.hasPermission(user, permissionService)) {
// add email addresses for users which have been configured to receive events over a certain level
if (user.getReceiveAlarmEmails().value() > AlarmLevels.IGNORE.value() && alarmLevel.value() >= user.getReceiveAlarmEmails().value() && !StringUtils.isEmpty(user.getEmail()))
emailUsers.add(user.getEmail());
// Notify All User Event Listeners of the new event
if ((alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventTypeNames.AUDIT))) {
userIdsToNotify.add(user.getId());
}
}
}
if (multicaster != null)
Common.backgroundProcessing.addWorkItem(new EventNotifyWorkItem(userIdsToNotify, multicaster, evt, true, false, false, false));
// add email addresses for mailing lists which have been configured to receive events over a certain level
emailUsers.addAll(mailingListService.getAlarmAddresses(alarmLevel, time, RecipientListEntryType.MAILING_LIST, RecipientListEntryType.ADDRESS, RecipientListEntryType.USER));
if (evt.isRtnApplicable()) {
activeEventsLock.writeLock().lock();
try {
activeEvents.add(evt);
} finally {
activeEventsLock.writeLock().unlock();
}
} else if (evt.getEventType().isRateLimited()) {
recentEventsLock.writeLock().lock();
try {
recentEvents.add(evt);
} finally {
recentEventsLock.writeLock().unlock();
}
}
if ((autoAckMessage != null) && (alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventTypeNames.AUDIT)))
this.acknowledgeEvent(evt, time, null, autoAckMessage);
else {
if (evt.isRtnApplicable()) {
if (alarmLevel.value() > highestActiveAlarmLevel) {
int oldValue = highestActiveAlarmLevel;
highestActiveAlarmLevel = alarmLevel.value();
SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_MAX_ALARM_LEVEL_CHANGED), time, false, getAlarmLevelChangeMessage("event.alarmMaxIncreased", oldValue));
}
}
// Call raiseEvent handlers.
handleRaiseEvent(evt, emailUsers);
if (log.isTraceEnabled()) {
log.trace("Event raised: type={}, message={}, time={}", type, message.translate(Common.getTranslations()), new Date(time));
}
}
}
use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by MangoAutomation.
the class EventInstanceService method getUnacknowledgedSummary.
/**
*/
public List<UserEventLevelSummary> getUnacknowledgedSummary() {
PermissionHolder user = Common.getUser();
this.permissionService.ensurePermission(user, eventsViewPermission.getPermission());
Map<AlarmLevels, UserEventLevelSummary> summaries = new EnumMap<>(AlarmLevels.class);
for (AlarmLevels level : AlarmLevels.values()) {
if (level == AlarmLevels.IGNORE) {
continue;
}
int count = dao.countUnacknowledgedAlarms(level, user);
EventInstanceVO latest = dao.getLatestUnacknowledgedAlarm(level, user);
summaries.put(level, new UserEventLevelSummary(level, count, latest));
}
return new ArrayList<>(summaries.values());
}
use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by MangoAutomation.
the class AuditEventType method registerEventType.
private static void registerEventType(String subtype, String key) {
TYPE_NAMES.addElement(subtype);
AlarmLevels level = AlarmLevels.fromValue(SystemSettingsDao.getInstance().getIntValue(AUDIT_SETTINGS_PREFIX + subtype));
EVENT_TYPES.put(subtype, new EventTypeVO(new AuditEventType(subtype, 0, 0), new TranslatableMessage(key), level));
}
use of com.serotonin.m2m2.rt.event.AlarmLevels in project ma-core-public by MangoAutomation.
the class UserLoginEventTypeDefinition method generatePossibleEventTypesWithReferenceId1.
@Override
public List<EventTypeVO> generatePossibleEventTypesWithReferenceId1(PermissionHolder user, String subtype) {
if (!StringUtils.equals(SystemEventType.TYPE_USER_LOGIN, subtype))
return Collections.emptyList();
AlarmLevels level = AlarmLevels.fromValue(systemSettingsDao.getIntValue(SystemEventType.SYSTEM_SETTINGS_PREFIX + SystemEventType.TYPE_USER_LOGIN));
List<User> users;
if (permissionService.hasAdminRole(user)) {
users = userDao.getEnabledUsers();
} else if (user.getUser() != null) {
users = Collections.singletonList(user.getUser());
} else {
users = Collections.emptyList();
}
return users.stream().map(u -> new EventTypeVO(new SystemEventType(SystemEventType.TYPE_USER_LOGIN, u.getId()), new TranslatableMessage("event.system.userLoginForUser", u.getName()), level)).collect(Collectors.toList());
}
Aggregations