IoT-Agent checks default attributes that are not in the iot payload - iot

I have a test environment where I have configured a service group for the JSON IoT Agent with a legacy expression in it:
{
"_id": "60acc2d549e4721ae5087356",
"__v": 0,
"iotagent": "http://10.0.0.2:4062",
"apikey": "apikeyTest2",
"entity_type": "WasteContainer",
"service_path": "/subservice",
"service": "service",
"resource": "/iot/json",
"description": "IoTAgent JSON - Node.js",
"protocol": "IoTA-JSON",
"internal_attributes": [],
"attributes": [
{
"name": "temperature",
"object_id": "t",
"type": "Number"
},
{
"name": "fillingLevel",
"expression": "${#level/100}",
"type": "Number"
}
],
"lazy": [],
"static_attributes": [],
"commands": []
}
Apart from that I register manually a device with a "jexl" as expression language:
curl --location --request POST 'https://host/iot/devices' \
--header 'Fiware-Service: service' \
--header 'Fiware-ServicePath: /subservice' \
--header 'X-Auth-Token: gAAAAABgrQm..._R8r98aeNWQ' \
--header 'Content-Type: application/json' \
--data-raw '{
"devices": [
{
"device_id": "deviceJSON1",
"entity_name": "device:entity01",
"entity_type": "device",
"expressionLanguage": "jexl",
"attributes": [
{
"object_id": "b",
"name": "position",
"type": "Number",
"expression": "(a+b)"
}
],
"protocol": "IoTA-JSON",
"transport": "HTTP"
}
]
}
'
Then I send data from the device using the apikey of the previous service group, but without using any attribute configured there:
curl --location --request POST 'http://host/iot/json?k=apikeyTest2&i=deviceJSON1&getCmd=0' \
--header 'Content-Type: application/json' \
--data-raw '{
"a": 4,
"b": 5
}'
The response is 400 Bad Request:
{
"name": "INVALID_EXPRESSION",
"message": "Invalid expression in evaluation [${#level/100}]"
}
Is this the expected result or should the agent try to use the "jexl" to transform the payload as there is not level attribute in the iot data?
To solve this I can create another service group with a different apikey and without default attributes, but just wanted to know if the result was the expected.

Related

Create issue with custom field by JIRA API

I want to create an issue using Jira REST API. Below code will works to create simple issue:
curl --request POST \
--url 'https://company_name.atlassian.net/rest/api/3/issue' \
--user 'user:token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data {
"fields": {
"summary": "Remote test with request type",
"issuetype": {
"id": "12542"
},
"project": {
"key": "Test"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Second remote test",
"type": "text"
}
]
}
]
}
}
}
The thing is I want to create an issue with custom field - customfield_10029. By default it's set as nil but when I changed it manually in my board I saw something few more things inside of it:
"customfield_10029":
{"_links": {"jiraRest": "https://company_name.atlassian.net/rest/api/2/issue/241495", "web": "https://company_name.atlassian.net/servicedesk/customer/portal/19/SUP-11", "self": "https://company_name.atlassian.net/rest/servicedeskapi/request/241495"},
"requestType":
{"_expands": ["field"],
"id": "358",
"_links": {"self": "https://company_name.atlassian.net/rest/servicedeskapi/servicedesk/19/requesttype/358"},
"name": "Add Colaborator / Team Member",
"description": "e.g. external dev",
"helpText": "you can find github nicks down here https://github.com/some_url",
"issueTypeId": "12542",
"serviceDeskId": "19",
"groupIds": ["70"],
"icon":
{"id": "19558",
"_links":
{"iconUrls":
{"48x48": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=large",
"24x24": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=small",
"16x16": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=xsmall",
"32x32": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=medium"}}}}
So I thought the only thing I need to do is to add above code to the first POST request, like below:
curl --request POST \
--url 'https://company_name.atlassian.net/rest/api/3/issue' \
--user 'user:token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data {
"fields": {
"summary": "Remote test with request type",
"issuetype": {
"id": "12542"
},
"project": {
"key": "SUP"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Second remote test",
"type": "text"
}
]
}
]
},
"customfield_10029":
{"_links": {"jiraRest": "https://company_name.atlassian.net/rest/api/2/issue/241495", "web": "https://company_name.atlassian.net/servicedesk/customer/portal/19/SUP-11", "self": "https://company_name.atlassian.net/rest/servicedeskapi/request/241495"},
"requestType":
{"_expands": ["field"],
"id": "358",
"_links": {"self": "https://company_name.atlassian.net/rest/servicedeskapi/servicedesk/19/requesttype/358"},
"name": "Add Colaborator / Team Member",
"description": "e.g. external dev",
"helpText": "you can find github nicks down here https://github.com/some_url",
"issueTypeId": "12542",
"serviceDeskId": "19",
"groupIds": ["70"],
"icon":
{"id": "19558",
"_links":
{"iconUrls":
{"48x48": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=large",
"24x24": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=small",
"16x16": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=xsmall",
"32x32": "https://company_name.atlassian.net/secure/viewavatar?avatarType=SD_REQTYPE&avatarId=19558&size=medium"}}}}
}
}
But I'm getting an error:
{"errorMessages":["Unexpected end-of-input: expected close marker for OBJECT (from [Source: org.apache.catalina.connector.CoyoteInputStream#2e2743e7; line: 1, column: 0])\n at [Source: org.apache.catalina.connector.CoyoteInputStream#2e2743e7; line: 46, column: 1863]"]}
Is there any logic behind that? how to create such an issue with customfield?
Looks like you're missing a brace.
--data { #<- This brace has no closing brace
"fields": { #<- This brace closes with the very last brace

FIWARE Orion error 'Couldn't connect to server' forwarding 'Query' to providing application

I am trying to provision a device and send actuation commands back using 2 components Orion and LoRaWAN IoT Agent.
I am running Orion and other components on docker-compose file, and the IoT Agent using node bin/iotagent-lora
I have successfully provisioned the device using :
curl -iX POST \
'http://localhost:4061/iot/devices' \
-H 'Content-Type: application/json' \
-H 'fiware-service: agriculture' \
-H 'fiware-servicepath: /irrigation' \
-d '{
"devices": [
{
"device_id": "pycom1",
"entity_name": "urn:ngsi-ld:tempHumid:001",
"entity_type": "tempHumid",
"transport": "MQTT",
"attributes": [
{
"object_id": "temperature",
"name": "deviceState",
"type": "Text"
}],
"commands": [
{
"name": "on",
"type": "command"
},
{
"name": "off"
,"type": "command"
}
],
"internal_attributes": {
"lorawan": {
"application_server": {
"host": "10.8.244.180",
"username": "admin",
"password": "admin",
"provider": "loraserver.io"
},
"dev_eui": "0097da62c6b67443",
"app_eui": "70B3D57ED000985F",
"application_id": "1",
"application_key": "2b043fb00af7c6ac4075a35b8a18fc9c",
"data_model":"application_server"
}}}]}'
an automatic registrations is created in Orion after provisioning the device:
{
"id": "5d2d9f4f795d881c2355ab7c",
"expires": "2020-07-16T09:56:31.00Z",
"dataProvided": {
"entities": [{
"id": "urn:ngsi-ld:tempHumid:001",
"type": "tempHumid"
}],
"attrs": ["on", "off"]
},
"provider": {
"http": {
"url": "http://localhost:4061"
},
"supportedForwardingMode": "all",
"legacyForwarding": true
},
"status": "active"
}
Following this tutorial I have created another registration for actuation commands like the following:
curl -iX POST \
'http://localhost:1026/v2/registrations' \
-H 'Content-Type: application/json' \
-H 'fiware-service: agriculture' \
-H 'fiware-servicepath: /irrigation' \
-d '{
"description": "Pump Commands",
"dataProvided": {
"entities": [
{
"id": "urn:ngsi-ld:tempHumid:001",
"type": "tempHumid"
}
],
"attrs": [ "on", "off" ]
},
"provider": {
"http": {"url": "http://localhost:1026/v1"},
"legacyForwarding": true
}
}'
I have tried to use the proposed solution to an issue similar to the one I am facing, and after trying, I have obtained this error:
{"error":"NotFound","description":"The requested entity has not been found. Check type and id"}
while Orion reported
fiware-orion Starting transaction to http://localhost:4061//updateContext
I don't know if it is linked to this issue but a similar bug (double slash in url) was already reported in here
fiware-orion | INFO#10:16:34 logMsg.h[1844]: Starting transaction to http://localhost:4061//updateContext
fiware-orion | INFO#10:16:34 httpRequestSend.cpp[592]: Sending message 4 to HTTP server: sending message of 447 bytes to HTTP server
fiware-orion | ERROR#10:16:34 postUpdateContext.cpp[190]: Runtime Error (error 'Couldn't connect to server' forwarding 'Update' to providing application)
fiware-orion | INFO#10:16:34 logMsg.h[1874]: Transaction ended
Thank you in advance

Orion Context Broker Post ":" character

When I make a POST call to the Orion Context Broker and the entity
"type": "geo:json" contains the ":" character I obtain:
{"error":"InternalError","description":"Database Error (collection: orion-carouge.entities - insert(): { _id: { id: "10_Place_Nations"....
curl -X POST \
http://<entityID>:port/v2/entities \
-H 'Content-Type: application/json' \
-H 'fiware-service:carouge' \
-H 'Fiware-ServicePath:/Traffic' \
-d '{ "type": {
"value": "Traffic"
},
"dateObserved": {
"value": "2019-05-22T21:26:00"
},
"id": "10_Place_Nations",
"location": {
"value": {
"coordinates": [
[
6.130983321064038,
46.21602766413273
]
],
"type" : "Point"
},
"type": "geo:json"
},
}'\
Apparently this is not a problem in the MongoDB of Orion. I am able to insert the "type": "geo:json" in the MongoDB. Probably some validation before making the post call, cause the problem. Any contribution will be very appreciated.
I think the problem is that your request has two errors.
First, you cannot use a JSON object as entity type. Entity types must be strings. Thus you have to use:
"type": "Traffic"
Second, the GeoJSON object you are using for location value is incorrect. Point uses a single coordinate in coordinates, not a list.
In sum, the following request will work:
curl -X POST \
http://localhost:1026/v2/entities \
-H 'Content-Type: application/json' \
-H 'fiware-service:carouge' \
-H 'Fiware-ServicePath:/Traffic' \
-d '{ "type": "Traffic",
"dateObserved": {
"value": "2019-05-22T21:26:00"
},
"id": "10_Place_Nations",
"location": {
"value": {
"coordinates": [
6.130983321064038,
46.21602766413273
],
"type" : "Point"
},
"type": "geo:json"
}
}'

Why does this Cypher return an array of arrays for the `data` key?

Query
curl -X POST \
http://my-neo4j.example.com:7474/db/data/cypher \
-H 'Accept: application/json; charset=UTF-8' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'Postman-Token: 10c0796f-d397-4c05-8f6d-9dcde4baca8a' \
-d '{
"query" : "MATCH (c:category) RETURN c {.categoryName} ORDER BY c.categoryName"
}'
Response
{
"columns": [
"c"
],
"data": [
[
{
"categoryName": "Scenario"
}
],
[
{
"categoryName": "Theme"
}
],
[
{
"categoryName": "Video Mood"
}
]
]
}
Question: Why doesn't the result look like this…
{
"columns": [
"c"
],
"data": [
{
"categoryName": "Scenario"
},
{
"categoryName": "Theme"
},
{
"categoryName": "Video Mood"
}
]
}
❓
The returned data is an array of rows.
Each row is an array of columns (one for each item in the RETURN clause).
RETURN c {.categoryName} returns just a single column. And, since you used a map projection to specify the column value, the resulting value is a map (that contains a single field in your case).
If your query had used RETURN c.categoryName instead of RETURN c {.categoryName}, then you might of found the result to be less confusing:
{
"columns": [
"c.categoryName"
],
"data": [
[
"Scenario"
],
[
"Theme"
],
[
"Video Mood"
]
]
}

How to get the status of a travis-ci request

I want to trigger a travis run on the master branch of a repository. That works alright following the instructions in the travis docs, but then I don't know how to get the status of the execution. The request returns some IDs, but none seem to be the request id.
$ body='{
"request": {
"branch":"master"
}}'
$ curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Travis-API-Version: 3" -H "Authorization: token $TOKEN" -d "$body" https://api.travis-ci.org/repo/snapcore%2Fsnapcraft/requests
{
"#type": "pending",
"remaining_requests": 9,
"repository": {
"#type": "repository",
"#href": "/repo/6402925",
"#representation": "minimal",
"id": 6402925,
"name": "snapcraft",
"slug": "snapcore/snapcraft"
},
"request": {
"repository": {
"id": 45199136,
"owner_name": "snapcore",
"name": "snapcraft"
},
"user": {
"id": 38186
},
"message": null,
"branch": "master",
"config": {
}
},
"resource_type": "request"
}
I can get all the requests using this endpoint: https://docs.travis-ci.com/api?http#requests
But then I would have to find my request, and again I'm not sure how to identify it.
The response should include a request.id as well:
{
"#type": "pending",
"remaining_requests": 49,
"repository": {
"#type": "repository",
"#href": "/repo/7181875",
"#representation": "minimal",
"id": 7181875,
"name": "repo_name",
"slug": "repo_user/repo_name"
},
"request": {
"repository": {
"id": 160982756,
"owner_name": "repo_owner",
"name": "repo_name"
},
"user": {
"id": 919859
},
"id": 160105240, # <-- this is the request ID that can be used in /request/#id
"message": null,
"branch": "master",
"config": {
}
},
"resource_type": "request"
}
This seems to be missing from what you posted. Either this was added in the meantime, or it got lost for you somehow.

Resources