[iotagent-json]Cannot create new device in mongodb
AlexandraLakka opened this issue · comments
Orion, Mongo and IoT-Agent have been deployed with the help of the Orion helm chart.
After creating a service, when trying to post a new device, I get the following message:
{"name":"ENTITY_GENERIC_ERROR","message":"Error accesing entity data for device: device1 of type: Thing"}
The logs from the IoT Agent look like this:
time=2022-03-01T10:53:42.928Z | lvl=ERROR | corr=1d437c8d-1c9b-4cba-838d-78ee85ff06eb | trans=1d437c8d-1c9b-4cba-838d-78ee85ff06eb | op=IoTAgentNGSI.Devices-v2 | from=n/a | srv=openiot | subsrv=/ | msg=Protocol error connecting to the Context Broker [500]: {
error: 'InternalServerError',
description: 'Database Error (collection: db-openiot.entities - count(): { _id.id: "urn:ngsi-ld:Device:1", _id.type: "Thing", _id.servicePath: { $in: [ null, /^/$/ ] } } - exception: count fails:{ ok: 0.0, errmsg: "not authorized on db-openiot to execute command { count: "entities", query: { _id.id: "urn:ngsi-ld:Device:1", _id.type: "Thing", _id.servicePath: {...", code: 13, codeName: "Unauthorized" })'
} | comp=IoTAgent
I have configured in the deviceRegistry.mongodb
the user
, password
and authSource
. I use Orion-LD (latest
tag), with the following info:
orionld version: "post-v1.0.0"
orion version: "1.15.0-next"
uptime: "11 d, 18 h, 39 m, 43 s"
git_hash: "nogitversion"
compile_time: "Mon Jan 24 15:03:06 UTC 2022"
compiled_by: "root"
compiled_in: ""
release_date: "Mon Jan 24 15:03:06 UTC 2022"
doc: "https://fiware-orion.readthedocs.org/en/master/"
Is there some other configuration required?
Hi,
how do you deploy mongodb? And how does that config look like?
The parameters for the configuration of mongo in values.yaml
can be found here: https://github.com/bitnami/charts/tree/master/bitnami/mongodb.
Mongodb exists in charts
folder as a compressed folder and is deployed with the rest of the components when applying values.yaml
.
Can you connect to mongodb with the user, password and url that you configure in the iot-agents values.yaml via a mongo-client container?
And how does you config of Orion look like? Can you post its log?
Orion's logs:
time=2022-03-01T11:06:06.046Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionld.cpp[925]:main | msg=Orion Context Broker is running
time=2022-03-01T11:06:08.841Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=MongoGlobal.cpp[241]:mongoInit | msg=Connected to mongo at mongodb:db as user 'user'
time=2022-03-01T11:06:13.945Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionldRequestSend.cpp[268]:orionldRequestSend | msg=Internal Error (curl_easy_perform returned error code 28)
time=2022-03-01T11:06:13.945Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionldRequestSend.cpp[276]:orionldRequestSend | msg=curl_easy_perform error 28
time=2022-03-01T11:06:13.945Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionldContextDownload.cpp[116]:orionldContextDownload | msg=orionldRequestSend failed (try number 1 out of 3. Timeout is: 5000ms): Internal CURL Error
time=2022-03-01T11:06:17.351Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=mongocContextCachePersist.cpp[59]:mongocContextCachePersist | msg=Database Error (persisting context: command insert requires authentication)
time=2022-03-01T11:06:17.354Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=orionld.cpp[1075]:main | msg=Startup completed
The logs of IoT-Agent show that the connection to mongodb has been successfully created.
time=2022-02-24T14:34:02.118Z | lvl=INFO | corr=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | trans=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | op=IoTAgentNGSI.Global | from=n/a | srv=n/a | subsrv=n/a | msg=Activating IOT Agent NGSI Library. | comp=IoTAgent
time=2022-02-24T14:34:02.118Z | lvl=INFO | corr=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | trans=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | op=IoTAgentNGSI.Global | from=n/a | srv=n/a | subsrv=n/a | msg=MongoDB Device registry selected for NGSI Library | comp=IoTAgent
time=2022-02-24T14:34:02.155Z | lvl=INFO | corr=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | trans=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | op=IoTAgentNGSI.DbConn | from=n/a | srv=n/a | subsrv=n/a | msg=First connection attempt | comp=IoTAgent
time=2022-02-24T14:34:02.156Z | lvl=INFO | corr=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | trans=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | op=IoTAgentNGSI.DbConn | from=n/a | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance with url "mongodb://mongodb:27017/db" and options {}. Attempt 1 | comp=IoTAgent
(node:1) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
time=2022-02-24T14:34:02.207Z | lvl=INFO | corr=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | trans=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | op=IoTAgentNGSI.DbConn | from=n/a | srv=n/a | subsrv=n/a | msg=Successfully connected to MongoDB. | comp=IoTAgent
time=2022-02-24T14:34:02.214Z | lvl=INFO | corr=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | trans=d3a6a3ed-10f9-43aa-b73c-0c2e6033417f | op=IoTAgentNGSI.NorthboundServer | from=n/a | srv=n/a | subsrv=n/a | msg=Starting IoT Agent listening on port [4041] | comp=IoTAgent
"time=2022-03-01T11:06:17.351Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=mongocContextCachePersist.cpp[59]:mongocContextCachePersist | msg=Database Error (persisting context: command insert requires authentication)"
That log indicates, that you did not configure a mongoDb for orion. Without that, orion cannot work.
You need to configure: https://github.com/FIWARE/helm-charts/blob/main/charts/orion/values.yaml#L247-L270
I have that configuration under the broker
parameter. I have defined hosts
, name
and auth
I have that configuration under the
broker
parameter. I have definedhosts
,name
andauth
Can you post the full values.yaml you are using for orion? The log clearly states that it cannot authenticate to mongo.
nameOverride: ""
fullnameOverride: ""
service:
type: ClusterIP
port: 1026
annotations: {}
serviceAccount:
create: false
deployment:
replicaCount: 1
revisionHistoryLimit: 3
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
image:
repository: fiware/orion-ld
tag: latest
pullPolicy: IfNotPresent
additionalLabels: {}
additionalAnnotations: {}
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}
livenessProbe:
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 30
readinessProbe:
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 30
sidecars: []
volumes: []
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 10
metrics: []
route:
enabled: false
annotations: {}
tls: {}
broker:
envPrefix: ORIONLD_
port: 1026
ipv6enabled: false
ipv4enabled: false
noDevTrace: true
troe:
enabled: false
dbHost: postgres
dbPort: 5432
dbUser: user
dbPassword: xxx
poolSize: 10
corsOrigin: __ALL
cachedContextFolder: "/opt/orion/ldcontexts"
logging:
level: "DEBUG"
db:
hosts:
- mongodb
name: db
auth:
user: user
password: xxxx
metrics:
enabled: "false"
Thank you. If you are using the bitnami mongodb chart with its default values(as stated before), the user "user" does not exist. Default admin is "root".
Thank you. That seemed to work.