Skip to main content

Install a trigger

We will use a trigger to test Data Orchestrator's push capabilities. In this case, we will send a POST to a URL of our choice every time the value generated by stream_test is above 0.6.

Due to how triggers work, it is fundamental to install the trigger before a device connects. Doing otherwise will cause the trigger to kick in at a later time, and as such no events will be streamed for a while.

Replace $TRIGGER_TARGET_URL with your target URL in the example below, you can use a Postbin service like Mailgun Postbin to generate a URL and see the POST requests. The resulting trigger would be:

{
"name": "my_trigger",
"action": {
"http_url": "$TRIGGER_TARGET_URL",
"http_method": "post"
},
"simple_triggers": [
{
"type": "data_trigger",
"on": "incoming_data",
"interface_name": "org.astarte-platform.genericsensors.Values",
"interface_major": 1,
"match_path": "/streamTest/value",
"value_match_operator": ">",
"known_value": 0.6
}
]
}

Replace $TRIGGER_TARGET_URL with the URL your Trigger will target. Assuming you saved this as my_trigger.json, you can now install it through astartectl:

$ astartectl realm-management triggers install my_trigger.json --astarte-url http://api.astarte.localhost -r test -k test_private.pem

You can now check that your trigger is correctly installed:

$ astartectl realm-management triggers ls --astarte-url http://api.astarte.localhost -r test -k test_private.pem