Class: DatadogExporter::Monitors::Utilities::TemplateManager
- Inherits:
-
Object
- Object
- DatadogExporter::Monitors::Utilities::TemplateManager
- 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
- #create_monitor(template, environment: :base) ⇒ Object
-
#create_template(datadog_hash, environment: :base) ⇒ Hash
Transforms the monitor to a template.
- #filter_by_template_keys(datadog_hash) ⇒ Object
-
#initialize(config: DatadogExporter::Client::Config.new) ⇒ TemplateManager
constructor
A new instance of TemplateManager.
Constructor Details
#initialize(config: DatadogExporter::Client::Config.new) ⇒ TemplateManager
Returns a new instance of TemplateManager.
54 55 56 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 54 def initialize(config: DatadogExporter::Client::Config.new) @config = config.organizations_config[:monitors] end |
Instance Method Details
#create_monitor(template, environment: :base) ⇒ Object
74 75 76 77 78 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 74 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
68 69 70 71 72 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 68 def create_template(datadog_hash, environment: :base) placeholders = @config[:placeholders][environment] replace_values_with_placeholders(filter_by_template_keys(datadog_hash), placeholders) end |
#filter_by_template_keys(datadog_hash) ⇒ Object
80 81 82 83 84 |
# File 'lib/datadog_exporter/monitors/utilities/template_manager.rb', line 80 def filter_by_template_keys(datadog_hash) return datadog_hash if template_keys.empty? datadog_hash.slice(*template_keys) end |