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();
}
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();
}
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()));
}
}
}
}
}
}
Aggregations