Beispiel #1
0
 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 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(
                 content, str) else block_list("sort", val,
                                               assignmentString)
         elif key in [
                 "event", "right_yaxis", "widget_layout", "xaxis", "yaxis",
                 "style"
         ]:
             res += block(key, val, assignmentString)
         elif key == "time":
             res += assignmentString("live_span", val["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 }}'
Beispiel #3
0
 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
Beispiel #4
0
 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 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"]:
             pass
         elif key in ["options"]:
             res += self.options_schema(val)
         else:
             res += assignmentString(key, val)
     return res
Beispiel #6
0
 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 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 ["silenced"]:
             # res += self.block(key, val, assignmentString)
             # res += block(key, val, assignmentString)
             pass  # unsupported block tyep.
         else:
             res += assignmentString(key, val)
     return res
Beispiel #8
0
 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":
             res += block_list("widget", val, self.widget_schema)
         elif key == "template_variables":
             res += block_list("template_variable", val, assignmentString)
         elif key == "template_variable_presets":
             res += block_list("template_variable_preset", val,
                               self.template_variable_preset_schema)
         else:
             res += assignmentString(key, val)
     return res