public Object generate() throws SiteWhereException { DeviceAlertCreateRequest request = new DeviceAlertCreateRequest(); request.setSource(ExampleData.EVENT_ALERT1.getSource()); request.setType(ExampleData.EVENT_ALERT1.getType()); request.setLevel(ExampleData.EVENT_ALERT1.getLevel()); request.setMessage(ExampleData.EVENT_ALERT1.getMessage()); request.setEventDate(new Date()); request.setUpdateState(true); return request; } }
public Object generate() throws SiteWhereException { DeviceEventBatch batch = new DeviceEventBatch(); batch.setHardwareId(ExampleData.TRACKER.getHardwareId()); DeviceMeasurementsCreateRequest mx = new DeviceMeasurementsCreateRequest(); mx.setMeasurements(ExampleData.EVENT_MEASUREMENT1.getMeasurements()); mx.setEventDate(new Date()); mx.setUpdateState(true); batch.getMeasurements().add(mx); DeviceLocationCreateRequest loc = new DeviceLocationCreateRequest(); loc.setLatitude(ExampleData.EVENT_LOCATION1.getLatitude()); loc.setLongitude(ExampleData.EVENT_LOCATION1.getLongitude()); loc.setElevation(ExampleData.EVENT_LOCATION1.getElevation()); loc.setEventDate(new Date()); loc.setUpdateState(true); batch.getLocations().add(loc); DeviceAlertCreateRequest alert = new DeviceAlertCreateRequest(); alert.setSource(ExampleData.EVENT_ALERT1.getSource()); alert.setType(ExampleData.EVENT_ALERT1.getType()); alert.setLevel(ExampleData.EVENT_ALERT1.getLevel()); alert.setMessage(ExampleData.EVENT_ALERT1.getMessage()); alert.setEventDate(new Date()); alert.setUpdateState(true); batch.getAlerts().add(alert); return batch; } }
@Override public void onLocation(IDeviceEventContext context, IDeviceLocation location) throws SiteWhereException { for (ZoneTest test : zoneTests) { Polygon poly = getZonePolygon(test.getZoneToken()); ZoneContainment containment = (poly.contains(GeoUtils.createPointForLocation(location))) ? ZoneContainment.Inside : ZoneContainment.Outside; if (test.getCondition() == containment) { DeviceAlertCreateRequest alert = new DeviceAlertCreateRequest(); alert.setType(test.getAlertType()); alert.setLevel(test.getAlertLevel()); alert.setMessage(test.getAlertMessage()); alert.setUpdateState(false); alert.setEventDate(new Date()); getDeviceEventManagement().addDeviceAlerts(location.getDeviceAssignmentId(), alert); } } }
request.setDeviceToken("99797-RASPBERRYPI-5545473"); request.setType(Type.DeviceAlert); DeviceAlertCreateRequest alert = new DeviceAlertCreateRequest(); alert.setSource(AlertSource.Device); alert.setLevel(AlertLevel.Info);
@Override public void onLocationNotFiltered(IDeviceLocation location) throws SiteWhereException { for (ZoneTest test : zoneTests) { Polygon poly = getZonePolygon(test.getZoneToken()); ZoneContainment containment = (poly.contains(GeoUtils.createPointForLocation(location))) ? ZoneContainment.Inside : ZoneContainment.Outside; if (test.getCondition() == containment) { DeviceAlertCreateRequest alert = new DeviceAlertCreateRequest(); alert.setType(test.getAlertType()); alert.setLevel(test.getAlertLevel()); alert.setMessage(test.getAlertMessage()); alert.setUpdateState(false); alert.setEventDate(new Date()); SiteWhere.getServer().getDeviceEventManagement(getTenant()) .addDeviceAlert(location.getDeviceAssignmentToken(), alert); } } }
/** * Convert device alert create request from GRPC to API. * * @param grpc * @return * @throws SiteWhereException */ public static DeviceAlertCreateRequest asApiDeviceAlertCreateRequest(GDeviceAlertCreateRequest grpc) throws SiteWhereException { DeviceAlertCreateRequest api = new DeviceAlertCreateRequest(); api.setSource(EventModelConverter.asApiAlertSource(grpc.getSource())); api.setLevel(EventModelConverter.asApiAlertLevel(grpc.getLevel())); api.setType(grpc.getType()); api.setMessage(grpc.getAlertMessage()); EventModelConverter.copyApiDeviceEventCreateRequest(grpc.getEvent(), api); return api; }
@Test public void testAddDeviceAlert() throws Exception { CoapClient client = createClientFor(getBaseDeviceUrl() + "/alerts"); DeviceAlertCreateRequest alert = new DeviceAlertCreateRequest(); alert.setType("alert.test"); alert.setMessage("Danger! Danger!"); handleResponse(client.post(MarshalUtils.marshalJson(alert), MediaTypeRegistry.APPLICATION_JSON)); }
request.getMeasurements().add(mx); DeviceAlertCreateRequest alert = new DeviceAlertCreateRequest(); alert.setType("engine.overheat"); alert.setMessage("Engine overheating.");
DeviceAlert alert = DeviceAlert.parseDelimitedFrom(stream); LOGGER.debug("Decoded alert for: " + alert.getHardwareId()); DeviceAlertCreateRequest request = new DeviceAlertCreateRequest(); request.setType(alert.getAlertType()); request.setMessage(alert.getAlertMessage());
SiteWhere.DeviceEvent.DeviceAlert alert = SiteWhere.DeviceEvent.DeviceAlert.parseDelimitedFrom(stream); getLogger().debug("Decoded alert for: " + header.getDeviceToken().getValue()); DeviceAlertCreateRequest request = new DeviceAlertCreateRequest(); request.setType(alert.getAlertType().getValue()); request.setMessage(alert.getAlertMessage().getValue());