Added device ID requesting
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6606ec0699
commit
3afa6d7260
@ -1,3 +1,4 @@
|
|||||||
aio-pika
|
aio-pika
|
||||||
sentry-sdk
|
sentry-sdk
|
||||||
aioinflux
|
aioinflux
|
||||||
|
requests
|
16
src/app.py
16
src/app.py
@ -16,6 +16,7 @@ from aio_pika import connect, IncomingMessage, ExchangeType
|
|||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
from aioinflux import InfluxDBClient
|
from aioinflux import InfluxDBClient
|
||||||
import config
|
import config
|
||||||
|
import requests
|
||||||
|
|
||||||
if config.SENTRY_DSN:
|
if config.SENTRY_DSN:
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
@ -33,12 +34,23 @@ async def on_message(message: IncomingMessage):
|
|||||||
"""
|
"""
|
||||||
msg_json = json.loads(message.body)
|
msg_json = json.loads(message.body)
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
||||||
|
r = requests.get(f"http://input-service/sample/{msg_json['tag']}")
|
||||||
|
r.raise_for_status()
|
||||||
|
|
||||||
point = {
|
point = {
|
||||||
'time': now,
|
'time': now,
|
||||||
'measurement': 'sturnus',
|
'measurement': 'sturnus',
|
||||||
'tags': {'device': 'dummy'},
|
'tags': {
|
||||||
'fields': {'probability': msg_json['probability']}
|
'device': r.json()['device_id']
|
||||||
|
},
|
||||||
|
'fields': {
|
||||||
|
'probability': float(msg_json['probability']) # This is required because otherwise of the json serialization and de-serialization round values would interpret as ints and influxdb would fail
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async with InfluxDBClient(username=config.INFLUXDB_USERNAME, password=config.INFLUXDB_PASSWORD,
|
async with InfluxDBClient(username=config.INFLUXDB_USERNAME, password=config.INFLUXDB_PASSWORD,
|
||||||
host=config.INFLUXDB_HOST, port=config.INFLUXDB_PORT, ssl=False,
|
host=config.INFLUXDB_HOST, port=config.INFLUXDB_PORT, ssl=False,
|
||||||
database=config.INFLUXDB_DB) as client:
|
database=config.INFLUXDB_DB) as client:
|
||||||
|
Loading…
Reference in New Issue
Block a user