Enrich device life cycle events Azure IoT Hub - azure-iot-hub

I need to enrich the device life cycle events[Created, Deleted, Connected, Disconnected] received on Event Grid.
The event flow in my solution is like below:-
Device send registration request to IoT Hub -> Event grid triggers device life cycle event -> Event grid routes device life cycle event to Event Hub.
Since my application i.e. consumer to Event hub only that is the reason I'm routing all events to Event Hub from Event Grid.
Now, I need to enrich the event received on Event hub. For example, the device connected event should look like below:
{
"body": [
{
"id": "58b1872d-1388-8043-dacc-6322ca65d2bf",
"topic": "SOME_TOPIC",
"subject": "devices/diablo-central-park-1",
"eventType": "Microsoft.Devices.DeviceConnected",
"data": {
"deviceConnectionStateEventInfo": {
"sequenceNumber": "SOME_SEQ_NUMBER"
},
"hubName": "IOT_HUBNAME",
"deviceId": "DEVICE_ID"
},
"dataVersion": "",
"metadataVersion": "1",
"eventTime": "2020-10-16T06:33:42.2418032Z"
}
],
"properties": {
"aeg-output-event-id": "SOME_ID",
"aeg-subscription-name": "SOME_NAME,
"aeg-delivery-count": "0",
"aeg-data-version": "",
"aeg-metadata-version": "1",
"aeg-event-type": "Notification",
"enrichedProperty": "enrichedValue"
},
"offset": "25769816448",
"sequenceNumber": 2197,
"enqueuedTimeUtc": "2020-10-16T06:33:49.321Z",
""systemProperties": {}
}
So, In above event JSON, I should get the enrichedProperty in the properties field. I have done message enrichment for twin change events, telemetry through Message routing(Enrich Messages)in IoT hub blade on the portal. But for device life cycle events I could not find a way.

This should work in a very similar manner. So you create an end point (e.g. a storage container), then create a route making sure you choose "Device Lifecycle Events" in the data source of the route. then go to "enrich messages" tab and add the name and value of the property that you want , making sure the correct end point is selected. Also make sure that the root is enabled and the route query is true. Now when you create or delete a device, your events will be captured and the enriched property will appear in the captured event properties.

Related

How to keep both button text and payload in whatsapp quick reply message template

Whatsapp quick reply request template has option for payload only. In what option we can configure the button text. After lots of searching on internet I did not find proper solution.
Here is the json of button which need to be send in request but it only has the payload option
{
"type": "button",
"sub_type" : "quick_reply",
"index": "0",
"parameters": [
{
"type": "payload",
# Business Developer-defined payload
"payload":"aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT"
}
]
},
Reference link: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates/interactive-message-templates#request
You need to configure that in the Facebook Business Manager UI or in the Graph API post request when you create the template. When you're sending the message, you can't dynamically configure the text.

How to set PartitionKey property from stream analytics on the output message to service bus?

I have following setup:
Event hub
Service bus topic with a single subscription that accepts all messages from the topic (for my POC)
Above service bus subscription is setup with sessions enabled
Stream analytics (SA) job that moves the events from event hub (the input) into service bus topic (the output). Here is my SA query:
SELECT *, LOWER(source) as Partner
INTO [sb-output]
FROM [test-input]
The above job also sets the partition key for service bus. Used following json in the System Properties of [sb-output] based on the documentation at https://learn.microsoft.com/en-us/azure/stream-analytics/service-bus-topics-output#custom-metadata-properties-for-output:
{ "PartitionKey" : "Partner" }
What I did:
Sent an event to event hub without partition key. This was successful.
{
"specversion": "1.0",
"id": "c8c4faad-9f53-4e43-95ca-c318d673660a",
"type": "CustomerChanged",
"time": "2020-09-09T22:25:40.0148301Z",
"source": "ABCD",
"subject": "system-1",
"datacontenttype": "application/json",
"dataschema": "1.0",
"data": {
"customerNumber": "7879875212123",
"firstName": "John",
"lastName" : "Kennedy"
}
}
The SA successfully moved the event from event hub to service bus.
The service bus subscription succcessfully received the message as shown below:
{
"specversion": "1.0",
"id": "c8c4faad-9f53-4e43-95ca-c318d673660a",
"type": "CustomerChanged",
"time": "2020-09-09T23:22:13.3647825Z",
"source": "ABCD",
"subject": "system-1",
"datacontenttype": "application/json",
"dataschema": "1.0",
"data": {
"customerNumber": "7879875212123",
"firstName": "John",
"lastName": "Kennedy"
},
"EventProcessedUtcTime": "2020-09-09T23:22:14.3776603Z",
"PartitionId": 0,
"EventEnqueuedUtcTime": "2020-09-09T23:22:14.3080000Z",
"Partner": "abcd"
}
As can be seen, the property Partner is at the end of the message.
However the Service Bus Explorer tool shows me that the PartitionKey property has not been set to "abcd" but to some other random string.
Troubleshooting:
To make sure that I can send a message to service bus topic with a specific PartitionKey key, I wrote a sample code that submits the message to service bus topic by explicitly setting the session id property on the message. The service bus explorer showed me that both SessionId as well as PartitionKey properties are set to the correct value.
In ASA output configuration, tried to set following system properties json. Neither worked.
{ "SessionId" : "Partner" }
{ "PartitionKey" : "Partner", "SessionId" : "Partner" }
In ASA output configuration, tried setting both Property Columns (to Partner) as well as System Property Columns (to { "PartitionKey" : "Partner" }). That did not work.
Question:
What am I doing wrong with ASA output configuration that is circumventing the propagation of PartitionKey value from my custom field to service bus message?
Also is there a reason why the System Property Columns does not show the json text that I entered after saving?
Sharing the answer as per the comment by the original poster:
Currently, Microsoft is working on a fix.
Until then, you can use the suggested work around: { "PartitionKey" : "Partner", "SessionId" : "Partner", "Label": "Partner" } in system properties.

Automatic tests of click events

Clicks on certain DOM elements sents click events to Google Analytics, as URL requests like https://stats.g.doubleclick.net/r/collect?v=1&aip=1&t=dc&_r=3&tid=UA-1234567-2&cid=297722160.1523959944&jid=2028321276&_gid=1320758195.1530624077&gjid=12698493&_v=j68&z=1135539045
What tools/methods/workarounds are usual to automatically test click events - mainly their status code and content?
I am not 100% sure that I understand your question. First think you should understand is that hits sent to google analytics are not validated they are send and forget. Google analytics returns a gif thats it there is no way to know if the request was a success or a fail.
There is one way of debugging hits being sent to Google analytics in test before you actually release to production and thats the debug endpoint
https://www.google-analytics.com/debug/collect?v=1&aip=1&t=dc&_r=3&tid=UA-1234567-2&cid=297722160.1523959944&jid=2028321276&_gid=1320758195.1530624077&gjid=12698493&_v=j68&z=1135539045
sending your hit to the debug endpoint results in
{
"hitParsingResult": [ {
"valid": true,
"parserMessage": [ {
"messageType": "INFO",
"description": "IP Address from this hit was anonymized to 185.128.103.0.",
"messageCode": "VALUE_MODIFIED"
} ],
"hit": "/debug/collect?v=1\u0026aip=1\u0026t=dc\u0026_r=3\u0026tid=UA-1234567-2\u0026cid=297722160.1523959944\u0026jid=2028321276\u0026_gid=1320758195.1530624077\u0026gjid=12698493\u0026_v=j68\u0026z=1135539045"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}
This hit was not actually sent to google analytics it was just test sent. If you want to set up some kind of unit testing or atuomation testing of your hits your going to have to do that yourself using the debug endpoint
More info can be found here validating-hits

Graph API Subscription Notification Fires Continuously

I am creating subscriptions to a OneDrive folder using the Graph API and I am receiving change notifications continuously (every half a second) even when the contents of the folder (or even the drive itself) is not changing. (Obviously I was expecting that I would receive notifications only when the folder contents change).
I post the following JSON to create the subscription:-
{
"clientState": "GraphAPITest1 2018/05/01 11:31:26",
"notificationUrl": "https://123e7ff5.ngrok.io/notification/listen",
"resource": "/drives/b!X5kF-EHEkECCcjyJ3Fh1CTQI-5nOBktJv57zZdpp13CPQb_8FIV-RIPt-7fnzyxP/root",
"expirationDateTime": "2018-05-02T11:31:26.0881202+01:00",
"changeType": "updated"
}
The notification that my service receives is:-
{
"value": [
{
"subscriptionId": "2467af01-a616-4493-8947-220146c4828a",
"clientState": "GraphAPITest1 2018/05/01 11:23:13",
"resource": "/drives/b!X5kF-EHEkECCcjyJ3Fh1CTQI-5nOBktJv57zZdpp13CPQb_8FIV-RIPt-7fnzyxP/root",
"resourceData": null,
"changeType": "updated",
"subscriptionExpirationDateTime": "2018-05-02T10:23:13.3640899+00:00"
}
]
}
I get the same behaviour in my own code as well as in Microsoft's example app (https://github.com/OneDrive/onedrive-webhooks-aspnet). My code uses an app-only authentication token but the Microsoft example forces user authentication - both suffer from the same behaviour.
Any idea what I need to do to only get notifications when the contents of the folder actually changes?
Barry

Can we receive step data in the pub sub payload?

I can see in the payload JSON that the pubsub notification includes the events but is it also capable of sending the activity or sleep amounts (e.g steps or sleep minutes)?
No, the pubsub notification will only include the user and the list of events that took place. You can then use this information to query the APIs that pertain to those specific types of events.
For example, suppose you receive the following pubsub notification:
{
"notification_timestamp": "1372787949",
"events": [
{
"user_xid": "RGaCBFg9CsB83FsEcMY44A",
"event_xid": "EJpCkyAtwoO0XTdkYyuTNw",
"type": "move",
"action": "creation" ,
"timestamp": "1372787849"
},
{
"user_xid": "RGaCBFg9CsB83FsEcMY44A",
"event_xid": "blaHyAtwoO0XTdkYyuTNw",
"type": "sleep",
"action": "updation" ,
"timestamp": "1372787859"
}
],
"secret_hash": "e570b3071a0964f9e2e69d13nd9ba19535392aaa",
}
Then you know that a move event was created and that a sleep event was updated for the user specified by user_xid: RGaCBFg9CsB83FsEcMY44A
Use this user's xid to determine which previously saved access_token to send with your next API requests.
You can get the details for the move event by sending a request to the moves endpoint with the event_xid: EJpCkyAtwoO0XTdkYyuTNw:
GET https://jawbone.com/nudge/api/v.1.1/moves/EJpCkyAtwoO0XTdkYyuTNw
And yo ucan get the details for the sleep event by querying the sleeps endpoint with the event_xid: blaHyAtwoO0XTdkYyuTN:
GET https://jawbone.com/nudge/api/v.1.1/sleeps/blaHyAtwoO0XTdkYyuTN