Class: DatadogExporter::Monitors::Export
- Inherits:
-
Object
- Object
- DatadogExporter::Monitors::Export
- Defined in:
- lib/datadog_exporter/monitors/export.rb
Overview
This class provide export tools for Datadog Monitors
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#export(tag: nil) ⇒ String
Exports Datadog monitors configuration in YAML files.
-
#export_as_template(tag: nil) ⇒ String
Exports Datadog monitors configuration in YAML files as templates.
-
#initialize(config: DatadogExporter::Client::Config.new, client: DatadogExporter::Client.new(config:), request: DatadogExporter::DatadogApiRequests::Monitors.new(config:, client:), name_transformer: Utilities::NameTransformer.new, template_creator: Utilities::TemplateManager.new(config:), file_class: File) ⇒ Export
constructor
A new instance of Export.
Constructor Details
#initialize(config: DatadogExporter::Client::Config.new, client: DatadogExporter::Client.new(config:), request: DatadogExporter::DatadogApiRequests::Monitors.new(config:, client:), name_transformer: Utilities::NameTransformer.new, template_creator: Utilities::TemplateManager.new(config:), file_class: File) ⇒ Export
Returns a new instance of Export.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/datadog_exporter/monitors/export.rb', line 8 def initialize( config: DatadogExporter::Client::Config.new, client: DatadogExporter::Client.new(config:), request: DatadogExporter::DatadogApiRequests::Monitors.new(config:, client:), name_transformer: Utilities::NameTransformer.new, template_creator: Utilities::TemplateManager.new(config:), file_class: File ) @config = config @request = request @monitors_base_path = config.base_path.join(DatadogExporter::Monitors::EXPORT_FOLDER) @name_transformer = name_transformer @template_creator = template_creator @file_class = file_class end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/datadog_exporter/monitors/export.rb', line 6 def config @config end |
Instance Method Details
#export(tag: nil) ⇒ String
Exports Datadog monitors configuration in YAML files. If no tag is provided, it exports all the monitors.
31 32 33 34 35 36 37 |
# File 'lib/datadog_exporter/monitors/export.rb', line 31 def export(tag: nil) reset_monitors_dir monitors(tag:).each { |exported_datadog_hash| save_original(exported_datadog_hash) } config.logger.info("Exported #{@monitors.count} monitors to #{@monitors_base_path}") end |
#export_as_template(tag: nil) ⇒ String
Exports Datadog monitors configuration in YAML files as templates. If no tag is provided, it exports all the monitors.
See TemplateManager for more information about the transformation.
48 49 50 51 52 53 54 55 56 |
# File 'lib/datadog_exporter/monitors/export.rb', line 48 def export_as_template(tag: nil) reset_monitors_dir monitors(tag:).each { |exported_datadog_hash| save_template(exported_datadog_hash) } config.logger.info( "Exported #{@monitors.count} monitor templates to #{@monitors_base_path}", ) end |