Search in sources :

Example 1 with ValueMonitor

use of com.infiniteautomation.mango.monitor.ValueMonitor in project ma-modules-public by infiniteautomation.

the class SystemMetricsRestController method query.

@ApiOperation(value = "Get the current value for all System Metrics", notes = "TBD Add RQL Support to this endpoint")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<List<ValueMonitor<?>>> query(HttpServletRequest request) {
    RestProcessResult<List<ValueMonitor<?>>> result = new RestProcessResult<List<ValueMonitor<?>>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        // Check Permissions
        String permissions = SystemSettingsDao.getValue(internalMetricsPermission);
        if (Permissions.hasPermission(user, permissions)) {
            return result.createResponseEntity(Common.MONITORED_VALUES.getMonitors());
        } else {
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) List(java.util.List) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ValueMonitor

use of com.infiniteautomation.mango.monitor.ValueMonitor in project ma-modules-public by infiniteautomation.

the class SystemMetricsRestController method get.

@ApiOperation(value = "Get the current value for one System Metric by its ID", notes = "")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/{id}")
public ResponseEntity<ValueMonitor<?>> get(@ApiParam(value = "Valid Monitor id", required = true, allowMultiple = false) @PathVariable String id, HttpServletRequest request) {
    RestProcessResult<ValueMonitor<?>> result = new RestProcessResult<ValueMonitor<?>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        // Check Permissions
        String permissions = SystemSettingsDao.getValue(internalMetricsPermission);
        if (Permissions.hasPermission(user, permissions)) {
            List<ValueMonitor<?>> values = Common.MONITORED_VALUES.getMonitors();
            ValueMonitor<?> value = null;
            for (ValueMonitor<?> v : values) {
                if (v.getId().equals(id)) {
                    value = v;
                    break;
                }
            }
            if (value != null)
                return result.createResponseEntity(value);
            else {
                result.addRestMessage(getDoesNotExistMessage());
            }
        } else {
            result.addRestMessage(getUnauthorizedMessage());
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ValueMonitor

use of com.infiniteautomation.mango.monitor.ValueMonitor in project ma-modules-public by infiniteautomation.

the class InternalMenuItem method maybeCreatePoints.

/**
 */
private void maybeCreatePoints(boolean safe, DataSourceVO<?> vo) {
    Map<String, ValueMonitor<?>> monitors = getAllHomePageMonitors();
    Iterator<String> it = monitors.keySet().iterator();
    while (it.hasNext()) {
        String xid = it.next();
        ValueMonitor<?> monitor = monitors.get(xid);
        if (monitor != null) {
            DataPointVO dp = DataPointDao.instance.getByXid(xid);
            if (dp == null) {
                InternalPointLocatorVO pl = new InternalPointLocatorVO();
                pl.setMonitorId(monitor.getId());
                dp = new DataPointVO();
                dp.setXid(xid);
                dp.setName(monitor.getName().translate(Common.getTranslations()));
                dp.setDataSourceId(vo.getId());
                dp.setDeviceName(vo.getName());
                dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
                dp.defaultTextRenderer();
                dp.setEnabled(true);
                dp.setChartColour("");
                dp.setPointLocator(pl);
                // Use default template
                DataPointPropertiesTemplateVO template = TemplateDao.instance.getDefaultDataPointTemplate(pl.getDataTypeId());
                if (template != null) {
                    template.updateDataPointVO(dp);
                    dp.setTemplateId(template.getId());
                }
                // If we are numeric then we want to log on change
                switch(pl.getDataTypeId()) {
                    case DataTypes.NUMERIC:
                        if (SYSTEM_UPTIME_POINT_XID.equals(xid)) {
                            // This changes every time, so just do an interval instant
                            dp.setLoggingType(LoggingTypes.INTERVAL);
                            dp.setIntervalLoggingPeriodType(Common.TimePeriods.MINUTES);
                            dp.setIntervalLoggingPeriod(5);
                            dp.setIntervalLoggingType(DataPointVO.IntervalLoggingTypes.INSTANT);
                        } else {
                            // Setup to Log on Change
                            dp.setLoggingType(LoggingTypes.ON_CHANGE);
                        }
                        if (dp.getTextRenderer() instanceof AnalogRenderer && !dp.getXid().equals(SYSTEM_UPTIME_POINT_XID)) {
                            // This are count points, no need for decimals.
                            ((AnalogRenderer) dp.getTextRenderer()).setFormat("0");
                        }
                        // No template in use here
                        dp.setTemplateId(null);
                        break;
                }
                ProcessResult result = new ProcessResult();
                dp.validate(result);
                if (!result.getHasMessages()) {
                    if (safe)
                        DataPointDao.instance.saveDataPoint(dp);
                    else
                        Common.runtimeManager.saveDataPoint(dp);
                } else {
                    for (ProcessMessage message : result.getMessages()) {
                        LOG.error(message.toString(Common.getTranslations()));
                    }
                }
            }
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor)

Aggregations

ValueMonitor (com.infiniteautomation.mango.monitor.ValueMonitor)3 User (com.serotonin.m2m2.vo.User)2 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 AnalogRenderer (com.serotonin.m2m2.view.text.AnalogRenderer)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)1 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)1 List (java.util.List)1