mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 11:18:03 +00:00
additional variables for csv to influx parsing
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
@@ -39,17 +39,19 @@ class CSVtoInflux():
|
|||||||
_capture_signal_list=[],
|
_capture_signal_list=[],
|
||||||
influxdb=None,
|
influxdb=None,
|
||||||
_influx_tag=[],
|
_influx_tag=[],
|
||||||
target_csv=None):
|
target_csv=None,
|
||||||
|
sep='\t'):
|
||||||
self.influxdb = influxdb
|
self.influxdb = influxdb
|
||||||
self.target_csv = target_csv.replace('/home/lanforge/html-reports/', '')
|
self.target_csv = target_csv.replace('/home/lanforge/html-reports/', '')
|
||||||
self.influx_tag = _influx_tag
|
self.influx_tag = _influx_tag
|
||||||
|
self.sep = sep
|
||||||
|
|
||||||
def read_csv(self, file):
|
def read_csv(self, file):
|
||||||
csv = open(file).read().split('\n')
|
csv = open(file).read().split('\n')
|
||||||
rows = list()
|
rows = list()
|
||||||
for x in csv:
|
for x in csv:
|
||||||
if len(x) > 0:
|
if len(x) > 0:
|
||||||
rows.append(x.split('\t'))
|
rows.append(x.split(self.sep))
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
# Submit data to the influx db if configured to do so.
|
# Submit data to the influx db if configured to do so.
|
||||||
@@ -57,6 +59,7 @@ class CSVtoInflux():
|
|||||||
df = self.read_csv(self.target_csv)
|
df = self.read_csv(self.target_csv)
|
||||||
length = list(range(0, len(df[0])))
|
length = list(range(0, len(df[0])))
|
||||||
columns = dict(zip(df[0], length))
|
columns = dict(zip(df[0], length))
|
||||||
|
print('columns: %s' % columns)
|
||||||
influx_variables = ['script', 'short-description', 'test_details', 'Graph-Group',
|
influx_variables = ['script', 'short-description', 'test_details', 'Graph-Group',
|
||||||
'DUT-HW-version', 'DUT-SW-version', 'DUT-Serial-Num', 'testbed', 'Units']
|
'DUT-HW-version', 'DUT-SW-version', 'DUT-Serial-Num', 'testbed', 'Units']
|
||||||
csv_variables = ['test-id', 'short-description', 'test details', 'Graph-Group',
|
csv_variables = ['test-id', 'short-description', 'test details', 'Graph-Group',
|
||||||
@@ -64,6 +67,7 @@ class CSVtoInflux():
|
|||||||
csv_vs_influx = dict(zip(csv_variables, influx_variables))
|
csv_vs_influx = dict(zip(csv_variables, influx_variables))
|
||||||
for row in df[1:]:
|
for row in df[1:]:
|
||||||
tags = dict()
|
tags = dict()
|
||||||
|
print("row: %s" % row)
|
||||||
short_description = row[columns['short-description']]
|
short_description = row[columns['short-description']]
|
||||||
numeric_score = float(row[columns['numeric-score']])
|
numeric_score = float(row[columns['numeric-score']])
|
||||||
date = row[columns['Date']]
|
date = row[columns['Date']]
|
||||||
@@ -138,6 +142,7 @@ python3 csv_to_influx.py --influx_host localhost --influx_org Candela --influx_t
|
|||||||
# This argument is specific to this script, so not part of the generic influxdb parser args
|
# This argument is specific to this script, so not part of the generic influxdb parser args
|
||||||
# method above.
|
# method above.
|
||||||
parser.add_argument('--target_csv', help='CSV file to record to influx database', default="")
|
parser.add_argument('--target_csv', help='CSV file to record to influx database', default="")
|
||||||
|
parser.add_argument('--sep', help='character to split CSV by', default='\t')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -151,7 +156,8 @@ python3 csv_to_influx.py --influx_host localhost --influx_org Candela --influx_t
|
|||||||
|
|
||||||
csvtoinflux = CSVtoInflux(influxdb=influxdb,
|
csvtoinflux = CSVtoInflux(influxdb=influxdb,
|
||||||
target_csv=args.target_csv,
|
target_csv=args.target_csv,
|
||||||
_influx_tag=args.influx_tag)
|
_influx_tag=args.influx_tag,
|
||||||
|
sep=args.sep)
|
||||||
csvtoinflux.post_to_influx()
|
csvtoinflux.post_to_influx()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,9 @@ class UseGrafana(LFCliBase):
|
|||||||
graph_groups_file=None,
|
graph_groups_file=None,
|
||||||
testbed=None,
|
testbed=None,
|
||||||
datasource='InfluxDB',
|
datasource='InfluxDB',
|
||||||
from_date='now-1y'):
|
from_date='now-1y',
|
||||||
|
graph_height=8,
|
||||||
|
graph__width=12):
|
||||||
options = string.ascii_lowercase + string.ascii_uppercase + string.digits
|
options = string.ascii_lowercase + string.ascii_uppercase + string.digits
|
||||||
uid = ''.join(random.choice(options) for i in range(9))
|
uid = ''.join(random.choice(options) for i in range(9))
|
||||||
input1 = dict()
|
input1 = dict()
|
||||||
@@ -137,8 +139,8 @@ class UseGrafana(LFCliBase):
|
|||||||
panel = dict()
|
panel = dict()
|
||||||
|
|
||||||
gridpos = dict()
|
gridpos = dict()
|
||||||
gridpos['h'] = 8
|
gridpos['h'] = graph_height
|
||||||
gridpos['w'] = 12
|
gridpos['w'] = graph__width
|
||||||
gridpos['x'] = 0
|
gridpos['x'] = 0
|
||||||
gridpos['y'] = 0
|
gridpos['y'] = 0
|
||||||
|
|
||||||
@@ -343,6 +345,8 @@ def main():
|
|||||||
optional.add_argument('--kpi', help='KPI file(s) which you want to graph form', action='append', default=None)
|
optional.add_argument('--kpi', help='KPI file(s) which you want to graph form', action='append', default=None)
|
||||||
optional.add_argument('--datasource', help='Name of Influx database if different from InfluxDB', default='InfluxDB')
|
optional.add_argument('--datasource', help='Name of Influx database if different from InfluxDB', default='InfluxDB')
|
||||||
optional.add_argument('--from_date', help='Date you want to start your Grafana dashboard from', default='now-1y')
|
optional.add_argument('--from_date', help='Date you want to start your Grafana dashboard from', default='now-1y')
|
||||||
|
optional.add_argument('--graph_height', help='Custom height for the graph on grafana dashboard', default=8)
|
||||||
|
optional.add_argument('--graph_width', help='Custom width for the graph on grafana dashboard', default=12)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
Grafana = UseGrafana(args.grafana_token,
|
Grafana = UseGrafana(args.grafana_token,
|
||||||
@@ -372,7 +376,9 @@ def main():
|
|||||||
graph_groups_file=args.graph_groups_file,
|
graph_groups_file=args.graph_groups_file,
|
||||||
testbed=args.testbed,
|
testbed=args.testbed,
|
||||||
datasource=args.datasource,
|
datasource=args.datasource,
|
||||||
from_date=args.from_date)
|
from_date=args.from_date,
|
||||||
|
graph_height=args.graph_height,
|
||||||
|
graph__width=args.graph_width)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user