dogapi 1.37.1 → 1.38.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,3 +17,7 @@ require 'dogapi/v1/user'
17
17
  require 'dogapi/v1/hosts'
18
18
  require 'dogapi/v1/integration'
19
19
  require 'dogapi/v1/usage'
20
+ require 'dogapi/v1/aws_integration'
21
+ require 'dogapi/v1/aws_logs'
22
+ require 'dogapi/v1/azure_integration'
23
+ require 'dogapi/v1/gcp_integration'
@@ -0,0 +1,113 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1 # for namespacing
5
+
6
+ # AwsIntegrationService for user interaction with AWS configs.
7
+ class AwsIntegrationService < Dogapi::APIService
8
+
9
+ API_VERSION = 'v1'
10
+
11
+ # Retrieve AWS integration information
12
+ def aws_integration_list
13
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws", nil, nil, false)
14
+ end
15
+
16
+ # Create an AWS integration
17
+ # :config => Hash: integration config.
18
+ # config = {
19
+ # :account_id => '<AWS_ACCOUNT>',
20
+ # :host_tags => ['api:example'],
21
+ # :role_name => '<AWS_ROLE_NAME>'
22
+ # }
23
+ #
24
+ # Access Key/Secret Access Key based accounts (GovCloud and China only)
25
+ #
26
+ # config = {
27
+ # :access_key_id => '<AWS_ACCESS_KEY_ID>',
28
+ # :host_tags => ['api:example'],
29
+ # :secret_access_key => '<AWS_SECRET_ACCESS_KEY>'
30
+ # }
31
+ #
32
+ # dog = Dogapi::Client.new(api_key, app_key)
33
+ #
34
+ # puts dog.aws_integration_create(config)
35
+ def aws_integration_create(config)
36
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws", nil, config, true)
37
+ end
38
+
39
+ # Delete an integration
40
+ # :config => Hash: integration config.
41
+ # config = {
42
+ # :account_id => '<AWS_ACCOUNT>',
43
+ # :role_name => '<AWS_ROLE_NAME>'
44
+ # }
45
+ # Access Key/Secret Access Key based accounts (GovCloud and China only)
46
+ #
47
+ # config = {
48
+ # :access_key_id => '<AWS_ACCESS_KEY_ID>',
49
+ # }
50
+ #
51
+ # dog = Dogapi::Client.new(api_key, app_key)
52
+ #
53
+ # puts dog.aws_integration_delete(config)
54
+ def aws_integration_delete(config)
55
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/integration/aws", nil, config, true)
56
+ end
57
+
58
+ # List available AWS namespaces
59
+ def aws_integration_list_namespaces
60
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws/available_namespace_rules", nil, nil, false)
61
+ end
62
+
63
+ # Generate new AWS external ID for a specific integrated account
64
+ # :config => Hash: integration config.
65
+ # config = {
66
+ # :account_id => '<AWS_ACCOUNT>',
67
+ # :role_name => '<AWS_ROLE_NAME>'
68
+ # }
69
+ #
70
+ # dog = Dogapi::Client.new(api_key, app_key)
71
+ #
72
+ # puts dog.aws_integration_generate_external_id(config)
73
+ def aws_integration_generate_external_id(config)
74
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/integration/aws/generate_new_external_id", nil, config, true)
75
+ end
76
+
77
+ # Update integrated AWS account.
78
+ # :config => Hash: integration config.
79
+ # config = {
80
+ # "account_id": '<EXISTING_AWS_ACCOUNT>',
81
+ # "role_name": '<EXISTING_AWS_ROLE_NAME>'
82
+ # }
83
+ #
84
+ # new_config = {
85
+ # "account_id": '<NEW_AWS_ACCOUNT>',
86
+ # "host_tags": ['tag:example1,tag:example2'],
87
+ # "filter_tags": ['datadog:true']
88
+ # }
89
+ #
90
+ # Access Key/Secret Access Key based accounts (GovCloud and China only)
91
+ #
92
+ # config = {
93
+ # "access_key_id": '<EXISTING_ACCESS_KEY_ID>',
94
+ # "secret_access_key": '<EXISTING_SECRET_ACCESS_KEY>'
95
+ # }
96
+ #
97
+ # new_config = {
98
+ # "access_key_id": '<NEW_ACCESS_KEY_ID>',
99
+ # "host_tags": ['new:tags'],
100
+ # "filter_tags": ['datadog:true']
101
+ # }
102
+ #
103
+ # dog = Dogapi::Client.new(api_key, app_key)
104
+
105
+ # puts dog.aws_integration_update(config, new_config)
106
+ def aws_integration_update(config, new_config)
107
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/integration/aws", config, new_config, true)
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,103 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1 # for namespacing
5
+
6
+ # AwsLogsService for user interaction with AWS configs.
7
+ class AwsLogsService < Dogapi::APIService
8
+
9
+ API_VERSION = 'v1'
10
+
11
+ # Get the list of current AWS services for which Datadog offers automatic log collection.
12
+ # Use returned service IDs with the services parameter for the Enable
13
+ # an AWS service log collection API endpoint.
14
+ def aws_logs_list_services
15
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws/logs/services", nil, nil, false)
16
+ end
17
+
18
+ # Create an AWS integration
19
+ # :config => Hash: integration config.
20
+ # config = {
21
+ # :account_id => '<AWS_ACCOUNT>',
22
+ # :lambda_arn => '<LAMBDA_ARN>'
23
+ # }
24
+ #
25
+ # dog = Dogapi::Client.new(api_key, app_key)
26
+ #
27
+ # puts dog.aws_logs_add_lambda(config)
28
+ def aws_logs_add_lambda(config)
29
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs", nil, config, true)
30
+ end
31
+
32
+ # List all Datadog-AWS Logs integrations configured in your Datadog account.
33
+ def aws_logs_integrations_list
34
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws/logs", nil, nil, false)
35
+ end
36
+
37
+ # Enable automatic log collection for a list of services.
38
+ # This should be run after running 'aws_logs_add_lambda' to save the config.
39
+ # config = {
40
+ # :account_id => '<AWS_ACCOUNT>',
41
+ # :services => ['s3', 'elb', 'elbv2', 'cloudfront', 'redshift', 'lambda']
42
+ # }
43
+ #
44
+ # dog = Dogapi::Client.new(api_key, app_key)
45
+ #
46
+ # puts dog.aws_logs_save_services(config)
47
+ def aws_logs_save_services(config)
48
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs/services", nil, config, true)
49
+ end
50
+
51
+ # Delete an AWS Logs integration
52
+ # :config => Hash: integration config.
53
+ # config = {
54
+ # :account_id => '<AWS_ACCOUNT>',
55
+ # :lambda_arn => '<LAMBDA_ARN>'
56
+ # }
57
+ #
58
+ # dog = Dogapi::Client.new(api_key, app_key)
59
+ #
60
+ # puts dog.aws_logs_integration_delete(config)
61
+ def aws_logs_integration_delete(config)
62
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/integration/aws/logs", nil, config, true)
63
+ end
64
+
65
+ # Check function to see if a lambda_arn exists within an account.
66
+ # This sends a job on our side if it does not exist, then immediately returns
67
+ # the status of that job. Subsequent requests will always repeat the above, so this endpoint
68
+ # can be polled intermittently instead of blocking.
69
+
70
+ # Returns a status of 'created' when it's checking if the Lambda exists in the account.
71
+ # Returns a status of 'waiting' while checking.
72
+ # Returns a status of 'checked and ok' if the Lambda exists.
73
+ # Returns a status of 'error' if the Lambda does not exist.
74
+
75
+ # contents of config should be
76
+ # >>> :account_id => '<AWS_ACCOUNT_ID>'
77
+ # >>> :lambda_arn => '<AWS_LAMBDA_ARN>'
78
+
79
+ def aws_logs_check_lambda(config)
80
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs/check_async", nil, config, true)
81
+ end
82
+
83
+ # Test if permissions are present to add log-forwarding triggers for the
84
+ # given services + AWS account. Input is the same as for save_services.
85
+ # Done async, so can be repeatedly polled in a non-blocking fashion until
86
+ # the async request completes
87
+
88
+ # Returns a status of 'created' when it's checking if the permissions exists in the AWS account.
89
+ # Returns a status of 'waiting' while checking.
90
+ # Returns a status of 'checked and ok' if the Lambda exists.
91
+ # Returns a status of 'error' if the Lambda does not exist.
92
+
93
+ # contents of config should be
94
+ # :account_id => '<AWS_ACCOUNT_ID>'
95
+ # :services => ['s3', 'elb', 'elbv2', 'cloudfront', 'redshift', 'lambda']
96
+ def aws_logs_check_services(config)
97
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs/services_async", nil, config, true)
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,81 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1 # for namespacing
5
+
6
+ # AzureIntegrationService for user interaction with Azure configs.
7
+ class AzureIntegrationService < Dogapi::APIService
8
+
9
+ API_VERSION = 'v1'
10
+
11
+ # Retrieve Azure integration information
12
+ def azure_integration_list
13
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/azure", nil, nil, false)
14
+ end
15
+
16
+ # Delete an Azure integration
17
+ # :config => Hash: integration config.
18
+ # config = {
19
+ # :tenant_name => '<TENANT_NAME>',
20
+ # :client_id => '<CLIENT_ID>'
21
+ # }
22
+ #
23
+ # dog = Dogapi::Client.new(api_key, app_key)
24
+ #
25
+ # puts dog.azure_integration_delete(config)
26
+ def azure_integration_delete(config)
27
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/integration/azure", nil, config, true)
28
+ end
29
+
30
+ # Create an Azure integration
31
+ # :config => Hash: integration config.
32
+ # config = {
33
+ # :tenant_name => '<TENANT_NAME>',
34
+ # :host_filters => 'new:filter',
35
+ # :client_id => '<CLIENT_ID>',
36
+ # :client_secret => '<CLIENT_SECRET>'
37
+ # }
38
+ #
39
+ # dog = Dogapi::Client.new(api_key, app_key)
40
+ #
41
+ # puts dog.azure_integration_create(config)
42
+ def azure_integration_create(config)
43
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/azure", nil, config, true)
44
+ end
45
+
46
+ # Update an Azure integrations host filters
47
+ # :config => Hash: integration config.
48
+ # config = {
49
+ # :tenant_name => '<TENANT_NAME>',
50
+ # :host_filters => 'new:filter',
51
+ # :client_id => '<CLIENT_ID>'
52
+ # }
53
+ #
54
+ # dog = Dogapi::Client.new(api_key, app_key)
55
+ #
56
+ # puts dog.azure_integration_update_host_filters(config)
57
+ def azure_integration_update_host_filters(config)
58
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/azure/host_filters", nil, config, true)
59
+ end
60
+
61
+ # Update a configured Azure account.
62
+ # :config => Hash: integration config.
63
+ # config = {
64
+ # :tenant_name => '<TENANT_NAME>',
65
+ # :new_tenant_name => '<NEW_TENANT_NAME>',
66
+ # :host_filters => '<KEY>:<VALUE>,<KEY>:<VALUE>',
67
+ # :client_id => '<CLIENT_ID>',
68
+ # :new_client_id => '<NEW_CLIENT_ID>'
69
+ # }
70
+ #
71
+ # dog = Dogapi::Client.new(api_key, app_key)
72
+ #
73
+ # puts dog.azure_integration_update(config)
74
+ def azure_integration_update(config)
75
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/integration/azure", nil, config, true)
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,72 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1 # for namespacing
5
+
6
+ # GcpIntegrationService for user interaction with gcp configs.
7
+ class GcpIntegrationService < Dogapi::APIService
8
+
9
+ API_VERSION = 'v1'
10
+
11
+ # Retrieve gcp integration information
12
+ def gcp_integration_list
13
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/gcp", nil, nil, false)
14
+ end
15
+
16
+ # Delete an gcp integration
17
+ # :config => Hash: integration config.
18
+ # config = {
19
+ # :project_id => 'datadog-sandbox',
20
+ # :client_email => 'email@example.com'
21
+ # }
22
+ #
23
+ # dog = Dogapi::Client.new(api_key, app_key)
24
+ #
25
+ # puts dog.gcp_integration_delete(config)
26
+ def gcp_integration_delete(config)
27
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/integration/gcp", nil, config, true)
28
+ end
29
+
30
+ # Create an gcp integration
31
+ # :config => Hash: integration config.
32
+ # config = {
33
+ # :type => 'service_account',
34
+ # :project_id => '<PROJECT_ID>',
35
+ # :private_key_id => '<PRIVATE_KEY_ID>',
36
+ # :private_key => '<PRIVATE_KEY>',
37
+ # :client_email => '<CLIENT_EMAIL>',
38
+ # :client_id => '<CLIENT_ID>',
39
+ # :auth_uri => '<AUTH_URI>',
40
+ # :token_uri => '<TOKEN_URI>',
41
+ # :auth_provider_x509_cert_url => '<AUTH_PROVIDER_X509_CERT_URL>',
42
+ # :client_x509_cert_url => '<CLIENT_X509_CERT_URL>',
43
+ # :host_filters => '<KEY>:<VALUE>,<KEY>:<VALUE>,'
44
+ # }
45
+ #
46
+ # dog = Dogapi::Client.new(api_key, app_key)
47
+ #
48
+ # puts dog.gcp_integration_create(config)
49
+ def gcp_integration_create(config)
50
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/gcp", nil, config, true)
51
+ end
52
+
53
+ # Update a configured gcp account.
54
+ # :config => Hash: integration config.
55
+ # config = {
56
+ # :project_id => '<PROJECT_ID>',
57
+ # :client_email => '<CLIENT_EMAIL>',
58
+ # :host_filters => '<KEY>:<VALUE>,<KEY>:<VALUE>,'
59
+ # :automute => true # takes a boolean and toggles GCE automuting
60
+ # }
61
+ #
62
+ # dog = Dogapi::Client.new(api_key, app_key)
63
+ #
64
+ # puts dog.gcp_integration_update(config)
65
+ def gcp_integration_update(config)
66
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/integration/gcp", nil, config, true)
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
@@ -2,9 +2,7 @@ require 'dogapi'
2
2
 
3
3
  module Dogapi
4
4
  class V1 # for namespacing
5
-
6
5
  class MonitorService < Dogapi::APIService
7
-
8
6
  API_VERSION = 'v1'
9
7
 
10
8
  def monitor(type, query, options = {})
@@ -42,6 +40,17 @@ module Dogapi
42
40
  request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", extra_params, nil, false)
43
41
  end
44
42
 
43
+ def can_delete_monitors(monitor_ids)
44
+ extra_params =
45
+ if monitor_ids.respond_to?(:join)
46
+ { "monitor_ids" => monitor_ids.join(",") }
47
+ else
48
+ { "monitor_ids" => monitor_ids }
49
+ end
50
+
51
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/can_delete", extra_params, nil, false)
52
+ end
53
+
45
54
  def delete_monitor(monitor_id)
46
55
  request(Net::HTTP::Delete, "/api/#{API_VERSION}/monitor/#{monitor_id}", nil, nil, false)
47
56
  end
@@ -122,8 +131,8 @@ module Dogapi
122
131
  request(Net::HTTP::Put, "/api/#{API_VERSION}/downtime/#{downtime_id}", nil, options, true)
123
132
  end
124
133
 
125
- def get_downtime(downtime_id)
126
- request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime/#{downtime_id}", nil, nil, false)
134
+ def get_downtime(downtime_id, options = {})
135
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime/#{downtime_id}", options, nil, false)
127
136
  end
128
137
 
129
138
  def cancel_downtime(downtime_id)
@@ -131,7 +140,7 @@ module Dogapi
131
140
  end
132
141
 
133
142
  def cancel_downtime_by_scope(scope)
134
- request(Net::HTTP::Post, "/api/#{API_VERSION}/downtime/cancel/by_scope", nil, { 'scope' => scope }, false)
143
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/downtime/cancel/by_scope", nil, { 'scope' => scope }, true)
135
144
  end
136
145
 
137
146
  def get_all_downtimes(options = {})
@@ -1,3 +1,3 @@
1
1
  module Dogapi
2
- VERSION = '1.37.1'
2
+ VERSION = '1.38.0'
3
3
  end
@@ -0,0 +1,51 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Dogapi::Client do
4
+ CONFIG = {
5
+ account_id: '123456789101',
6
+ role_name: 'DatadogApiTestRole'
7
+ }.freeze
8
+
9
+ UPDATE_CONFIG = {
10
+ account_id: '123456789102',
11
+ filter_tags: ['datadog:true'],
12
+ host_tags: ['api:test'],
13
+ role_name: 'DatadogApiTestRole'
14
+ }.freeze
15
+
16
+ describe '#aws_integration_create' do
17
+ it_behaves_like 'an api method',
18
+ :aws_integration_create, [CONFIG],
19
+ :post, '/integration/aws', CONFIG
20
+ end
21
+
22
+ describe '#aws_integration_list' do
23
+ it_behaves_like 'an api method',
24
+ :aws_integration_list, nil,
25
+ :get, '/integration/aws'
26
+ end
27
+
28
+ describe '#aws_integration_list_namespaces' do
29
+ it_behaves_like 'an api method',
30
+ :aws_integration_list_namespaces, nil,
31
+ :get, '/integration/aws/available_namespace_rules'
32
+ end
33
+
34
+ describe '#aws_integration_generate_external_id' do
35
+ it_behaves_like 'an api method',
36
+ :aws_integration_generate_external_id, [CONFIG],
37
+ :put, '/integration/aws/generate_new_external_id', CONFIG
38
+ end
39
+
40
+ describe '#aws_integration_update' do
41
+ it_behaves_like 'an api method with params and body',
42
+ :aws_integration_update, [CONFIG, UPDATE_CONFIG],
43
+ :put, '/integration/aws', CONFIG, UPDATE_CONFIG
44
+ end
45
+
46
+ describe '#aws_integration_delete' do
47
+ it_behaves_like 'an api method',
48
+ :aws_integration_delete, [CONFIG],
49
+ :delete, '/integration/aws', CONFIG
50
+ end
51
+ end