Skip to content

Commit 98c9cb2

Browse files
authored
Merge pull request #13 from flightaware/BCK-7183_update_README_clarifications
Update README Clarifications Add endpoint to return endpoint for where triggered alerts are sent. BCK-7183
2 parents 0726b9d + 762c6c9 commit 98c9cb2

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

.env-sample

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
AEROAPI_KEY=key
1+
AEROAPI_KEY=key
2+
POST_PORT=8081
3+
WEB_SERVER_PORT=8080

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ and `docker-compose up` creates containers from those images and launches them.
3232
If you'd like to build the images yourself, you can instead run
3333
`docker-compose up --build`.
3434

35-
*For alert creation, the commands will all be the same except add `-f
36-
docker-compose-alerts.yml` to utilize the alerts docker compose file. For
35+
*For alert creation, the commands will all be the same except add `-f
36+
docker-compose-alerts.yml` to utilize the alerts docker compose file. For
3737
example, instead of `docker-compose --profile python up`, you should have
3838
`docker-compose -f docker-compose-alerts.yml --profile python up`*.
3939

@@ -45,3 +45,35 @@ log as requests are made to them.
4545
You can test out the FIDS/Alerts sample application by visiting http://localhost:8080 in
4646
your web browser (if not running Docker locally, use the Docker host's
4747
address).
48+
49+
## Alerts Backend Note:
50+
51+
Whenever an event is triggered for an alert, AeroAPI will send a POST request to your
52+
configured endpoint. In order to configure your endpoint, you need to publicly expose its
53+
address/port (specified using the POST_PORT environment variable, NOT the WEB_SERVER_PORT variable).
54+
Furthermore, as noted in the docker-compose-alerts.yml file, we encourage the service for
55+
accepting POSTed triggered alerts to be isolated, and thus will be sent to a different Docker
56+
container. This means that you will have to set the endpoint URL using /post, instead of /api/post.
57+
In order to get send your alerts to this webapp, you should configure this webapp
58+
(http://localhost:8081/post for example) to receive alerts using a REST client like cURL,
59+
like the following command:
60+
```
61+
curl --location --request PUT 'https://aeroapi.flightaware.com/aeroapi/alerts/endpoint' \
62+
--header 'Content-Type: application/json; charset=UTF-8' \
63+
--header 'x-apikey: <YOUR API KEY>' \
64+
--data-raw '{
65+
"url": "http://<YOUR IP>:8081/post"
66+
}'
67+
```
68+
(see the [documentation](https://flightaware.com/aeroapi/portal/documentation#put-/alerts/endpoint)
69+
for more information). NOTE: if you previously configured a different production endpoint to receive alerts,
70+
**you will change the same URL!** This means that ALL of your configured alerts
71+
will all be sent to the newly configured endpoint.
72+
73+
You can see this newly configured URL by going to FlightAware's
74+
[push notification testing page](https://flightaware.com/commercial/aeroapi/send.rvt)
75+
or by going to the alert creation page on the webapp. On this push notification testing
76+
page, you can also do two things: test your configured endpoint on the backend to see if it
77+
receives a test triggered alert properly, and also see the success/failure of triggered alerts
78+
that were sent up to 24 hours in the past. If there was an error it will display the
79+
full error message.

alerts_backend/python/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ def delete_from_table(fa_alert_id: int) -> int:
141141
return 0
142142

143143

144+
@app.route("/endpoint")
145+
def get_endpoint_url() -> Response:
146+
"""
147+
Return the configured endpoint URL for AeroAPI to send POST requests as a JSON payload.
148+
"""
149+
api_resource = "/alerts/endpoint"
150+
logger.info(f"Making AeroAPI request to GET {api_resource}")
151+
result = AEROAPI.get(f"{AEROAPI_BASE_URL}{api_resource}")
152+
url = "NO ENDPOINT CONFIGURED"
153+
if result.json():
154+
url = result.json()["url"]
155+
return jsonify({"url": url})
156+
157+
144158
@app.route("/delete", methods=["POST"])
145159
def delete_alert() -> Response:
146160
"""

0 commit comments

Comments
 (0)