Files
wlan-lanforge-scripts/py-scripts/csv_to_influx.py
erinnerim 1d7578251c Updates to import statements:
- Import importlib, os, and sys to each python script.
 - Append "lanforge-scripts" root directory to the system path, allowing each script to be called from an antecedent directory. e.g.
if 'lanforge-scripts' not in sys.path:
    sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../../")))
 - All statements of the form 'from <module> import <class>' replace with:
<module> = importlib.import_module("lanforge-scripts.<directory>.<module>")
<class> = <module>.<class>
2021-09-15 16:17:16 -07:00

62 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
import os
import importlib
from pathlib import Path
import argparse
if 'lanforge-scripts' not in sys.path:
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../")))
cv_test_manager = importlib.import_module("lanforge-scripts.py-json.cv_test_manager")
cv_add_base_parser = cv_test_manager.cv_add_base_parser
cv_base_adjust_parser = cv_test_manager.cv_base_adjust_parser
InfluxRequest = importlib.import_module("lanforge-scripts.py-dashboard.InfluxRequest")
RecordInflux = InfluxRequest.RecordInflux
influx_add_parser_args = InfluxRequest.influx_add_parser_args
class CSVtoInflux:
def __init__(self,
influx_host,
influx_port,
influx_org,
influx_token,
influx_bucket,
path):
self.path = path
self.influxdb = RecordInflux(_influx_host=influx_host,
_influx_port=influx_port,
_influx_org=influx_org,
_influx_token=influx_token,
_influx_bucket=influx_bucket)
def glob(self):
path = Path(self.path)
self.kpi_list = list(path.glob('**/kpi.csv'))
for kpi in self.kpi_list:
self.influxdb.RecordInflux.csv_to_influx(kpi)
def main():
parser = argparse.ArgumentParser()
cv_add_base_parser(parser)
parser.add_argument('--path', action='append')
args = parser.parse_args()
cv_base_adjust_parser(args)
csvtoinflux = CSVtoInflux(args.influx_host,
args.influx_port,
args.influx_org,
args.influx_token,
args.influx_bucket,
args.path)
csvtoinflux.glob()
if __name__ == "__main__":
main()