Class: DatadogExporter::Monitors::Utilities::TemplateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog_exporter/monitors/utilities/template_manager.rb

Overview

This class transform the monitor into a template

Defined Under Namespace

Classes: PlaceholderToString, StringToPlaceholder

Instance Method Summary collapse

Constructor Details

#initialize(config: DatadogExporter::Client::Config.new) ⇒ TemplateManager

Returns a new instance of TemplateManager.



52
53
54
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 52

def initialize(config: DatadogExporter::Client::Config.new)
  @config = config.organizations_config[:monitors]
end

Instance Method Details

#create_monitor(template, environment: :base) ⇒ Object



72
73
74
75
76
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 72

def create_monitor(template, environment: :base)
  placeholders = @config[:placeholders][environment]

  replace_placeholders_with_values(placeholders, filter_by_template_keys(template))
end

#create_template(datadog_hash, environment: :base) ⇒ Hash

 Transforms the monitor to a template

Placeholders can be defined in a “organizations_config.yml” file See “organizations_config.example.yml” to see an example

If no placeholder is defined, it returns the monitor as it is

Parameters:

  • datadog_hash (Hash)

    The monitor configuration

  • environment (Symbol) (defaults to: :base)

    (optional) The env tag name where the placeholders are defined

Returns:

  • (Hash)

    The transformed monitor into a template with placeholders



66
67
68
69
70
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 66

def create_template(datadog_hash, environment: :base)
  placeholders = @config[:placeholders][environment]

  replace_values_with_placeholders(filter_by_template_keys(datadog_hash), placeholders)
end