Creation of events from incoming webhooks

Within the Milestone infrastructure, we are evaluating the possibility of creating generic events when incoming webhooks are received from an external MQTT broker. The body of the JSON sent externally has the following structure:

{
“timestamp”: 1559295045797,
“rule”: {
“id”: “d9aa6b19-ffdd-4a47-aabd-22632e7ec31b”,
“name”: “Rule test”
},
“status”: “started”,
“measures”: [
{
“value1”: -12,

}
],
“deviceInfo”: {
“label”: “device 1”,
“serial”: “8945G326”,
“id”: “a7f687fd-f74b-47be-adb5-0c8797d4213f”,
“devEui”: “0011223344326677”
}
}

Could you please indicate the methodology to follow in order to implement this integration? Thank you.

Generic events in XProtect receive an text string and then using filter an event is generated. The event can be used in rules, to trigger some action e.g. start recording on a camera. The information submitted, the text string, is not saved in XProtect.

It might be exactly what you need.

If you want data to be saved and available for your integration later you might want to use Analytics Events instead.

See also the events described here.

To give any better advise I need a better understanding of what the event is supposed to achieve. Please elaborate if the links doesn’t answer your question.

Thank you for your replies. I will try to better clarify the objective of creating the event.

The goal is to receive these incoming JSON messages in the system in order to generate an event that can be associated with an alarm visible in the Alarm Manager tab.

For example, if I receive a JSON like this, I would like to have an alarm entry showing:

  • Source: “Label 1” from the JSON (identifier of the sensor generating the event)

  • Time: “Timestamp” (time when the event is received)

  • Alarm: “Status” from the JSON (it always consists of two states, ON/OFF – for example open/closed)

Thank you

You need Analytics Events. We can conclude that what in Milestone terms are called Generic Events is something different, and not what you should use.

XProtect has a REST API where you can POST Analytics Events.

Your job would be to get the MQTT event, potentially transform its JSON payload to the Analytics Events REST API JSON payload format, acquire a bearer token, and POST it to the XProtect API…!

PS. The MIP SDK has other methods of sending an Analytics Event since you already have JSON I assume the Rest API will be your favorite choice.

Thank you for your support.

Since there will be an API Manager between the external system and Milestone, the field mapping/conversion will need to be handled at the API Manager level, so that Milestone receives a message structured like the one below. Are the fields shown in this example mandatory, and is it not possible to define additional ones?

{
  "type": "481d4d6c-9156-4698-af7e-74b32f9e4359",
  "source": "cameras/e028f597-c64b-4f27-bb8d-08f5cd768e1c",
  "time": "2009-02-15T00:00:00.0000000Z",
  "datatype": "analytics",
  "tag": "My custom tag",
  "data": { }
}

Regarding authentication from the API Manager to Milestone, how does authentication take place (i.e., obtain a token from /IDP/connect/token and pass it as a Bearer token)? Is it possible to authenticate using OAuth 2.0 with a Client ID and Client Secret?

Thank you

If you look at the documentation, you’ll see that both type and datatype are required fields. If you expand data, you’ll find several additional fields that you can use.

I believe I’ve shared this link before, so if it still doesn’t address your question, please let me know and I’ll be happy to clarify further.

Regarding authentication, please go to the beginning of the linked page. The Milestone API Gateway uses OAuth2, but since it does not support client registration with a Client ID and Client Secret, you must authenticate with a username and password instead.