Class: DatadogExporter::DatadogApiRequests::Monitors
- Inherits:
-
Object
- Object
- DatadogExporter::DatadogApiRequests::Monitors
- Defined in:
- lib/datadog_exporter/datadog_api_requests/monitors.rb
Overview
The class that contains all the Datadog API client requests for Monitors
Instance Attribute Summary collapse
-
#monitors_api ⇒ Object
readonly
Returns the value of attribute monitors_api.
Instance Method Summary collapse
-
#create(monitor_hash) ⇒ Integer
Creates a monitor in Datadog.
-
#find(monitor_id) ⇒ Hash
Returns a Datadog monitor configuration.
-
#initialize(config: DatadogExporter::Client::Config.new, client: DatadogExporter::Client.new(config:), monitors_api: DatadogAPIClient::V1::MonitorsAPI.new(client.datadog_client)) ⇒ Monitors
constructor
A new instance of Monitors.
-
#list_monitors(tag: nil) ⇒ Array<Hash>
Returns a list of Hashes containing Datadog monitor configuration.
Constructor Details
#initialize(config: DatadogExporter::Client::Config.new, client: DatadogExporter::Client.new(config:), monitors_api: DatadogAPIClient::V1::MonitorsAPI.new(client.datadog_client)) ⇒ Monitors
Returns a new instance of Monitors.
7 8 9 10 11 12 13 14 |
# File 'lib/datadog_exporter/datadog_api_requests/monitors.rb', line 7 def initialize( config: DatadogExporter::Client::Config.new, client: DatadogExporter::Client.new(config:), monitors_api: DatadogAPIClient::V1::MonitorsAPI.new(client.datadog_client) ) @client = client @monitors_api = monitors_api end |
Instance Attribute Details
#monitors_api ⇒ Object (readonly)
Returns the value of attribute monitors_api.
5 6 7 |
# File 'lib/datadog_exporter/datadog_api_requests/monitors.rb', line 5 def monitors_api @monitors_api end |
Instance Method Details
#create(monitor_hash) ⇒ Integer
Creates a monitor in Datadog
49 50 51 52 53 |
# File 'lib/datadog_exporter/datadog_api_requests/monitors.rb', line 49 def create(monitor_hash) monitor = @monitors_api.create_monitor(monitor_hash) monitor.id end |
#find(monitor_id) ⇒ Hash
Returns a Datadog monitor configuration.
38 39 40 41 |
# File 'lib/datadog_exporter/datadog_api_requests/monitors.rb', line 38 def find(monitor_id) monitor = @monitors_api.get_monitor(monitor_id) monitor.to_hash end |
#list_monitors(tag: nil) ⇒ Array<Hash>
Returns a list of Hashes containing Datadog monitor configuration. If no tag is provided, it returns all the monitors.
23 24 25 26 27 28 29 30 |
# File 'lib/datadog_exporter/datadog_api_requests/monitors.rb', line 23 def list_monitors(tag: nil) monitors = @monitors_api .list_monitors # NOTE: Unfortunately, the filter provided by the API is not working https://github.com/DataDog/datadog-api-client-ruby/issues/2063 .select { |monitor| tag.nil? || monitor..include?(tag) } monitors.map(&:to_hash) end |