iotagent-node-lib 3.2.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +134 -0
  2. package/.github/ISSUE_TEMPLATE/config.yml +16 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.yml +55 -0
  4. package/.github/advanced-issue-labeler.yml +30 -0
  5. package/.github/workflows/issue-labeler.yml +43 -0
  6. package/README.md +10 -11
  7. package/doc/README.md +16 -0
  8. package/doc/admin.md +565 -0
  9. package/doc/api.md +32 -85
  10. package/doc/deprecated.md +16 -10
  11. package/doc/{architecture.md → devel/architecture.md} +3 -3
  12. package/doc/{Contribution.md → devel/contribution-guidelines.md} +43 -35
  13. package/doc/devel/development.md +1879 -0
  14. package/doc/{northboundinteractions.md → devel/northboundinteractions.md} +18 -33
  15. package/doc/index.md +3 -5
  16. package/doc/requirements.txt +1 -1
  17. package/docker/Mosquitto/Dockerfile +1 -1
  18. package/docker/Mosquitto/README.md +1 -0
  19. package/lib/commonConfig.js +0 -5
  20. package/lib/fiware-iotagent-lib.js +1 -1
  21. package/lib/jexlTranformsMap.js +2 -1
  22. package/lib/model/Device.js +0 -1
  23. package/lib/model/Group.js +0 -1
  24. package/lib/model/dbConn.js +1 -7
  25. package/lib/plugins/jexlParser.js +1 -1
  26. package/lib/request-shim.js +2 -2
  27. package/lib/services/commands/commandService.js +1 -1
  28. package/lib/services/common/genericMiddleware.js +1 -1
  29. package/lib/services/common/iotManagerService.js +0 -1
  30. package/lib/services/devices/deviceRegistryMemory.js +2 -2
  31. package/lib/services/devices/deviceRegistryMongoDB.js +32 -19
  32. package/lib/services/devices/deviceService.js +44 -43
  33. package/lib/services/devices/devices-NGSI-LD.js +14 -2
  34. package/lib/services/devices/devices-NGSI-mixed.js +0 -2
  35. package/lib/services/devices/devices-NGSI-v2.js +23 -104
  36. package/lib/services/groups/groupService.js +1 -1
  37. package/lib/services/ngsi/entities-NGSI-LD.js +3 -3
  38. package/lib/services/ngsi/entities-NGSI-v2.js +28 -19
  39. package/lib/services/northBound/deviceProvisioningServer.js +14 -8
  40. package/lib/templates/createDevice.json +0 -4
  41. package/lib/templates/createDeviceLax.json +0 -4
  42. package/lib/templates/deviceGroup.json +1 -5
  43. package/lib/templates/updateDevice.json +4 -0
  44. package/lib/templates/updateDeviceLax.json +11 -0
  45. package/mkdocs.yml +6 -11
  46. package/package.json +3 -3
  47. package/scripts/legacy_expression_tool/README.md +280 -0
  48. package/scripts/legacy_expression_tool/legacy_expression_tool.py +423 -0
  49. package/scripts/legacy_expression_tool/requirements.txt +3 -0
  50. package/test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice4.json +0 -1
  51. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +5 -15
  52. package/test/unit/mongodb/mongodb-registry-test.js +1 -1
  53. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +66 -65
  54. package/test/unit/ngsi-ld/general/https-support-test.js +1 -1
  55. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +8 -7
  56. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +31 -30
  57. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +12 -11
  58. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +41 -39
  59. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +122 -122
  60. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +28 -28
  61. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +18 -17
  62. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +7 -7
  63. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +8 -7
  64. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +33 -37
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContext.json +2 -0
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContext1.json +3 -1
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json +2 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContext4.json +4 -1
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContext5.json +12 -0
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContext6.json +12 -0
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -0
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin2.json +3 -1
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin3.json +3 -1
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin4.json +3 -1
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin5.json +3 -1
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin6.json +3 -1
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin7.json +3 -1
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +3 -1
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin9.json +3 -1
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +2 -0
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +2 -0
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +3 -1
  83. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +3 -1
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +3 -1
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +3 -1
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +3 -1
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandError.json +3 -1
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandExpired.json +3 -1
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandFinish.json +3 -1
  90. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus.json +2 -0
  91. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +2 -0
  92. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp1.json +3 -1
  93. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp2.json +3 -1
  94. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +2 -12
  95. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +2 -4
  96. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -4
  97. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin13.json +3 -1
  98. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +2 -12
  99. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +2 -12
  100. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +2 -4
  101. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +2 -0
  102. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +2 -0
  103. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +2 -0
  104. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +2 -0
  105. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +2 -0
  106. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +2 -0
  107. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +1 -0
  108. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +2 -0
  109. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +1 -1
  110. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +1 -10
  111. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +2 -4
  112. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +2 -4
  113. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +2 -4
  114. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +2 -12
  115. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +2 -4
  116. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionSkip.json +12 -0
  117. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +1 -1
  118. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +1 -1
  119. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
  120. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +1 -1
  121. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +1 -1
  122. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +1 -1
  123. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +1 -1
  124. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +1 -1
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +1 -1
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +1 -1
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +1 -1
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +2 -6
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +1 -1
  135. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
  136. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +1 -1
  137. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -1
  138. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  139. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -0
  140. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +2 -0
  141. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributes.json +2 -0
  142. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +3 -1
  143. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestamp.json +3 -1
  144. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalse.json +12 -0
  145. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalseTimeInstant.json +12 -0
  146. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +2 -0
  147. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +2 -0
  148. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampTimezone.json +3 -1
  149. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +144 -85
  150. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +20 -53
  151. package/test/unit/ngsiv2/general/https-support-test.js +2 -6
  152. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +4 -10
  153. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +8 -24
  154. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +146 -65
  155. package/test/unit/ngsiv2/ngsiService/autocast-test.js +14 -21
  156. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +3 -5
  157. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +11 -20
  158. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +20 -30
  159. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +4 -6
  160. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +1 -2
  161. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +3 -5
  162. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -3
  163. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +2 -3
  164. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +13 -156
  165. package/test/unit/ngsiv2/provisioning/device-registration_test.js +9 -13
  166. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +4 -10
  167. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -11
  168. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +0 -8
  169. package/test/unit/plugins/capture-provision-inPlugins_test.js +0 -6
  170. package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
  171. package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
  172. package/.nyc_output/processinfo/index.json +0 -1
  173. package/doc/config-basic-example.js +0 -20
  174. package/doc/development.md +0 -285
  175. package/doc/howto.md +0 -645
  176. package/doc/installationguide.md +0 -370
  177. package/doc/operations.md +0 -127
  178. package/doc/usermanual.md +0 -900
  179. package/lib/plugins/bidirectionalData.js +0 -356
  180. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +0 -697
  181. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +0 -599
  182. /package/doc/{NorthboundInteractions.postman_collection → devel/NorthboundInteractions.postman_collection} +0 -0
  183. /package/doc/{echo.js → devel/echo.js} +0 -0
  184. /package/doc/{finalResult.js → devel/finalResult.js} +0 -0
package/doc/admin.md ADDED
@@ -0,0 +1,565 @@
1
+ # Administration
2
+
3
+ - [Configuration](#configuration)
4
+ - [Configuration parameters:](#configuration-parameters)
5
+ - [loglevel](#loglevel)
6
+ - [contextBroker](#contextbroker)
7
+ - [server](#server)
8
+ - [stats](#stats)
9
+ - [authentication](#authentication)
10
+ - [deviceRegistry](#deviceregistry)
11
+ - [mongodb](#mongodb)
12
+ - [iotManager](#iotmanager)
13
+ - [types](#types)
14
+ - [service](#service)
15
+ - [subservice](#subservice)
16
+ - [providerUrl](#providerurl)
17
+ - [iotaVersion](#iotaversion)
18
+ - [dieOnUnexpectedError](#dieonunexpectederror)
19
+ - [singleConfigurationMode](#singleconfigurationmode)
20
+ - [timestamp](#timestamp)
21
+ - [defaultResource](#defaultresource)
22
+ - [defaultKey](#defaultkey)
23
+ - [componentName](#componentname)
24
+ - [pollingExpiration](#pollingexpiration)
25
+ - [pollingDaemonFrequency](#pollingdaemonfrequency)
26
+ - [autocast](#autocast)
27
+ - [multiCore](#multicore)
28
+ - [fallbackTenant](#fallbacktenant)
29
+ - [fallbackPath](#fallbackpath)
30
+ - [explicitAttrs](#explicitattrs)
31
+ - [defaultEntityNameConjunction](#defaultentitynameconjunction)
32
+ - [relaxTemplateValidation](#relaxtemplatevalidation)
33
+ - [Configuration using environment variables](#configuration-using-environment-variables)
34
+ - [Logs](#logs)
35
+ - [Errors](#errors)
36
+ - [Alarms](#alarms)
37
+
38
+ The **IoT Agent node library** is not a standalone product and should be added as a dependency to `package.json` of the
39
+ project is going to be used in. The library is published in the npm repository, so it can be added to the project by
40
+ adding the following line to the `package.json` file:
41
+
42
+ ```json
43
+ ...
44
+ "dependencies": {
45
+ "iotagent-node-lib": "x.y.z",
46
+ }
47
+ ```
48
+
49
+ wher `x.y.z` is an actual version number.
50
+
51
+ As alternative, you can use the master branch as dependency. In this case, you will be using the latest version of the
52
+ code but note that some instability could exist (as the code in master is work in progress until the next version is
53
+ closed).
54
+
55
+ ```json
56
+ ...
57
+ "dependencies": {
58
+ "iotagent-node-lib": "https://github.com/telefonicaid/iotagent-node-lib.git#master",
59
+ }
60
+ ```
61
+
62
+ In order to use the library within your own IoT Agent, you must first you require it before use:
63
+
64
+ ```javascript
65
+ const iotagentLib = require('iotagent-node-lib');
66
+ ```
67
+
68
+ ## Configuration
69
+
70
+ The `activate()` function that starts the IoT Agent receives as single parameter with the configuration for the IoT
71
+ Agent. The Agent Console reads the same configuration from the `config.js` file or from the environment variables. The
72
+ configuration parameters work in the same way in both cases but the environment variables have precedence over the
73
+ `config.js` file. The following sections describe the configuration parameters that can be used in the IoT Agent.
74
+
75
+ ### Configuration parameters:
76
+
77
+ These are the parameters that can be configured in the global section:
78
+
79
+ #### `loglevel`
80
+
81
+ It is the minimum log level to log. May take one of the following values: DEBUG, INFO, ERROR, FATAL. E.g.: 'DEBUG'.
82
+
83
+ #### `contextBroker`
84
+
85
+ It configures the connection parameters to stablish a connection to the Context Broker (host and port). E.g.:
86
+
87
+ ```javascript
88
+ {
89
+ host: '192.168.56.101',
90
+ port: '1026'
91
+ }
92
+ ```
93
+
94
+ - If you want to use **NGSI v2**:
95
+
96
+ ```javascript
97
+ {
98
+ host: '192.168.56.101',
99
+ port: '1026',
100
+ ngsiVersion: 'v2'
101
+ }
102
+ ```
103
+
104
+ - If you want to use **NGSI-LD** (experimental):
105
+
106
+ ```javascript
107
+ {
108
+ host: '192.168.56.101',
109
+ port: '1026',
110
+ ngsiVersion: 'ld',
111
+ jsonLdContext: 'http://context.json-ld' // or ['http://context1.json-ld','http://context2.json-ld'] if you need more than one
112
+ }
113
+ ```
114
+
115
+ Where `http://context.json-ld` is the location of the NGSI-LD `@context` element which provides additional information
116
+ allowing the computer to interpret the rest of the data with more clarity and depth. Read the
117
+ [JSON-LD specification](https://w3c.github.io/json-ld-syntax/#the-context) for more information.
118
+
119
+ - If you want to support a "mixed" mode with both **NGSI-v2** and **NGSI-LD** (experimental):
120
+
121
+ ```javascript
122
+ {
123
+ host: '192.168.56.101',
124
+ port: '1026',
125
+ ngsiVersion: 'mixed',
126
+ jsonLdContext: 'http://context.json-ld' // or ['http://context1.json-ld','http://context2.json-ld'] if you need more than one
127
+ }
128
+ ```
129
+
130
+ Under mixed mode, **NGSI v2** payloads are used for context broker communications by default, but this payload may also
131
+ be switched to **NGSI LD** at service group or device provisioning time using the `ngsiVersion` field in the
132
+ provisioning API. The `ngsiVersion` field switch may be added at either group or device level, with the device level
133
+ overriding the group setting.
134
+
135
+ #### `server`
136
+
137
+ This parameter is used to create the Context Server (port where the IoT Agent will be listening as a Context Provider
138
+ and base root to prefix all the paths). The `port` attribute is required. If no `baseRoot` attribute is used, '/' is
139
+ used by default. E.g.:
140
+
141
+ ```javascript
142
+ {
143
+ baseRoot: '/',
144
+ port: 4041
145
+ }
146
+ ```
147
+
148
+ When connected to an **NGSI-LD** context broker, an IoT Agent is able to indicate whether it is willing to accept `null`
149
+ values and also whether it is able to process the **NGSI-LD** `datasetId` metadata element. Setting these values to
150
+ `false` will cause the IoT Agent to return a 400 **Bad Request** HTTP status code explaining that the IoT Agent does not
151
+ support nulls or multi-attribute requests if they are encountered.
152
+
153
+ ```javascript
154
+ {
155
+ baseRoot: '/',
156
+ port: 4041,
157
+ ldSupport : {
158
+ null: true,
159
+ datasetId: true
160
+ }
161
+ }
162
+ ```
163
+
164
+ #### `stats`
165
+
166
+ It configures the periodic collection of statistics. Use `interval` in milliseconds to set the time between stats
167
+ writings.
168
+
169
+ ```javascript
170
+ stats: {
171
+ interval: 100;
172
+ }
173
+ ```
174
+
175
+ #### `authentication`
176
+
177
+ Stores the authentication data, for use in retrieving tokens for devices with a trust token (required in scenarios with
178
+ security enabled in the Context Broker side). Currently, two authentication provider are supported: `keystone` and
179
+ `oauth2`. Authentication need to be enabled by setting the field `enabled` to `true`. In `keystone` based
180
+ authentication, the `trust` associated to the `device` or `deviceGroup` is a token representing a specific user and his
181
+ rights on a given domain (i.e. combination of `fiware-service` and `fiware-servicepath`). The authentication process use
182
+ the trust delegation workflow to check if the trust provided is valid, in which case return a `x-subject-token` that can
183
+ be used to authenticate the request to the Context Broker. Required parameters are: the `url` of the keystone to be used
184
+ (alternatively `host` and `port` but if you use this combination, the IoT Agent will assume that the protocol is HTTP),
185
+ the `user` and `password` to which it is delegated the `trust` verification. E.g.:
186
+
187
+ ```javascript
188
+ {
189
+ enabled: true,
190
+ url: 'https://localhost:5000',
191
+ type: 'keystone',
192
+ user: 'iotagent',
193
+ password: 'iotagent'
194
+ }
195
+ ```
196
+
197
+ In `oauth2` based authentication, two types of tokens can be used depending on the availability in the IDM to be used.
198
+ On one hand, the `trust` associated to the `device` or `deviceGroup` is a `refresh_token` issued by a specific user for
199
+ the Context Broker client. The authentication process uses the
200
+ [`refresh_token` grant type](https://tools.ietf.org/html/rfc6749#section-1.5) to obtain an `access_token` that can be
201
+ used to authenticate the request to the Context Broker. At the time being the assumption is that the `refresh_token` is
202
+ a not expiring `offline_token` (we believe this is the best solution in the case of IoT Devices, since injecting a
203
+ refresh token look may slow down communication. Still, the developer would be able to invalidate the refresh token on
204
+ the provider side in case of security issues connected to a token). The code was tested using
205
+ [Keycloak](http://www.keycloak.org), [Auth0](https://auth0.com) and [FIWARE Keyrock](https://github.com/ging/fiware-idm)
206
+ (it may require customisation for other providers - while OAuth2 is a standard, not all implementations behave in the
207
+ same way, especially as regards status codes and error messages). Required parameters are: the `url` of the OAuth 2
208
+ provider to be used (alternatively `host` and `port` but if you use this combination, the IoT Agent will assume that the
209
+ protocol is HTTP), the `tokenPath` to which the validation request should be sent
210
+ (`/auth/realms/default/protocol/openid-connect/token` for Keycloak and Auth0, `/oauth2/token` for Keyrock), the
211
+ `clientId` and `clientSecret` that identify the Context Broker, and the `header` field that should be used to send the
212
+ authentication request (that will be sent in the form `Authorization: Bearer <access_token>`). E.g.:
213
+
214
+ ```javascript
215
+ {
216
+ enabled: true,
217
+ type: 'oauth2',
218
+ url: 'http://localhost:3000',
219
+ header: 'Authorization',
220
+ clientId: 'context-broker',
221
+ clientSecret: 'c8d58d16-0a42-400e-9765-f32e154a5a9e',
222
+ tokenPath: '/auth/realms/default/protocol/openid-connect/token'
223
+ }
224
+ ```
225
+
226
+ Nevertheless, this kind of authentication relying on `refresh_token` grant type implies that when the acces_token
227
+ expires, it is needed to request a new one from the IDM, causing some overhead in the communication with the Context
228
+ Broker. To mitigate this issue, FIWARE KeyRock IDM implements `permanent tokens` that can be retrieved using
229
+ `scope=permanent`. With this approach, the IOTA does not need to interact with the IDM and directly include the
230
+ `permanent token` in the header. In order to use this type of token, an additional parameter `permanentToken` must be
231
+ set to `true` in the `authentication` configuration. An environment variable `IOTA_AUTH_PERMANENT_TOKEN` can be also
232
+ used for the same purpose. For instance:
233
+
234
+ ```javascript
235
+ {
236
+ type: 'oauth2',
237
+ url: 'http://localhost:3000',
238
+ header: 'Authorization',
239
+ clientId: 'context-broker',
240
+ clientSecret: '0c2492e1-3ce3-4cca-9723-e6075b89c244',
241
+ tokenPath: '/oauth2/token',
242
+ enabled: true,
243
+ permanentToken: true
244
+ }
245
+ ```
246
+
247
+ #### `deviceRegistry`
248
+
249
+ Stores type of Device Registry to create. Currently, two values are supported: `memory` and `mongodb`. If the former is
250
+ configured, a transient memory-based device registry will be used to register all the devices. This registry will be
251
+ emptied whenever the process is restarted. If the latter is selected, a MongoDB database will be used to store all the
252
+ device information, so it will be persistent from one execution to the other. Mongodb databases must be configured in
253
+ the `mongob` section (as described bellow). E.g.:
254
+
255
+ ```javascript
256
+ {
257
+ type: 'mongodb';
258
+ }
259
+ ```
260
+
261
+ #### `mongodb`
262
+
263
+ It configures the MongoDB driver for those repositories with 'mongodb' type. If the `host` parameter is a list of
264
+ comma-separated IPs, they will be considered to be part of a Replica Set. In that case, the optional property
265
+ `replicaSet` should contain the Replica Set name. If the database requires authentication, username (`username`),
266
+ password (`password`) and authSource (`authSource`) can be set. If the database requires TLS/SSL connection but any
267
+ validation of the certificate chain is not mandatory, all you need is to set the ssl (`ssl`) option as `true` to connect
268
+ the database. If you need to add more complex option(s) such as `retryWrites=true` or `w=majority` when connection
269
+ database, extraArgs (`extraArgs`) can be used to perform it. For The MongoBD driver will retry the connection at startup
270
+ time `retries` times, waiting `retryTime` seconds between attempts, if those attributes are present (default values are
271
+ 5 and 5 respectively). E.g.:
272
+
273
+ ```javascript
274
+ {
275
+ host: 'localhost',
276
+ port: '27017',
277
+ db: 'iotagent',
278
+ retries: 5,
279
+ retryTime: 5
280
+ }
281
+ ```
282
+
283
+ ```javascript
284
+ {
285
+ host: 'mongodb-0,mongodb-1,mongodb-2',
286
+ port: '27017',
287
+ db: 'iotagent',
288
+ replicaSet: 'rs0',
289
+ user: 'rootuser',
290
+ password: 'password',
291
+ authSource: 'admin',
292
+ ssl: true,
293
+ extraArgs: {
294
+ retryWrites: true,
295
+ readPreference: 'nearest',
296
+ w: 'majority'
297
+ },
298
+ retries: 5,
299
+ retryTime: 5
300
+ }
301
+ ```
302
+
303
+ #### `iotManager`
304
+
305
+ This parameter configures all the information needed to register the IoT Agent in the IoTManager. If this section is
306
+ present, the IoTA will try to register to a IoTAM in the `host`, `port` and `path` indicated, with the information
307
+ configured in the object. The IoTAgent URL that will be reported will be the `providedUrl` (described below) with the
308
+ added `agentPath`:
309
+
310
+ ```javascript
311
+ {
312
+ host: 'mockediotam.com',
313
+ port: 9876,
314
+ path: '/protocols',
315
+ protocol: 'GENERIC_PROTOCOL',
316
+ description: 'A generic protocol',
317
+ agentPath: '/iot'
318
+ }
319
+ ```
320
+
321
+ #### `types`
322
+
323
+ See **Type Configuration** in the [Configuration API](#configurationapi) section below.
324
+
325
+ #### `service`
326
+
327
+ Default service for the IoT Agent. If a device is being registered, and no service information comes with the device
328
+ data, and no service information is configured for the given type, the default IoT agent service will be used instead.
329
+ E.g.: 'smartGondor'.
330
+
331
+ #### `subservice`
332
+
333
+ default subservice for the IoT Agent. If a device is being registered, and no subservice information comes with the
334
+ device data, and no subservice information is configured for the given type, the default IoT agent subservice will be
335
+ used instead. E.g.: '/gardens'.
336
+
337
+ #### `providerUrl`
338
+
339
+ URL to send in the Context Provider registration requests. Should represent the external IP of the deployed IoT Agent
340
+ (the IP where the Context Broker will redirect the NGSI requests). E.g.: 'http://192.168.56.1:4041'.
341
+
342
+ #### `iotaVersion`
343
+
344
+ indicates the version of the IoTA that will be displayed in the about method (it should be filled automatically by each
345
+ IoTA).
346
+
347
+ #### `dieOnUnexpectedError`
348
+
349
+ if this flag is activated, the IoTAgent will not capture global exception, thus dying upon any unexpected error.
350
+
351
+ #### `singleConfigurationMode`
352
+
353
+ enables the Single Configuration mode for backwards compatibility (see description in the Overview). Default to false.
354
+
355
+ #### `timestamp`
356
+
357
+ if this flag is activated:
358
+
359
+ - For NGSI-v2, the IoT Agent will add a `TimeInstant` metadata attribute to all the attributes updated from device
360
+ information. This flag is overwritten by `timestamp` flag in group or device
361
+ - With NGSI-LD, the standard `observedAt` property-of-a-property is created instead.
362
+
363
+ #### `defaultResource`
364
+
365
+ default string to use as resource for the registration of new Configurations (if no resource is provided).
366
+
367
+ #### `defaultKey`
368
+
369
+ default string to use as API Key for devices that do not belong to a particular Configuration.
370
+
371
+ #### `componentName`
372
+
373
+ default string identifying the component name for this IoT Agent in the logs.
374
+
375
+ #### `pollingExpiration`
376
+
377
+ expiration time for commands waiting in the polling queue in miliseconds. If a command has been in the queue for this
378
+ amount of time without being collected by the device, the expiration daemon will reclaim it. This attribute is optional
379
+ (if it doesn't exist, commands won't expire).
380
+
381
+ #### `pollingDaemonFrequency`
382
+
383
+ time between collection of expired commands in milliseconds. This attribute is optional (if this parameter doesn't exist
384
+ the polling daemon won't be started).
385
+
386
+ #### `autocast`
387
+
388
+ When enabled, the IoT Agents will try to cast attribute's values considering the JSON native type (only for NGSI v2).
389
+
390
+ #### `multiCore`
391
+
392
+ When enabled, the IoT Agents runs in multi-thread environment to take advantage of multi-core systems. It allows two
393
+ values `true` or `false`. This attribute is optional with default to false, which means that the IoTAgent runs in a
394
+ single thread. For more details about multi-core functionality, please refer to the
395
+ [Cluster](https://nodejs.org/api/cluster.html) module in Node.js and
396
+ [this section](devel/development.md#iot-agent-in-multi-thread-mode) of the library documentation.
397
+
398
+ #### `fallbackTenant`
399
+
400
+ For Linked Data Context Brokers which do not support multi-tenancy, this provides an alternative mechanism for supplying
401
+ the `NGSILD-Tenant` header. Note that NGSILD-Tenant has not yet been included in the NGSI-LD standard (it has been
402
+ proposed for the next update of the standard, but the final decision has yet been confirmed), take into account it could
403
+ change. Note that for backwards compatibility with NGSI v2, the `fiware-service` header is already used as alternative
404
+ if the `NGSILD-Tenant` header is not supplied.
405
+
406
+ #### `fallbackPath`
407
+
408
+ For Linked Data Context Brokers which do not support a service path, this provides an alternative mechanism for suppling
409
+ the `NGSILD-Path` header. Note that for backwards compatibility with NGSI v2, the `fiware-servicepath` header is already
410
+ used as alternative if the `NGSILD-Path` header is not supplied. Note that NGSILD-Path has not yet been included in the
411
+ NGSI-LD standard (it has been proposed for the next update of the standard, but the final decision has yet been
412
+ confirmed), take into account it could change
413
+
414
+ #### `explicitAttrs`
415
+
416
+ if this flag is activated, only provisioned attributes will be processed to Context Broker. This flag is overwritten by
417
+ `explicitAttrs` flag in group or device provision. Additionally `explicitAttrs` can be used to define which meassures
418
+ defined in JSON/JEXL array will be propagated to NGSI interface.
419
+
420
+ #### `defaultEntityNameConjunction`
421
+
422
+ the default conjunction string used to compose a default `entity_name` when is not provided at device provisioning time;
423
+ in that case `entity_name` is composed by `type` + `:` + `device_id`. Default value is `:`. This value is overwritten by
424
+ `defaultEntityNameConjunction` in group provision.
425
+
426
+ #### `relaxTemplateValidation`
427
+
428
+ if this flag is activated, `objectId` attributes for incoming devices are not validated, and may exceptionally include
429
+ characters (such as semi-colons) which are
430
+ [forbidden](https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html) according to the NGSI
431
+ specification. When provisioning devices, it is necessary that the developer provides valid `objectId`-`name` mappings
432
+ whenever relaxed mode is used, to prevent the consumption of forbidden characters.
433
+
434
+ ### Configuration using environment variables
435
+
436
+ Some of the configuration parameters can be overriden with environment variables, to ease the use of those parameters
437
+ with container-based technologies, like Docker, Heroku, etc...
438
+
439
+ The following table shows the accepted environment variables, as well as the configuration parameter the variable
440
+ overrides.
441
+
442
+ | Environment variable | Configuration attribute |
443
+ | :----------------------------------- | :------------------------------ |
444
+ | IOTA_CB_URL | `contextBroker.url` |
445
+ | IOTA_CB_HOST | `contextBroker.host` |
446
+ | IOTA_CB_PORT | `contextBroker.port` |
447
+ | IOTA_CB_NGSI_VERSION | `contextBroker.ngsiVersion` |
448
+ | IOTA_NORTH_HOST | `server.host` |
449
+ | IOTA_NORTH_PORT | `server.port` |
450
+ | IOTA_LD_SUPPORT_NULL | `server.ldSupport.null` |
451
+ | IOTA_LD_SUPPORT_DATASET_ID | `server.ldSupport.datasetId` |
452
+ | IOTA_PROVIDER_URL | `providerUrl` |
453
+ | IOTA_AUTH_ENABLED | `authentication.enabled` |
454
+ | IOTA_AUTH_TYPE | `authentication.type` |
455
+ | IOTA_AUTH_HEADER | `authentication.header` |
456
+ | IOTA_AUTH_URL | `authentication.url` |
457
+ | IOTA_AUTH_HOST | `authentication.host` |
458
+ | IOTA_AUTH_PORT | `authentication.port` |
459
+ | IOTA_AUTH_USER | `authentication.user` |
460
+ | IOTA_AUTH_PASSWORD | `authentication.password` |
461
+ | IOTA_AUTH_CLIENT_ID | `authentication.clientId` |
462
+ | IOTA_AUTH_CLIENT_SECRET | `authentication.clientSecret` |
463
+ | IOTA_AUTH_TOKEN_PATH | `authentication.tokenPath` |
464
+ | IOTA_AUTH_PERMANENT_TOKEN | `authentication.permanentToken` |
465
+ | IOTA_REGISTRY_TYPE | `deviceRegistry.type` |
466
+ | IOTA_LOG_LEVEL | `logLevel` |
467
+ | IOTA_TIMESTAMP | `timestamp` |
468
+ | IOTA_IOTAM_URL | `iotManager.url` |
469
+ | IOTA_IOTAM_HOST | `iotManager.host` |
470
+ | IOTA_IOTAM_PORT | `iotManager.port` |
471
+ | IOTA_IOTAM_PATH | `iotManager.path` |
472
+ | IOTA_IOTAM_AGENTPATH | `iotManager.agentPath` |
473
+ | IOTA_IOTAM_PROTOCOL | `iotManager.protocol` |
474
+ | IOTA_IOTAM_DESCRIPTION | `iotManager.description` |
475
+ | IOTA_MONGO_HOST | `mongodb.host` |
476
+ | IOTA_MONGO_PORT | `mongodb.port` |
477
+ | IOTA_MONGO_DB | `mongodb.db` |
478
+ | IOTA_MONGO_REPLICASET | `mongodb.replicaSet` |
479
+ | IOTA_MONGO_USER | `mongodb.user` |
480
+ | IOTA_MONGO_PASSWORD | `mongodb.password` |
481
+ | IOTA_MONGO_AUTH_SOURCE | `mongodb.authSource` |
482
+ | IOTA_MONGO_RETRIES | `mongodb.retries` |
483
+ | IOTA_MONGO_RETRY_TIME | `mongodb.retryTime` |
484
+ | IOTA_MONGO_SSL | `mongodb.ssl` |
485
+ | IOTA_MONGO_EXTRAARGS | `mongodb.extraArgs` |
486
+ | IOTA_SINGLE_MODE | `singleConfigurationMode` |
487
+ | IOTA_POLLING_EXPIRATION | `pollingExpiration` |
488
+ | IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
489
+ | IOTA_AUTOCAST | `autocast` |
490
+ | IOTA_MULTI_CORE | `multiCore` |
491
+ | IOTA_JSON_LD_CONTEXT | `jsonLdContext` |
492
+ | IOTA_FALLBACK_TENANT | `fallbackTenant` |
493
+ | IOTA_FALLBACK_PATH | `fallbackPath` |
494
+ | IOTA_EXPLICIT_ATTRS | `explicitAttrs` |
495
+ | IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION | `defaultEntityNameConjunction` |
496
+ | IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |
497
+
498
+ Note:
499
+
500
+ - If you need to pass more than one JSON-LD context, you can define the IOTA_JSON_LD_CONTEXT environment variable as a
501
+ comma separated list of contexts (e.g. `'http://context1.json-ld,http://context2.json-ld'`)
502
+
503
+ ## Logs
504
+
505
+ This section describes the logs that can be generated by the IoT Agent library. The IoT Agent library uses the following
506
+ log levels:
507
+
508
+ | Level | Description |
509
+ | :------ | :-------------------------------------------------------------------------------- |
510
+ | `DEBUG` | Used to log information useful for debugging. |
511
+ | `INFO` | Used to log information about the normal operation of the IoT Agent library. |
512
+ | `ERROR` | Used to log information about errors that may affect the IoT Agent library. |
513
+ | `FATAL` | Used to log information about fatal errors that may affect the IoT Agent library. |
514
+
515
+ Additionally, every error log has an associated error code that can be used to identify the error. The error codes are
516
+ composed by a prefix and a number. The following table shows the prefixes used in the IoT Agent library:
517
+
518
+ | Prefix | Type of operation |
519
+ | :----------------- | :--------------------------------------------------------- |
520
+ | `MONGODB` | Errors related with the MongoDB repository |
521
+ | `IOTAM` | Errors related with the IoTA Manager |
522
+ | `KEYSTONE` | Errors related with trust token retrieval |
523
+ | `ORION` | Errors in Context Broker access |
524
+ | `VALIDATION-FATAL` | Errors related with management of the Validation templates |
525
+
526
+ ### Errors
527
+
528
+ | Error code | Error name | Description |
529
+ | :--------------------- | :----------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
530
+ | `GENERAL-001` | Couldn't find callback in listDevices call. | Implies that the callback function was not found in the listDevices call. This error is thrown when the callback function is not provided in the listDevices call. |
531
+ | `MONGODB-001` | Error trying to connect to MongoDB: %s | Implies there has been an error connecting with the DB. The component will automatically retry from this error, but it may be a sign of connectivity problems between the DB and the component. If the connection cannot be restablished from this error, a MONGODB-002 error will be raised. |
532
+ | `MONGODB-002` | Error found after [%d] attempts: %s | Indicates that it was impossible to establish a connection to the MongoDB cluster, even after retrying N times. This could be caused by a connectivity problem with the MongoDB machine, a problem in the MongoDB cluster, or a misconfiguration of the IoTA Manager. Check the conectivity, the state of the MongoDB cluster and the Mongo configuration data. |
533
+ | `MONGODB-003` | No host found for MongoDB driver. | This error will thrown if MongoDB is selected as the configured repository for data but some information is missing in the configuration file. Check the configuration file and add all the required information. |
534
+ | `MONGODB-004` | MongoDB connection was lost. | Indicates that it was impossible to reestablish the connection with the MongoDB server after retrying N times. This could be caused by a connectivity problem with the MongoDB machine or by changes on the configuration of the MongoDB server done while the IoT Agent was running. This error is only thrown when using a single MongoDB instance or when using sharding but just a single mongos proxy. When using MongoDB instances using replica sets or multiple mongos servers, the IoT Agent will retry connecting forever alternating between the different nodes. |
535
+ | `IOTAM-001` | Error updating information in the IOTAM. Status Code [%d] | The IoT Agent could not contact the IoT Agent manager to update its information. This condition may indicate a lack of connectivity between machines or a problem in the IoT Agent Manager. The IoT Agent information in the IoT Agent Manager will be out-of-date until this problem is solved. |
536
+ | `KEYSTONE-001` | Error retrieving token from Keystone: %s | There was connection error connecting with Keystone to retrieve a token. This condition may indicate a lack of connectivity between both machines or a problem with Keystone. |
537
+ | `KEYSTONE-002` | Unexpected status code: %d | There was a problem retrieving a token from keystone that was not caused by connectivity errors. Check the Keystone log for errors and the security configuration in the IoTAgent. This may also be caused by a wrong trust token used by the user. |
538
+ | `KEYSTONE-003` | Token missing in the response headers. | Authentication flow worked correctly, but the response headers did not include the expected header `x-subject-token`. Check the Keystone logs and configuration. |
539
+ | `OAUTH2-001` | Error retrieving token from OAuth2 provider: %s | There was connection error connecting with OAuth2 provider to retrieve a token. This condition may indicate a lack of connectivity between both machines or a problem with OAuth2 provider. |
540
+ | `OAUTH2-002` | Unexpected status code: %d | There was a problem retrieving a token from OAuth2 provider that was not caused by connectivity errors. Check the OAuth2 provider log for errors and the security configuration in the IoTAgent. This may also be caused by an invalid `refresh_token` used by the user. |
541
+ | `OAUTH2-003` | Token missing in the response body | The JSON response body returned by the OAuth2 provider does not include a field `access_token`. Check the OAuth2 logs and configuration. |
542
+ | `ORION-001` | Connection error creating initial entity in the Context Broker: %s | There was a connectivity error accessing Context Broker to create an initial entity (or the Context Broker was down). Check connectivity between the machines, the status of the remote Context Broker and the configuration of the IoTAgent. |
543
+ | `ORION-002` | Connection error sending registrations to the Context Broker: %s | There was a connectivity error accessing Context Broker to register the IoTA as a Context Provider (or the Context Broker was down). Check connectivity between the machines, the status of the remote Context Broker and the configuration of the IoT Agent. |
544
+ | `VALIDATION-FATAL-001` | Validation Request templates not found | Validation templates were not found. Check all the validation templates are properly located in the IoTAgent Library folder and that the file permissions are correct. |
545
+
546
+ ## Alarms
547
+
548
+ The following table shows the alarms that can be raised in the IoTAgent library. All the alarms are signaled by a error
549
+ log starting with the prefix "Raising [%s]:" (where %s is the alarm name). All the alarms are released by an info log
550
+ with the prefix "Releasing [%s]". These texts appear in the `msg=` field of the generic log record format.
551
+
552
+ | Alarm name | Severity | Description |
553
+ | :--------------- | :----------- | :------------------------------------------------------- |
554
+ | `MONGO-ALARM_XX` | **Critical** | Indicates an error in the MongoDB connectivity |
555
+ | `ORION-ALARM` | **Critical** | Indicates a persistent error accesing the Context Broker |
556
+ | `IOTAM-ALARM` | **Critical** | Indicates a persistent error accessing the IoTAM |
557
+
558
+ while the 'Severity' criterium is as follows:
559
+
560
+ - **Critical** - The system is not working
561
+ - **Major** - The system has a problem that degrades the service and must be addressed
562
+ - **Warning** - It is happening something that must be notified
563
+
564
+ In order to identify the internal flow which origins a mongo alarm, there is a suffix `_XX` which identifies from `01`
565
+ to `11` each flow.