From 245a296ec4124f81d9f0a7f23af91fb8af3bacab Mon Sep 17 00:00:00 2001 From: "SLW\\ARNAUA" Date: Mon, 6 Mar 2023 12:10:10 +0100 Subject: [PATCH] updated convert.py --- convert.py | 67 ++++++------------- output/CN_Prod/slo/TP_Mobile_Login.tf | 49 ++++++++++++++ output/CN_Prod/slo/TP_Mobile_Mapping.tf | 51 ++++++++++++++ output/CN_Prod/slo/TP_Mobile_Remote360.tf | 57 ++++++++++++++++ .../CN_Prod/slo/TP_Mobile_Send2VehicleMGU.tf | 45 +++++++++++++ output/CN_Prod/slo/TP_Mobile_VehicleList.tf | 43 ++++++++++++ output/EMEA_Prod/slo/TP_Mobile_Login.tf | 49 ++++++++++++++ output/EMEA_Prod/slo/TP_Mobile_Mapping.tf | 51 ++++++++++++++ output/EMEA_Prod/slo/TP_Mobile_Remote360.tf | 57 ++++++++++++++++ .../slo/TP_Mobile_Send2VehicleMGU.tf | 45 +++++++++++++ output/EMEA_Prod/slo/TP_Mobile_VehicleList.tf | 43 ++++++++++++ output/NA_Prod/slo/TP_Mobile_Login.tf | 49 ++++++++++++++ output/NA_Prod/slo/TP_Mobile_Mapping.tf | 51 ++++++++++++++ output/NA_Prod/slo/TP_Mobile_Remote360.tf | 57 ++++++++++++++++ .../NA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf | 45 +++++++++++++ output/NA_Prod/slo/TP_Mobile_VehicleList.tf | 43 ++++++++++++ 16 files changed, 756 insertions(+), 46 deletions(-) create mode 100644 output/CN_Prod/slo/TP_Mobile_Login.tf create mode 100644 output/CN_Prod/slo/TP_Mobile_Mapping.tf create mode 100644 output/CN_Prod/slo/TP_Mobile_Remote360.tf create mode 100644 output/CN_Prod/slo/TP_Mobile_Send2VehicleMGU.tf create mode 100644 output/CN_Prod/slo/TP_Mobile_VehicleList.tf create mode 100644 output/EMEA_Prod/slo/TP_Mobile_Login.tf create mode 100644 output/EMEA_Prod/slo/TP_Mobile_Mapping.tf create mode 100644 output/EMEA_Prod/slo/TP_Mobile_Remote360.tf create mode 100644 output/EMEA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf create mode 100644 output/EMEA_Prod/slo/TP_Mobile_VehicleList.tf create mode 100644 output/NA_Prod/slo/TP_Mobile_Login.tf create mode 100644 output/NA_Prod/slo/TP_Mobile_Mapping.tf create mode 100644 output/NA_Prod/slo/TP_Mobile_Remote360.tf create mode 100644 output/NA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf create mode 100644 output/NA_Prod/slo/TP_Mobile_VehicleList.tf diff --git a/convert.py b/convert.py index 876c732..a9d47fc 100644 --- a/convert.py +++ b/convert.py @@ -23,27 +23,9 @@ FOLDERS = {"My Journey":"DE-3", "China Services":"EC-DE"} # methods -def homogenize_metrics(metricList): - for metric in metricList: - if len(metricList) < 4: - metricList.append('') - return metricList - -def homogenize_services(serviceList): - for service in serviceList: - if len(serviceList) < 2: - serviceList.append('') - return serviceList - -def homogenize_keyRequests(keyRequestLists): - for keyRequestList in keyRequestLists: - if len(keyRequestLists) < 2: - keyRequestLists.append('') - return keyRequestLists - -def template_logic(metricList): - for template,metricTemplate in TEMPLATE_FILES.items(): - if all([item in metricTemplate for item in metricList]): +def template_logic(metric): + for template,metricElement in TEMPLATE_FILES.items(): + if all([item in metricElement for item in metric]): # if set(metricList) == set(metricTemplate): return template print("Problem occured while matching metric: Exiting program...") @@ -62,9 +44,9 @@ def main(configFile): slo_definition_tresholds_failure = None environments = {} template = None - metricList = [] - serviceList = [] - keyRequestList = [] + metric = None + services = None + keyRequests = None try: # read yaml file @@ -100,35 +82,28 @@ def main(configFile): lstrip_blocks=True) # generate terraform file - for i,(environment,ev) in enumerate(environments.items()): + for environment,ev in environments.items(): folder_path = os.path.join(cwd,OUTPUT_FOLDER_BASENAME,environment.replace('-','_'),"slo") if not os.path.exists(folder_path): os.makedirs(folder_path) - template = template_logic(nested_lookup('metric',ev)) - metricList = homogenize_metrics(nested_lookup('metric',ev)) + metric = nested_lookup('metric',ev) - for service in ev[i]["filter"]: - serviceList.append(nested_lookup('service',service)) - keyRequestList.append(nested_lookup('keyRequests',service)) - i = 0 + for service in ev[0]["filter"]: + services = nested_lookup('service',service) + keyRequests = nested_lookup('keyRequests',service) - with open(os.path.join(folder_path,module_name+".tf"),"w+") as file: - jinja_template = jinja_environment.get_template(template) - file.write(jinja_template.render(module=module_name, - slo_name=slo_name, - metric=metricList[0], - metricA=metricList[0],metricB=metricList[1],metricC=metricList[2],metricD=metricList[3], - description=description, - services='~",\n\t\t\t\t~"'.join(serviceList[0]), - servicesA='~",\n\t\t\t\t~"'.join(serviceList[0]),servicesB='~",\n\t\t\t\t~"'.join(serviceList[1]), - keyRequests='~",\n\t\t\t\t~"'.join(itertools.chain.from_iterable(keyRequestList[0])), - keyRequestsA='~",\n\t\t\t\t~"'.join(itertools.chain.from_iterable(keyRequestList[0])), - keyRequestsB='~",\n\t\t\t\t~"'.join(itertools.chain.from_iterable(keyRequestList[1])), - target=slo_definition_tresholds_failure, - warning=slo_definition_tresholds_warning)) + with open(os.path.join(folder_path,module_name+".tf"),"w+") as file: + jinja_template = jinja_environment.get_template(template_logic(metric)) + file.write(jinja_template.render(module=module_name, + slo_name=slo_name, + metric=metric, + description=description, + services='~",\n\t\t\t\t~"'.join(services), + keyRequests='~",\n\t\t\t\t~"'.join(itertools.chain.from_iterable(keyRequests)), + target=slo_definition_tresholds_failure, + warning=slo_definition_tresholds_warning)) - if __name__ == "__main__": # pre-initialization get current working directory diff --git a/output/CN_Prod/slo/TP_Mobile_Login.tf b/output/CN_Prod/slo/TP_Mobile_Login.tf new file mode 100644 index 0000000..9d043d7 --- /dev/null +++ b/output/CN_Prod/slo/TP_Mobile_Login.tf @@ -0,0 +1,49 @@ +module TP_Mobile_Login { + + source = "../../_dynatrace-base-modules/dynatrace-service-level-objective" + + name = "TP_Mobile_Login" + + description = "2.0 SLO Mobile" + + # entity selector object + filter = "" + + # metric expression of the calculation as done in data explorer ui + metric_expression = </primary~", + ~"POST /api/v2/vehicles//primary/map~", + ~"POST /api/v1/vehicles//validate-security-code~", + ~"POST /api/v1/vehicles//resend-security-code~", + ~"DELETE /api/v1/vehicles/~" + )"))))):splitBy()) + / + (builtin:service.keyRequest.count.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method), + fromRelationship.isServiceMethodOfService( + type(~"SERVICE~"),entityName.in( + ~"vehicle-mapping-composite-service - PROD~" + ) + ),entityName.in( + ~"POST /api/v2/vehicles//primary~", + ~"POST /api/v2/vehicles//primary/map~", + ~"POST /api/v1/vehicles//validate-security-code~", + ~"POST /api/v1/vehicles//resend-security-code~", + ~"DELETE /api/v1/vehicles/~" + )"))))):splitBy())) + EOT + + # if not set (removed) it's defaulted to "-1d" + timeframe = "-1d" + + # currently the only possible value + evaluation = "AGGREGATE" + + # target and warning percentage of the SLO as double + target = 98 # if not set(removed) it's defaulted to 98 + warning = 99 # if not set(removed) it's defaulted to 99 + +} \ No newline at end of file diff --git a/output/CN_Prod/slo/TP_Mobile_Remote360.tf b/output/CN_Prod/slo/TP_Mobile_Remote360.tf new file mode 100644 index 0000000..c664d0d --- /dev/null +++ b/output/CN_Prod/slo/TP_Mobile_Remote360.tf @@ -0,0 +1,57 @@ +module TP_Mobile_Remote360 { + + source = "../../_dynatrace-base-modules/dynatrace-service-level-objective" + + name = "TP_Mobile_Remote360" + + description = "2.0 SLO Mobile" + + # entity selector object + filter = "" + + # metric expression of the calculation as done in data explorer ui + metric_expression = <~", + ~"POST /api/v1/download/[UUID]//confirm~", + ~"GET /api/v1/vehicle//egomodelurl~", + ~"GET /api/v1/vehicle//key~", + ~"GET /api/v1/recordings/vehicle/~" + )"))))):splitBy()) + / + (builtin:service.keyRequest.count.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method), + fromRelationship.isServiceMethodOfService( + type(~"SERVICE~"),entityName.in( + ~"remote-360-composite-service - PROD~" + ) + ),entityName.in( + ~"GET /api/v1/events/[UUID]~", + ~"POST /api/v1/events/[UUID]/cancel~", + ~"POST /api/v1/event/execute~", + ~"GET /api/v1/download/[UUID]/~", + ~"POST /api/v1/download/[UUID]//confirm~", + ~"GET /api/v1/vehicle//egomodelurl~", + ~"GET /api/v1/vehicle//key~", + ~"GET /api/v1/recordings/vehicle/~" + )"))))):splitBy())) + EOT + + # if not set (removed) it's defaulted to "-1d" + timeframe = "-1d" + + # currently the only possible value + evaluation = "AGGREGATE" + + # target and warning percentage of the SLO as double + target = 98 # if not set(removed) it's defaulted to 98 + warning = 99 # if not set(removed) it's defaulted to 99 + +} \ No newline at end of file diff --git a/output/CN_Prod/slo/TP_Mobile_Send2VehicleMGU.tf b/output/CN_Prod/slo/TP_Mobile_Send2VehicleMGU.tf new file mode 100644 index 0000000..2e16584 --- /dev/null +++ b/output/CN_Prod/slo/TP_Mobile_Send2VehicleMGU.tf @@ -0,0 +1,45 @@ +module TP_Mobile_Send2VehicleMGU { + + source = "../../_dynatrace-base-modules/dynatrace-service-level-objective" + + name = "TP_Mobile_Send2VehicleMGU" + + description = "2.0 SLO Mobile" + + # entity selector object + filter = "" + + # metric expression of the calculation as done in data explorer ui + metric_expression = </primary~", + ~"POST /api/v2/vehicles//primary/map~", + ~"POST /api/v1/vehicles//validate-security-code~", + ~"POST /api/v1/vehicles//resend-security-code~", + ~"DELETE /api/v1/vehicles/~" + )"))))):splitBy()) + / + (builtin:service.keyRequest.count.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method), + fromRelationship.isServiceMethodOfService( + type(~"SERVICE~"),entityName.in( + ~"vehicle-mapping-composite-service - PROD~" + ) + ),entityName.in( + ~"POST /api/v2/vehicles//primary~", + ~"POST /api/v2/vehicles//primary/map~", + ~"POST /api/v1/vehicles//validate-security-code~", + ~"POST /api/v1/vehicles//resend-security-code~", + ~"DELETE /api/v1/vehicles/~" + )"))))):splitBy())) + EOT + + # if not set (removed) it's defaulted to "-1d" + timeframe = "-1d" + + # currently the only possible value + evaluation = "AGGREGATE" + + # target and warning percentage of the SLO as double + target = 98 # if not set(removed) it's defaulted to 98 + warning = 99 # if not set(removed) it's defaulted to 99 + +} \ No newline at end of file diff --git a/output/EMEA_Prod/slo/TP_Mobile_Remote360.tf b/output/EMEA_Prod/slo/TP_Mobile_Remote360.tf new file mode 100644 index 0000000..c664d0d --- /dev/null +++ b/output/EMEA_Prod/slo/TP_Mobile_Remote360.tf @@ -0,0 +1,57 @@ +module TP_Mobile_Remote360 { + + source = "../../_dynatrace-base-modules/dynatrace-service-level-objective" + + name = "TP_Mobile_Remote360" + + description = "2.0 SLO Mobile" + + # entity selector object + filter = "" + + # metric expression of the calculation as done in data explorer ui + metric_expression = <~", + ~"POST /api/v1/download/[UUID]//confirm~", + ~"GET /api/v1/vehicle//egomodelurl~", + ~"GET /api/v1/vehicle//key~", + ~"GET /api/v1/recordings/vehicle/~" + )"))))):splitBy()) + / + (builtin:service.keyRequest.count.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method), + fromRelationship.isServiceMethodOfService( + type(~"SERVICE~"),entityName.in( + ~"remote-360-composite-service - PROD~" + ) + ),entityName.in( + ~"GET /api/v1/events/[UUID]~", + ~"POST /api/v1/events/[UUID]/cancel~", + ~"POST /api/v1/event/execute~", + ~"GET /api/v1/download/[UUID]/~", + ~"POST /api/v1/download/[UUID]//confirm~", + ~"GET /api/v1/vehicle//egomodelurl~", + ~"GET /api/v1/vehicle//key~", + ~"GET /api/v1/recordings/vehicle/~" + )"))))):splitBy())) + EOT + + # if not set (removed) it's defaulted to "-1d" + timeframe = "-1d" + + # currently the only possible value + evaluation = "AGGREGATE" + + # target and warning percentage of the SLO as double + target = 98 # if not set(removed) it's defaulted to 98 + warning = 99 # if not set(removed) it's defaulted to 99 + +} \ No newline at end of file diff --git a/output/EMEA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf b/output/EMEA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf new file mode 100644 index 0000000..2e16584 --- /dev/null +++ b/output/EMEA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf @@ -0,0 +1,45 @@ +module TP_Mobile_Send2VehicleMGU { + + source = "../../_dynatrace-base-modules/dynatrace-service-level-objective" + + name = "TP_Mobile_Send2VehicleMGU" + + description = "2.0 SLO Mobile" + + # entity selector object + filter = "" + + # metric expression of the calculation as done in data explorer ui + metric_expression = </primary~", + ~"POST /api/v2/vehicles//primary/map~", + ~"POST /api/v1/vehicles//validate-security-code~", + ~"POST /api/v1/vehicles//resend-security-code~", + ~"DELETE /api/v1/vehicles/~" + )"))))):splitBy()) + / + (builtin:service.keyRequest.count.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method), + fromRelationship.isServiceMethodOfService( + type(~"SERVICE~"),entityName.in( + ~"vehicle-mapping-composite-service - PROD~" + ) + ),entityName.in( + ~"POST /api/v2/vehicles//primary~", + ~"POST /api/v2/vehicles//primary/map~", + ~"POST /api/v1/vehicles//validate-security-code~", + ~"POST /api/v1/vehicles//resend-security-code~", + ~"DELETE /api/v1/vehicles/~" + )"))))):splitBy())) + EOT + + # if not set (removed) it's defaulted to "-1d" + timeframe = "-1d" + + # currently the only possible value + evaluation = "AGGREGATE" + + # target and warning percentage of the SLO as double + target = 98 # if not set(removed) it's defaulted to 98 + warning = 99 # if not set(removed) it's defaulted to 99 + +} \ No newline at end of file diff --git a/output/NA_Prod/slo/TP_Mobile_Remote360.tf b/output/NA_Prod/slo/TP_Mobile_Remote360.tf new file mode 100644 index 0000000..c664d0d --- /dev/null +++ b/output/NA_Prod/slo/TP_Mobile_Remote360.tf @@ -0,0 +1,57 @@ +module TP_Mobile_Remote360 { + + source = "../../_dynatrace-base-modules/dynatrace-service-level-objective" + + name = "TP_Mobile_Remote360" + + description = "2.0 SLO Mobile" + + # entity selector object + filter = "" + + # metric expression of the calculation as done in data explorer ui + metric_expression = <~", + ~"POST /api/v1/download/[UUID]//confirm~", + ~"GET /api/v1/vehicle//egomodelurl~", + ~"GET /api/v1/vehicle//key~", + ~"GET /api/v1/recordings/vehicle/~" + )"))))):splitBy()) + / + (builtin:service.keyRequest.count.server:filter(and(or(in("dt.entity.service_method",entitySelector("type(service_method), + fromRelationship.isServiceMethodOfService( + type(~"SERVICE~"),entityName.in( + ~"remote-360-composite-service - PROD~" + ) + ),entityName.in( + ~"GET /api/v1/events/[UUID]~", + ~"POST /api/v1/events/[UUID]/cancel~", + ~"POST /api/v1/event/execute~", + ~"GET /api/v1/download/[UUID]/~", + ~"POST /api/v1/download/[UUID]//confirm~", + ~"GET /api/v1/vehicle//egomodelurl~", + ~"GET /api/v1/vehicle//key~", + ~"GET /api/v1/recordings/vehicle/~" + )"))))):splitBy())) + EOT + + # if not set (removed) it's defaulted to "-1d" + timeframe = "-1d" + + # currently the only possible value + evaluation = "AGGREGATE" + + # target and warning percentage of the SLO as double + target = 98 # if not set(removed) it's defaulted to 98 + warning = 99 # if not set(removed) it's defaulted to 99 + +} \ No newline at end of file diff --git a/output/NA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf b/output/NA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf new file mode 100644 index 0000000..2e16584 --- /dev/null +++ b/output/NA_Prod/slo/TP_Mobile_Send2VehicleMGU.tf @@ -0,0 +1,45 @@ +module TP_Mobile_Send2VehicleMGU { + + source = "../../_dynatrace-base-modules/dynatrace-service-level-objective" + + name = "TP_Mobile_Send2VehicleMGU" + + description = "2.0 SLO Mobile" + + # entity selector object + filter = "" + + # metric expression of the calculation as done in data explorer ui + metric_expression = <