Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_influxdb_cache(self):
client = InfluxDBClient(host='localhost', port=8086, username='root', password='root', database='test_cache')
try:
client.drop_database('test_cache')
client.create_database('test_cache')
client.switch_database('test_cache')
with InfluxDBCache(client=DataFrameClient(host='localhost', port=8086, username='root', password='root', database='test_cache')) as cache:
listeners = SyncListeners()
QuandlEvents(listeners)
non_cache_data = get_table([{'datatable_code': 'SHARADAR/SF1', 'ticker': 'AAPL', 'dimension': 'MRY', 'qopts': {"columns": ['dimension', 'ticker', 'datekey', 'revenue']}},
{'datatable_code': 'SHARADAR/SF1', 'ticker': 'IBM', 'dimension': 'MRY', 'qopts': {"columns": ['dimension', 'ticker', 'datekey', 'revenue']}}])
items = list()
for df in non_cache_data['SHARADAR/SF1']:
items.append(df.rename({'revenue': 'value', 'datekey': 'timestamp'}, axis=1).set_index('timestamp'))
def _setup_influxdb_server(inst):
inst.influxd_inst = InfluxDbInstance(
inst.influxdb_template_conf,
udp_enabled=getattr(inst, 'influxdb_udp_enabled', False))
inst.cli = InfluxDBClient('localhost',
inst.influxd_inst.http_port,
'root',
'',
database='db')
if not using_pypy:
inst.cliDF = DataFrameClient('localhost',
inst.influxd_inst.http_port,
'root',
'',
database='db')
def get_handle_db():
global HANDLE_DB
if HANDLE_DB == '':
HANDLE_DB = influxdb.InfluxDBClient(
host=DOCKER_IP,
port=TEST_PORT_INFLUXDB_API,
database=DATABASE_NAME,
username="juniper",
password="juniper"
)
return HANDLE_DB
for M in ('user','password','hostname','database'):
if (not M in net.keys()):
if M == 'database' and resource['type'] != 'mysql': continue
sys.exit("Please provide access credential %s" % M)
try:
if resource['type'] == 'mysql':
DB = mysql.connector.connect(
charset='utf8',
user=net['user'],
password=net['password'],
host=net['hostname'],
port=net['port'],
database=net['database'])
elif resource['type'] == 'influx':
from influxdb import InfluxDBClient
DB = InfluxDBClient(
net['hostname'], net['port'],
net['user'], net['password'],
timeout=2*60)
except:
sys.exit("Unable to connect to database %s on host %s" %(net['database'],net['hostname']))
return DB
METRICS_TYPE_SUPPORTED = ['gauge', 'counter']
DEFAULT_CONFIG_FILE = '/home/panoptes/conf/influxdb_consumer.ini'
class PanoptesInfluxDBConsumerContext(PanoptesContext): # pragma: no cover
"""
This class implements a PanoptesContext without any KV stores, producers or ZK client
"""
def __init__(self):
super(PanoptesInfluxDBConsumerContext, self).__init__(
key_value_store_class_list=[PanoptesResourcesKeyValueStore],
create_message_producer=False, async_message_producer=False, create_zookeeper_client=False)
class PanoptesInfluxDBConnection(InfluxDBClient):
"""
Class to create Influxdb client connection
"""
def __init__(self, host, port, database, retries, timeout, pool_size):
super(PanoptesInfluxDBConnection, self).__init__(
host=host, port=port, database=database, retries=retries, timeout=timeout, pool_size=pool_size)
class PanoptesInfluxDBDefaultTransformer(object):
"""
This class implements Panoptes Metrics Group to InfluxDB line protocol points transformation
"""
def __init__(self, metrics_group):
self._resource = metrics_group['resource']
self._metrics_group = metrics_group
from mongoengine import *
from influxdb import InfluxDBClient
from models.version import VersionModel
from collections import defaultdict
connect(**{
'db': 'dms-v2',
'host': None,
'port': None,
'username': os.getenv('MONGO_ID'),
'password': os.getenv('MONGO_PW')
})
CLIENT = InfluxDBClient(**{
'host': 'localhost',
'port': 8086,
'username': 'root',
'password': os.getenv('INFLUX_PW_{}'.format('DMS_V2'), 'root'),
'database': 'dms_v2'
})
MEASUREMENT = 'version'
version_data = defaultdict(lambda: '')
for version in VersionModel.objects:
version_data[version.platform] = version.version
payload = [
{
'measurement': MEASUREMENT,
def initialise_database(self):
self._db_client = MySQLdb.connect ( self._mysql_host,
self._mysql_username,
self._mysql_password,
self._mysql_db,
cursorclass = MySQLdb.cursors.DictCursor
)
self._influx_client = InfluxDBClient(
self._influx_db_host,
self._influx_db_port,
self._influx_db_username,
self._influx_db_password,
self._influx_db
)
def __init__(self, host='localhost', port=8086, user='influx', password=None, database='test', method='http', writeport=None):
self.client = InfluxDBClient(host, port, user, password, database)
def push_data(self, rtu_id, asset_name, asset_context, timestamp, value, unit):
try:
client = InfluxDBClient('138.197.74.74', 8086, 'early', 'adopter')
dbs = client.get_list_database()
found = False
for item in dbs:
if asset_context in item:
found = True
if found is False:
client.query("CREATE DATABASE {0}".format('"' + asset_context + '"'))
client = InfluxDBClient('138.197.74.74', 8086, 'early', 'adopter', asset_context)
json_body = [
{
"measurement": asset_context,
"tags": {
"site": self.name,
"rtu": rtu_id,
"asset": asset_name
},
"time": str(datetime.datetime.now()),
"fields": {
"value": value,
"unit": unit
}
}
]