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
Beispiel #2
0
 def options_schema(self, content):
     """
     Converter of options block.
         Args:
         . content - options dict.
     """
     logging.debug(f'Monitor options schema content  => \n {content}')
     res = ""
     for key, val in content.items():
         if key in ["thresholds"]:
             # res += self.block("monitor_thresholds", val, assignmentString)
             res += block("monitor_thresholds", val, assignmentString)
         elif key in ["threshold_windows"]:
             res += block("monitor_threshold_windows", val,
                          assignmentString)
         elif key in ["silenced"]:
             # res += self.block(key, val, assignmentString)
             # res += block(key, val, assignmentString)
             pass  # unsupported block tyep.
         # Following argument not supported yet in Terraform(used in log type)
         elif key in [
                 "queryConfig", "aggregation", "groupby_simple_monitor",
                 "restriction_query"
         ]:
             pass
         else:
             res += assignmentString(key, val)
     return res
 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 logMetrics_schema(self, logMetricsData):
     """
     Create terrafom logMetrics schema.
         Args:
         . logMetricsData - datadog logMetrics dict.
     """
     logging.debug(f'LogMetrics schema data => \n {logMetricsData}')
     res = ""
     for key, val in logMetricsData.items():
         if key in ["type"]:
             pass
         elif key in ["id"]:
             res += assignmentString("name", val)
         elif key in ["attributes"]:
             res += self.attributes_schema(val)
         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 }}'
    def filter_schema(self, key, val):
        """
        Convert filter schema.
            Args:
            . key - key name in the schema. 
            . val - the key value.
        """
        logging.debug(f'filter schema , key => {key} val => {val}')
        res = ""

        if key in ["query"]:
            if not val:
                raise ValueError(
                    f'filter query is required and can not be empty!!!')
            res += assignmentString(key, 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 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 processor_schema(self, key, val):
        """
        Convert processor schema.
            Args:
            . key - key name in the schema. 
            . val - the key value.
        """
        logging.debug(f'processors schema , key => {key} val => {val}')
        res = ""

        if key in ["type"]:
            pass
        else:
            res += assignmentString(key, val)

        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 group_by_schema(self, key, val):
     """
     Converter for group_by schema.
         Args:
         . key - key name in the schema. 
         . val - the key value.
     """
     logging.debug(f'group_by schema key => {key} , val => {val}')
     res = ""
     if key in ["sort"]:
         res += block("sort_query", val, assignmentString)
     elif key in ["sort_query"]:
         res += block("sort_query", 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 grok_parser_schema(self, key, val):
        """
        Convert grok_parser schema.
            Args:
            . key - key name in the schema. 
            . val - the key value.
        """
        logging.debug(f'grok_parser schema , key => {key} val => {val}')
        res = ""

        if key in ["type"]:
            pass
        elif key in ["grok"]:
            res += block("grok", val, assignmentString)
        else:
            res += assignmentString(key, val)

        return res
Beispiel #15
0
 def monitor_schema(self, monitorData):
     """
     Create terrafom monitor schema.
         Args:
         . monitorData - datadog monitor dict.
     """
     logging.debug(f'Monitor schema dashboard data => \n {monitorData}')
     res = ""
     for key, val in monitorData.items():
         if key in ["id", "classification"]:
             pass
         elif key in ["options"]:
             res += self.options_schema(val)
         # elif key in ["priority"]:
         #     if val is None:
         #         res += assignmentString(key, 'null')
         #     else:
         #         res += assignmentString(key, val)
         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