def dashboard_schema(self, dashboardData): """ Create terrafom dashboard schema. Args: . dashboardData - datadog dashboard dict. """ logging.debug(f'Dashboard schema dashboard data => \n {dashboardData}') res = "" for key, val in dashboardData.items(): if key in ["id", "reflow_type"]: pass elif key == "widgets": logging.debug(f'Dashboard schema widgets => \n {val}') res += block_list( "widget", val, self.widget_schema) if val is not None else "" elif key == "template_variables": logging.debug( f'Dashboard schema template_variables => \n {val}') res += block_list("template_variable", val, assignmentString) if val is not None else "" elif key == "template_variable_presets": logging.debug( f'Dashboard schema template_variable_presets => \n {val}') res += block_list("template_variable_preset", val, self.template_variable_preset_schema ) if val is not None else "" else: res += assignmentString(key, val) return res
def request_schema(self, key, val): """ Converter for request schema. Args: . key - key name in the schema. . val - the key value. """ logging.debug(f'request schema key => {key} , val => {val}') res = "" if key in ["style", "process_query", "apm_stats_query"]: res += block(key, val, assignmentString) elif key in ["metadata", "conditional_formats"]: res += block_list(key, val, assignmentString) elif key in [ "log_query", "rum_query", "apm_query", "security_query", "network_query" ]: res += block(key, val, self.request_nested_schema) elif key in ["fill", "size"]: res += block(key, val, self.request_schema) elif key in ["profile_metrics_query"]: #unsupported keys pass else: res += assignmentString(key, val) return res
def template_variable_preset_schema(self, key, val): """ Converter for template_variable_present schema. Args: . key - key name in the schema. . val - the key value. """ logging.debug( f'template variable preset schema key => {key} , val => {val}') res = "" if key == "name": res += assignmentString(key, val) elif key == "template_variables": res += block_list("template_variable", val, assignmentString) return res
def attributes_schema(self, content): """ Converter of attributes block. Args: . content - attributes_schema dict. """ logging.debug(f'LogMetrics attributes schema content => \n {content}') res = "" for key, val in content.items(): if key in ["compute", "filter"]: res += block(key, val, assignmentString) elif key in ["group_by"]: res += block_list("group_by", val, assignmentString) else: res += assignmentString(key, val) return res
def category_schema(self, key, val): """ Convert category schema. Args: . key - key name in the schema. . val - the key value. """ logging.debug(f'category schema , key => {key} val => {val}') res = "" if key in ["filter"]: res += block_list("filter", val, self.filter_schema) if isinstance( val, list) else block("filter", val, self.filter_schema) else: res += assignmentString(key, val) return res
def category_processor_schema(self, key, val): """ Convert category_processor schema. Args: . key - key name in the schema. . val - the key value. """ logging.debug(f'category_processor schema , key => {key} val => {val}') res = "" if key in ["type"]: pass elif key in ["categories"]: res += block_list("category", val, self.category_schema) else: res += assignmentString(key, val) return res
def pipeline_schema(self, pipelineData): """ Create terrafom pipeline schema. Args: . pipelineData - datadog pipeline dict. """ logging.debug(f'Pipeline schema pipeline data => \n {pipelineData}') res = "" for key, val in pipelineData.items(): if key in ["id", "type", "is_read_only"]: pass elif key in ["filter"]: res += block_list("filter", val, self.filter_schema) if isinstance( val, list) else block( "filter", val, self.filter_schema) elif key == "processors": res += self.pipeline_processors_engine(val) else: res += assignmentString(key, val) return res
def request_nested_schema(self, key, val): """ Converter for request nested schema. Args: . key - key name in the schema. . val - the key value. """ logging.debug(f'request nested schema key => {key} , val => {val}') res = "" if key in ["search"]: res += assignmentString("search_query", val["query"]) elif key in ["compute"]: res += block("compute_query", val, assignmentString) elif key in ["compute_query"]: res += block("compute_query", val, assignmentString) elif key in ["multi_compute"]: pass elif key in ["group_by"]: res += block_list("group_by", val, self.group_by_schema) else: res += assignmentString(key, val) return res
def widget_definition_schema(self, content): """ Converter for widget dfinition schema. Args: . content - the content dict of the widget definition. """ logging.debug(f'widget definition schema content => \n {content}') res = "" for key, val in content.items(): if key in [ "type", "legend_layout", "legend_columns", "global_time_target", "reflow_type" ]: pass elif key == "custom_links": res += block_list("custom_link", val, assignmentString) elif key == "requests": res += block_list("request", val, self.request_schema) if isinstance( val, list) else block( "request", val, self.request_schema) elif key == "widgets": res += block_list("widget", val, self.widget_schema) elif key == "events": res += block_list("event", val, assignmentString) elif key == "markers": res += block_list("marker", val, assignmentString) elif key == "sort": res += assignmentString("sort", val) if isinstance( val, str) else block_list("sort", val, assignmentString) elif key in [ "event", "right_yaxis", "widget_layout", "xaxis", "yaxis", "style", "view" ]: res += block(key, val, assignmentString) elif key == "time": live_span = val.get("live_span", "") if live_span != "": res += assignmentString("live_span", live_span) else: res += assignmentString(key, val) definition_type = "service_level_objective" if content[ "type"] == "slo" else content["type"] return f'\n {definition_type}_definition {{ {res} \n }}'