Module: Dogapi

Defined in:
lib/dogapi/v1/tag.rb,
lib/dogapi/event.rb,
lib/dogapi/common.rb,
lib/dogapi/facade.rb,
lib/dogapi/metric.rb,
lib/dogapi/v1/dash.rb,
lib/dogapi/v1/user.rb,
lib/dogapi/version.rb,
lib/dogapi/v1/alert.rb,
lib/dogapi/v1/embed.rb,
lib/dogapi/v1/event.rb,
lib/dogapi/v1/hosts.rb,
lib/dogapi/v1/usage.rb,
lib/dogapi/v1/metric.rb,
lib/dogapi/v1/search.rb,
lib/dogapi/v1/comment.rb,
lib/dogapi/v1/monitor.rb,
lib/dogapi/v1/aws_logs.rb,
lib/dogapi/v1/metadata.rb,
lib/dogapi/v1/snapshot.rb,
lib/dogapi/v1/dashboard.rb,
lib/dogapi/v1/synthetics.rb,
lib/dogapi/v1/integration.rb,
lib/dogapi/v1/screenboard.rb,
lib/dogapi/v1/logs_pipeline.rb,
lib/dogapi/v1/service_check.rb,
lib/dogapi/v1/dashboard_list.rb,
lib/dogapi/v2/dashboard_list.rb,
lib/dogapi/v1/aws_integration.rb,
lib/dogapi/v1/gcp_integration.rb,
lib/dogapi/v1/azure_integration.rb,
lib/dogapi/v1/service_level_objective.rb

Overview

Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License. This product includes software developed at Datadog (www.datadoghq.com/). Copyright 2011-Present Datadog, Inc.

Defined Under Namespace

Classes: APIService, Client, ClientV2, Event, EventService, MetricService, Scope, Service, V1, V2

Constant Summary collapse

USER_AGENT =
format(
  'dogapi-rb/%<version>s (ruby %<ruver>s; os %<os>s; arch %<arch>s)',
  version: VERSION,
  ruver: RUBY_VERSION,
  os: RbConfig::CONFIG['host_os'].downcase,
  arch: RbConfig::CONFIG['host_cpu']
)
VERSION =
'1.45.0'
@@hostname =

Memoize the hostname as a module variable

nil

Class Method Summary collapse

Class Method Details

.find_datadog_hostObject



208
209
210
211
# File 'lib/dogapi/common.rb', line 208

def Dogapi.find_datadog_host
  # allow env-based overriding, useful for tests
  ENV['DATADOG_HOST'] || 'https://api.datadoghq.com'
end

.find_localhostObject



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/dogapi/common.rb', line 216

def Dogapi.find_localhost
  return @@hostname if @@hostname
  out, status = Open3.capture2('hostname', '-f', err: File::NULL)
  unless status.exitstatus.zero?
    begin
      out = Addrinfo.getaddrinfo(Socket.gethostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first.canonname
    rescue SocketError
      out, status = Open3.capture2('hostname', err: File::NULL)
      raise SystemCallError, 'Both `hostname` and `hostname -f` failed.' unless status.exitstatus.zero?
    end
  end
  @@hostname = out.strip
end

.find_proxyObject



230
231
232
233
234
# File 'lib/dogapi/common.rb', line 230

def Dogapi.find_proxy
  ENV['DD_PROXY_HTTPS'] || ENV['dd_proxy_https'] ||
    ENV['DD_PROXY_HTTP'] || ENV['dd_proxy_http'] ||
    ENV['HTTPS_PROXY'] || ENV['https_proxy'] || ENV['HTTP_PROXY'] || ENV['http_proxy']
end

.symbolized_access(hash) ⇒ Object

Very simplified hash with indifferent access - access to string or symbol keys via symbols. E.g.: my_hash = { ‘foo’ => 1 } Dogapi.symbolized_access(my_hash) my_hash # => 1



250
251
252
253
# File 'lib/dogapi/common.rb', line 250

def Dogapi.symbolized_access(hash)
  hash.default_proc = proc { |h, k| h.key?(k.to_s) ? h[k.to_s] : nil }
  hash
end

.validate_tags(tags) ⇒ Object



236
237
238
239
240
241
242
243
# File 'lib/dogapi/common.rb', line 236

def Dogapi.validate_tags(tags)
  unless tags.is_a? Array
    raise ArgumentError, "The tags parameter needs to be an array of string. Current value: #{tags}"
  end
  tags.each do |tag|
    raise ArgumentError, "Each tag needs to be a string. Current value: #{tag}" unless tag.is_a? String
  end
end