Create influx bucket if it doesn't exist
This commit is contained in:
parent
415f933143
commit
8119f908ba
1 changed files with 18 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
from sys import exit
|
||||
from logging import getLogger
|
||||
from requests.exceptions import ConnectionError
|
||||
import influxdb_client
|
||||
from influxdb_client import InfluxDBClient, Point
|
||||
from influxdb_client.client.write_api import SYNCHRONOUS
|
||||
|
||||
|
@ -17,6 +18,23 @@ class InfluxDB2Manager(object):
|
|||
timeout=self.server.timeout, verify_ssl=self.server.verify_ssl, ssl_ca_cert=self.server.ssl)
|
||||
self.influx_write_api = self.influx.write_api(write_options=SYNCHRONOUS)
|
||||
|
||||
# Create the bucket if needed
|
||||
|
||||
bucket_api = self.influx.buckets_api()
|
||||
|
||||
bucket = bucket_api.find_bucket_by_name(self.server.bucket)
|
||||
|
||||
if bucket is None:
|
||||
self.logger.info('Creating bucket %s', self.server.bucket)
|
||||
|
||||
org_api = influxdb_client.service.organizations_service.OrganizationsService(self.influx.api_client)
|
||||
orgs = org_api.get_orgs()
|
||||
for org in orgs.orgs:
|
||||
if org.name == self.server.org:
|
||||
my_org = org
|
||||
|
||||
self.influx.buckets_api().create_bucket(bucket_name=self.server.bucket, org_id=my_org.id)
|
||||
|
||||
def write_points(self, data):
|
||||
d = data
|
||||
self.logger.info('Writing Data to InfluxDBv2 %s', d)
|
||||
|
|
Loading…
Reference in a new issue