...
parent
9c19e55bac
commit
7e0581a907
|
|
@ -58,89 +58,89 @@ def getSLO(ENV, DTAPIToken, DTENV):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def init_argparse():
|
# def init_argparse():
|
||||||
parser = argparse.ArgumentParser(
|
# parser = argparse.ArgumentParser(
|
||||||
usage="%(prog)s [--fromDate] [toDate] or [preSelect]",
|
# usage="%(prog)s [--fromDate] [toDate] or [preSelect]",
|
||||||
description="gather SLO in daily slices for given Timeframe"
|
# description="gather SLO in daily slices for given Timeframe"
|
||||||
)
|
# )
|
||||||
parser.add_argument(
|
# parser.add_argument(
|
||||||
"-f","--fromDate",
|
# "-f","--fromDate",
|
||||||
help = "YYYY-mm-dd e.g. 2022-01-01"
|
# help = "YYYY-mm-dd e.g. 2022-01-01"
|
||||||
)
|
# )
|
||||||
parser.add_argument(
|
# parser.add_argument(
|
||||||
"-t","--toDate",
|
# "-t","--toDate",
|
||||||
help = "YYYY-mm-dd e.g. 2022-01-31"
|
# help = "YYYY-mm-dd e.g. 2022-01-31"
|
||||||
)
|
# )
|
||||||
parser.add_argument(
|
# parser.add_argument(
|
||||||
"-p","--preSelect",
|
# "-p","--preSelect",
|
||||||
help = "day | week | month - gathers the data for the last full day, week or month"
|
# help = "day | week | month - gathers the data for the last full day, week or month"
|
||||||
)
|
# )
|
||||||
parser.add_argument(
|
# parser.add_argument(
|
||||||
"-s","--slices",
|
# "-s","--slices",
|
||||||
help = "h | d | t | y - writes the slices hourly, daily, total or year to date into ecxel. given in any order"
|
# help = "h | d | t | y - writes the slices hourly, daily, total or year to date into ecxel. given in any order"
|
||||||
)
|
# )
|
||||||
|
|
||||||
|
|
||||||
return parser
|
# return parser
|
||||||
|
|
||||||
def check_inputs(args):
|
# def check_inputs(args):
|
||||||
'''
|
# '''
|
||||||
This functions is the single point of true for arguments. If new arguments are added they need to be added in here. Returns from and to date.
|
# This functions is the single point of true for arguments. If new arguments are added they need to be added in here. Returns from and to date.
|
||||||
'''
|
# '''
|
||||||
if args.preSelect and (args.fromDate or args.toDate):
|
# if args.preSelect and (args.fromDate or args.toDate):
|
||||||
print("--preSelect must not be used in conjuntion with --fromDate and/or --toDate")
|
# print("--preSelect must not be used in conjuntion with --fromDate and/or --toDate")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
elif args.fromDate and not args.toDate:
|
# elif args.fromDate and not args.toDate:
|
||||||
print("--fromDate only in conjunction with --toDate")
|
# print("--fromDate only in conjunction with --toDate")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
elif args.toDate and not args.fromDate:
|
# elif args.toDate and not args.fromDate:
|
||||||
print("--toDate only in conjunction with --fromDate")
|
# print("--toDate only in conjunction with --fromDate")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
elif args.toDate and args.fromDate and not args.preSelect:
|
# elif args.toDate and args.fromDate and not args.preSelect:
|
||||||
try:
|
# try:
|
||||||
#fromDate = datetime.date.fromisoformat(args.fromDate)
|
# #fromDate = datetime.date.fromisoformat(args.fromDate)
|
||||||
fromDate = datetime.datetime.strptime(args.fromDate, "%Y-%m-%d")
|
# fromDate = datetime.datetime.strptime(args.fromDate, "%Y-%m-%d")
|
||||||
|
|
||||||
#toDate = datetime.date.fromisoformat(args.toDate)
|
# #toDate = datetime.date.fromisoformat(args.toDate)
|
||||||
toDate = datetime.datetime.strptime(args.toDate, "%Y-%m-%d")
|
# toDate = datetime.datetime.strptime(args.toDate, "%Y-%m-%d")
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
print("Progam closed: " + str(e))
|
# print("Progam closed: " + str(e))
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
if toDate < fromDate:
|
# if toDate < fromDate:
|
||||||
print("--toDate can't be older than --fromDate")
|
# print("--toDate can't be older than --fromDate")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
if toDate > datetime.date.today() or fromDate > datetime.date.today():
|
# if toDate > datetime.date.today() or fromDate > datetime.date.today():
|
||||||
print("--toDate or --fromDate can't be in the future")
|
# print("--toDate or --fromDate can't be in the future")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
elif args.preSelect and not args.fromDate and not args.toDate:
|
# elif args.preSelect and not args.fromDate and not args.toDate:
|
||||||
|
|
||||||
date = datetime.date.today()
|
# date = datetime.date.today()
|
||||||
|
|
||||||
if args.preSelect == "week":
|
# if args.preSelect == "week":
|
||||||
fromDate, toDate = previous_week_range(date)
|
# fromDate, toDate = previous_week_range(date)
|
||||||
elif args.preSelect == "month":
|
# elif args.preSelect == "month":
|
||||||
fromDate, toDate = previous_month_range(date)
|
# fromDate, toDate = previous_month_range(date)
|
||||||
elif args.preSelect == "day":
|
# elif args.preSelect == "day":
|
||||||
fromDate, toDate = previous_day_range(date)
|
# fromDate, toDate = previous_day_range(date)
|
||||||
else:
|
# else:
|
||||||
print("--preSelect must be week or month")
|
# print("--preSelect must be week or month")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
else:
|
# else:
|
||||||
print("Invalid arguments, please use --help")
|
# print("Invalid arguments, please use --help")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
if args.slices == None:
|
# if args.slices == None:
|
||||||
print("-s or --slices must not be null and needs at least one letter of h d t or y, lower- or uppercase.")
|
# print("-s or --slices must not be null and needs at least one letter of h d t or y, lower- or uppercase.")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
elif sum([1 if one_inp in str.lower(args.slices) else 0 for one_inp in ['h','d','t','y'] ]) == 0:
|
# elif sum([1 if one_inp in str.lower(args.slices) else 0 for one_inp in ['h','d','t','y'] ]) == 0:
|
||||||
print("-s or --slices must has at least one letter of h d t or y, lower- or uppercase.")
|
# print("-s or --slices must has at least one letter of h d t or y, lower- or uppercase.")
|
||||||
sys.exit()
|
# sys.exit()
|
||||||
return fromDate, toDate
|
# return fromDate, toDate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -157,8 +157,6 @@ def applyPatterns(subject):
|
||||||
break
|
break
|
||||||
|
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parseAndCreateSLOObject(row):
|
def parseAndCreateSLOObject(row):
|
||||||
|
|
@ -224,8 +222,6 @@ def getParsedSLOs(ENV, DTTOKEN, DTURL):
|
||||||
for index, row in slosF.iterrows():
|
for index, row in slosF.iterrows():
|
||||||
#if row['id'] == "06292149-0f7f-34f6-b226-dfd9f680486d": #or row['id'] == "ab1bf34a-10fc-3446-9cc7-79d257498a52":
|
#if row['id'] == "06292149-0f7f-34f6-b226-dfd9f680486d": #or row['id'] == "ab1bf34a-10fc-3446-9cc7-79d257498a52":
|
||||||
slos.append(parseAndCreateSLOObject(row))
|
slos.append(parseAndCreateSLOObject(row))
|
||||||
#print("filter:"+row["filter"])
|
|
||||||
|
|
||||||
return slos
|
return slos
|
||||||
|
|
||||||
def write_to_excel(ignored, notExists):
|
def write_to_excel(ignored, notExists):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue