No Notification from Orion Context Broker - fiware-orion

I am working with the Orion Context Broker and wanna get notifications for the following subscription, added to orion.lab.fiware.org:1026:
curl -v orion.lab.fiware.org:1026/v2/subscriptions -X POST -s -S --header 'Content-Type: application/json' --header "X-Auth-Token: <myToken>" -d #- <<EOF
{
"description": "A subscription to get info about Room1",
"subject": {
"entities": [
{
"id": "11582",
"type": "User"
}
],
"condition": {
"attrs": [
"temperature"
]
}
},
"notification": {
"http": {
"url": "http://<myIPAddress>:8080"
},
"attrs": [
"temperature"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
myToken: the token generated by the FIWARE server
myIPAddress: the IP address of my PC
However, in my sample HTTP server program (Node.js) on port 8080 I do not receive any notifications. I should note that after adding the above subscription, I add the entity with id 11582 through another POST request to orion.lab.fiware.org:1026/v2/entities.
When I read later the added subscription, it confirms that the notification has been sent (through lastNotification):
{
"id": "5768088c70dce43aa351cf9b",
"description": "A subscription to get info about Room1",
"expires": "2040-01-01T14:00:00.00Z",
"status": "active",
"subject": {
"entities": [
{
"id": "11582",
"idPattern": "",
"type": "User"
}
],
"condition": {
"attrs": [
"temperature"
]
}
},
"notification": {
"timesSent": 1,
"lastNotification": "2016-06-20T15:16:04.00Z",
"attrs": [
"temperature"
],
"attrsFormat": "normalized",
"http": {
"url": "http://<myIPAddress>:8080"
}
},
"throttling": 5
}
Any idea why I do not receive the notification i my HTTP server program? My firewall is also off.
Thanks!

The following test has been donde in orion.lab.fiware.org. The termina1l.txt file shows the subscriptions and entity creation request sent to Orion (note we use localhost:10026, as the test has been done in the orion.lab.fiware.org host itself) and terminal2.txt file shows the notification received at the listener process (nc).
We have also done the same test (using UserTest2 type this time) running the listener on a VM machine at FIWARE Lab (which IP cannot be disclosed for security reasons) with the 1028 port openend in the Security Group and everything worked fine again, getting:
POST / HTTP/1.1
user-agent: orion/1.2.1 libcurl/7.19.7
host: 130.206.112.29:1028
accept: application/json
content-length: 146
content-type: application/json; charset=utf-8
fiware-correlator: 0870b41c-378d-11e6-910f-52540003a38e
ngsiv2-attrsformat: normalized
X-Forwarded-For: 127.0.0.1
Connection: keep-alive
{"subscriptionId":"5768ff6a70dce43aa351cfaa","data":[{"id":"11582","type":"UserTest2","temperature":{"type":"Float","value":23.5,"metadata":{}}}]}
Thus, I understand that something between orion.lab.fiware.org and your process is blocking the traffic. Note that apart for the firewall running in your machine (which you mention is off) another firewall layer could be blocking (e.g. FIWARE cloud or AWS cloud security group, coorporate firewalls, etc.)

Related

FIWARE Orion: notification responses

In Orion I can create subscription:
curl localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' \
-d #- <<EOF
{
"description": "A subscription to get info about Room1",
"subject": {
"entities": [
{
"id": "Room1",
"type": "Room"
}
],
"condition": {
"attrs": [
"pressure"
]
}
},
"notification": {
"http": {
"url": "http://localhost:1028/accumulate"
},
"attrs": [
"temperature"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
In this example, Orion will perform POST request on the server http://localhost:1028/accumulate. Is there a way to retrieve the response from the POST received by Orion? i.e. 200, 404...
In my use case the notifications perform POST requests to create some resources on another server. The POSTs returns the location of the created resources. It would be useful to retrieve those locations.
Orion doesn't record the responses to notifications it sends. It implements a "fire and forget" approach and pays little attention to the response of notification requests. Actually, Orion looks to the response of the last notification and uses it to set lastFailure or lastSuccess timestamp (depending the case) and setting status to failed if the response has an error code.
A workaround for your case could be achieved using a system in the middle. I mean, some bridging software that receives the notification from Orion, forwards to the final system, gets the response and does whatever processing should be do with such response (e.g. storing the location of the just created resource).

FIWARE Orion: return subscription id

When creating a subscription, it would be nice to return the subscription ID.
For instance, the following code doesn't return anything :
curl localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' \
-d #- <<EOF
{
"description": "A subscription to get info about Room1",
"subject": {
"entities": [
{
"id": "Room1",
"type": "Room"
}
],
"condition": {
"attrs": [
"pressure"
]
}
},
"notification": {
"http": {
"url": "http://localhost:1028/accumulate"
},
"attrs": [
"temperature"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
In the subscription case, the resource id is generated server-side (with difference to the entities endpoint, where the id is decided client-side).
It would be nice to return it in the POST call, is there any way to do this?
Subscription ID is retrieved in Location header in the response to the subscription creation request, eg:
Location: /v2/subscriptions/5b991dfa12f473cee6651a1a
More details in the NGSIv2 API specification (check "Create Subscription" section).

Fiware Orion CB subscriptions throttling

I have created this subscription :
curl localhost:1026/v2/subscriptions -s -S -H 'Accept: application/json' | python -mjson.tool
[
{
"description": "Update room temperature",
"expires": "2020-04-05T14:00:00.00Z",
"id": "5b104ace028f2284c5517f51",
"notification": {
"attrs": [
"temperature"
],
"attrsFormat": "normalized",
"http": {
"url": "http://MyUrl/getSub"
},
"lastNotification": "2018-05-31T19:19:42.00Z",
"metadata": [
"5b019ae132232812eccb6d50",
"device",
"16",
"Auto",
"30",
"greater"
],
"timesSent": 1
},
"status": "active",
"subject": {
"condition": {
"attrs": [
"temperature"
]
},
"entities": [
{
"id": "5aff0eef23102126a4aeeea2",
"type": "room"
}
]
},
"throttling": 60
}
and even though I have set the throttling at 60 (1 minute if I understand it right), when I change the value of the temperature, orion sends me a notification even if the change happened before the one minute mark (for example I change the temperature value every 10 seconds). Shouldn't a notification be sent only if a change occurred after 60 seconds or am I understanding something wrong?
What you describe seems to be the right behaviour. I mean, if the subscription has a throttling of 60 seconds, you shouldn't receive any new notifiction until 60 seconds have passed from the previous one.
Possible causes:
You have another subscripion in place that is being triggered. But I understand this is not the case, as such subscription should be shown in the GET /v2/subscriptions result.
There is a bug in Orion which causes throttling to be ignored. In that case, it would be interesting to do the same test using a subscription created using NGSIv1 (using POST /v1/subscribeContext) in order to know the reach of the bug.

Fiware Orion subscription to STH in NGSI V2 with legacy values

Im working with sth, with ngsi v1 i dont have any problems. When i try to use it with ngsi v2 ( trough legacy values) im having several problems.
Im creating a subscription in v2 in this way:
POST /v2/subscriptions HTTP/1.1
Host: <orion-context-broker-host>:<orion-context-broker-port>
Content-Type: application/json
fiware-service: xxxx
fiware-servicepath: /xxxx
{
"description": "Probando legacy",
"subject": {
"entities": [
{
"id": "sthlegacy2",
"type": "NGSIV2"
}
],
"condition": {
"attrs": []
}
},
"notification": {
"attrsFormat":"legacy",
"http": {
"url": "http://<sth-host>:<sth-port>/notify"
},
"attrs": []
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 0
}
The subscription is well created but when i try to update a value the subscription state changes to "failed", and it does not create anything in sth.
I would appreciate a solution, something I must be doing wrong.

How to make a entity creation?

I create my Instance on the CLOUD but when try to do a POST the data are not send to the VM, something is wrong with the data I use ?
I'm using Rest Client on Firefox.
This is the body of the code (Json) :
{
"contextElements": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1",
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "23"
},
{
"name": "pressure",
"type": "integer",
"value": "720"
}
]
}
],
"updateAction": "APPEND"
}
The URL is http://10.0.22x.6x:1026/NGSI10/updateContext and the headers are:
Content-Type: application/json
Accept: application/json
Note that you are sending your REST request to a private IP (10.0.22x.6x). However, I guess that you run your Firefox REST Client in a PC or laptop computer without direct connectivity to that IP.
The solution would be to allocate a public IP to the VM, then access to that public IP from your external REST Client. Note that you need the port 1026 opened in the security group associated to that VM (otherwise the cloud will block any attemp to connect to it from an external host).