Search in sources :

Example 1 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-modules-public by infiniteautomation.

the class EventsRestController method getActiveSummary.

@ApiOperation(value = "Get the active events summary", notes = "List of counts for all active events by type and the most recent active alarm for each.")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/active-summary")
public ResponseEntity<List<EventLevelSummaryModel>> getActiveSummary(HttpServletRequest request) {
    RestProcessResult<List<EventLevelSummaryModel>> result = new RestProcessResult<List<EventLevelSummaryModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        List<EventLevelSummaryModel> list = new ArrayList<EventLevelSummaryModel>();
        // This query is slow the first time as it must fill the UserEventCache
        List<EventInstance> events = Common.eventManager.getAllActiveUserEvents(user.getId());
        int lifeSafetyTotal = 0;
        EventInstance lifeSafetyEvent = null;
        int criticalTotal = 0;
        EventInstance criticalEvent = null;
        int urgentTotal = 0;
        EventInstance urgentEvent = null;
        int warningTotal = 0;
        EventInstance warningEvent = null;
        int importantTotal = 0;
        EventInstance importantEvent = null;
        int informationTotal = 0;
        EventInstance informationEvent = null;
        int noneTotal = 0;
        EventInstance noneEvent = null;
        int doNotLogTotal = 0;
        EventInstance doNotLogEvent = null;
        for (EventInstance event : events) {
            switch(event.getAlarmLevel()) {
                case AlarmLevels.LIFE_SAFETY:
                    lifeSafetyTotal++;
                    lifeSafetyEvent = event;
                    break;
                case AlarmLevels.CRITICAL:
                    criticalTotal++;
                    criticalEvent = event;
                    break;
                case AlarmLevels.URGENT:
                    urgentTotal++;
                    urgentEvent = event;
                    break;
                case AlarmLevels.WARNING:
                    warningTotal++;
                    warningEvent = event;
                    break;
                case AlarmLevels.IMPORTANT:
                    importantTotal++;
                    importantEvent = event;
                    break;
                case AlarmLevels.INFORMATION:
                    informationTotal++;
                    informationEvent = event;
                    break;
                case AlarmLevels.NONE:
                    noneTotal++;
                    noneEvent = event;
                    break;
                case AlarmLevels.DO_NOT_LOG:
                    doNotLogTotal++;
                    doNotLogEvent = event;
                    break;
            }
        }
        EventInstanceModel model;
        // Life Safety
        if (lifeSafetyEvent != null)
            model = new EventInstanceModel(lifeSafetyEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.LIFE_SAFETY), lifeSafetyTotal, model));
        // Critical Events
        if (criticalEvent != null)
            model = new EventInstanceModel(criticalEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.CRITICAL), criticalTotal, model));
        // Urgent Events
        if (urgentEvent != null)
            model = new EventInstanceModel(urgentEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.URGENT), urgentTotal, model));
        // Warning Events
        if (warningEvent != null)
            model = new EventInstanceModel(warningEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.WARNING), warningTotal, model));
        // Important Events
        if (importantEvent != null)
            model = new EventInstanceModel(importantEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.IMPORTANT), importantTotal, model));
        // Information Events
        if (informationEvent != null)
            model = new EventInstanceModel(informationEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.INFORMATION), informationTotal, model));
        // None Events
        if (noneEvent != null)
            model = new EventInstanceModel(noneEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.NONE), noneTotal, model));
        // Do Not Log Events
        if (doNotLogEvent != null)
            model = new EventInstanceModel(doNotLogEvent);
        else
            model = null;
        list.add(new EventLevelSummaryModel(AlarmLevels.CODES.getCode(AlarmLevels.DO_NOT_LOG), doNotLogTotal, model));
        return result.createResponseEntity(list);
    }
    return result.createResponseEntity();
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) EventLevelSummaryModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventLevelSummaryModel) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-modules-public by infiniteautomation.

the class EventsRestController method acknowledgeEvent.

/**
 * Update an event
 * @param vo
 * @param xid
 * @param builder
 * @param request
 * @return
 */
@ApiOperation(value = "Acknowledge an existing event", notes = "")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json" }, produces = { "application/json" }, value = "/acknowledge/{id}")
public ResponseEntity<EventInstanceModel> acknowledgeEvent(@PathVariable Integer id, @RequestBody(required = false) TranslatableMessageModel message, UriComponentsBuilder builder, HttpServletRequest request) {
    RestProcessResult<EventInstanceModel> result = new RestProcessResult<EventInstanceModel>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        TranslatableMessage tlm = null;
        if (message != null)
            tlm = new TranslatableMessage(message.getKey(), message.getArgs().toArray());
        EventInstance event = EventDao.instance.get(id);
        if (event == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        } else if (!Permissions.hasEventTypePermission(user, event.getEventType())) {
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
        Common.eventManager.acknowledgeEventById(id, System.currentTimeMillis(), user, tlm);
        // if event has a different ack timestamp, user or message it was already acked, we could return a different message
        EventInstanceModel model = new EventInstanceModel(event);
        // Put a link to the updated data in the header?
        URI location = builder.path("/v1/events/{id}").buildAndExpand(id).toUri();
        result.addRestMessage(getResourceUpdatedMessage(location));
        return result.createResponseEntity(model);
    }
    // Not logged in
    return result.createResponseEntity();
}
Also used : EventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.EventInstanceModel) EventInstance(com.serotonin.m2m2.rt.event.EventInstance) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) URI(java.net.URI) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.

the class EventManagerImpl method resetHighestAlarmLevel.

private void resetHighestAlarmLevel(long time) {
    int max = 0;
    activeEventsLock.readLock().lock();
    try {
        ListIterator<EventInstance> it = activeEvents.listIterator();
        while (it.hasNext()) {
            EventInstance e = it.next();
            if (e.getAlarmLevel() > max)
                max = e.getAlarmLevel();
        }
    } finally {
        activeEventsLock.readLock().unlock();
    }
    if (max > highestActiveAlarmLevel) {
        int oldValue = highestActiveAlarmLevel;
        highestActiveAlarmLevel = max;
        SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_MAX_ALARM_LEVEL_CHANGED), time, false, getAlarmLevelChangeMessage("event.alarmMaxIncreased", oldValue));
    } else if (max < highestActiveAlarmLevel) {
        int oldValue = highestActiveAlarmLevel;
        highestActiveAlarmLevel = max;
        SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_MAX_ALARM_LEVEL_CHANGED), time, false, getAlarmLevelChangeMessage("event.alarmMaxDecreased", oldValue));
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType)

Example 4 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.

the class EventManagerImpl method cancelEventsForPublisher.

/**
 * Cancel all events for a publisher
 * @param publisherId
 */
public void cancelEventsForPublisher(int publisherId) {
    List<EventInstance> publisherEvents = new ArrayList<EventInstance>();
    activeEventsLock.writeLock().lock();
    try {
        ListIterator<EventInstance> it = activeEvents.listIterator();
        while (it.hasNext()) {
            EventInstance e = it.next();
            if (e.getEventType().getPublisherId() == publisherId) {
                it.remove();
                publisherEvents.add(e);
            }
        }
    } finally {
        activeEventsLock.writeLock().unlock();
    }
    deactivateEvents(publisherEvents, Common.timer.currentTimeMillis(), EventInstance.RtnCauses.SOURCE_DISABLED);
    recentEventsLock.writeLock().lock();
    try {
        ListIterator<EventInstance> it = recentEvents.listIterator();
        while (it.hasNext()) {
            EventInstance e = it.next();
            if (e.getEventType().getPublisherId() == publisherId)
                it.remove();
        }
    } finally {
        recentEventsLock.writeLock().unlock();
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 5 with EventInstance

use of com.serotonin.m2m2.rt.event.EventInstance in project ma-core-public by infiniteautomation.

the class EventManagerImpl method cancelEventsForDataPoint.

// 
// 
// Canceling events.
// 
public void cancelEventsForDataPoint(int dataPointId) {
    List<EventInstance> dataPointEvents = new ArrayList<EventInstance>();
    activeEventsLock.writeLock().lock();
    try {
        ListIterator<EventInstance> it = activeEvents.listIterator();
        while (it.hasNext()) {
            EventInstance e = it.next();
            if (e.getEventType().getDataPointId() == dataPointId) {
                it.remove();
                dataPointEvents.add(e);
            }
        }
    } finally {
        activeEventsLock.writeLock().unlock();
    }
    deactivateEvents(dataPointEvents, Common.timer.currentTimeMillis(), EventInstance.RtnCauses.SOURCE_DISABLED);
    recentEventsLock.writeLock().lock();
    try {
        ListIterator<EventInstance> it = recentEvents.listIterator();
        while (it.hasNext()) {
            EventInstance e = it.next();
            if (e.getEventType().getDataPointId() == dataPointId)
                it.remove();
        }
    } finally {
        recentEventsLock.writeLock().unlock();
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

EventInstance (com.serotonin.m2m2.rt.event.EventInstance)30 ArrayList (java.util.ArrayList)14 User (com.serotonin.m2m2.vo.User)12 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)7 HashMap (java.util.HashMap)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 EventDao (com.serotonin.m2m2.db.dao.EventDao)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 UserEventListener (com.serotonin.m2m2.rt.event.UserEventListener)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 Translations (com.serotonin.m2m2.i18n.Translations)3 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)3 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)3 ScriptLog (com.serotonin.m2m2.rt.script.ScriptLog)3 ScriptPermissionsException (com.serotonin.m2m2.rt.script.ScriptPermissionsException)3 EventInstanceBean (com.serotonin.m2m2.web.dwr.beans.EventInstanceBean)3 ScriptException (javax.script.ScriptException)3