-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ruby cloud integration support (#201)
- Loading branch information
1 parent
109f11c
commit b65a476
Showing
11 changed files
with
716 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
require 'dogapi' | ||
|
||
module Dogapi | ||
class V1 # for namespacing | ||
|
||
# AwsIntegrationService for user interaction with AWS configs. | ||
class AwsIntegrationService < Dogapi::APIService | ||
|
||
API_VERSION = 'v1' | ||
|
||
# Retrieve AWS integration information | ||
def aws_integration_list | ||
request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws", nil, nil, false) | ||
end | ||
|
||
# Create an AWS integration | ||
# :config => Hash: integration config. | ||
# config = { | ||
# :account_id => '<AWS_ACCOUNT>', | ||
# :host_tags => ['api:example'], | ||
# :role_name => '<AWS_ROLE_NAME>' | ||
# } | ||
# | ||
# Access Key/Secret Access Key based accounts (GovCloud and China only) | ||
# | ||
# config = { | ||
# :access_key_id => '<AWS_ACCESS_KEY_ID>', | ||
# :host_tags => ['api:example'], | ||
# :secret_access_key => '<AWS_SECRET_ACCESS_KEY>' | ||
# } | ||
# | ||
# dog = Dogapi::Client.new(api_key, app_key) | ||
# | ||
# puts dog.aws_integration_create(config) | ||
def aws_integration_create(config) | ||
request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws", nil, config, true) | ||
end | ||
|
||
# Delete an integration | ||
# :config => Hash: integration config. | ||
# config = { | ||
# :account_id => '<AWS_ACCOUNT>', | ||
# :role_name => '<AWS_ROLE_NAME>' | ||
# } | ||
# Access Key/Secret Access Key based accounts (GovCloud and China only) | ||
# | ||
# config = { | ||
# :access_key_id => '<AWS_ACCESS_KEY_ID>', | ||
# } | ||
# | ||
# dog = Dogapi::Client.new(api_key, app_key) | ||
# | ||
# puts dog.aws_integration_delete(config) | ||
def aws_integration_delete(config) | ||
request(Net::HTTP::Delete, "/api/#{API_VERSION}/integration/aws", nil, config, true) | ||
end | ||
|
||
# List available AWS namespaces | ||
def aws_integration_list_namespaces | ||
request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws/available_namespace_rules", nil, nil, false) | ||
end | ||
|
||
# Generate new AWS external ID for a specific integrated account | ||
# :config => Hash: integration config. | ||
# config = { | ||
# :account_id => '<AWS_ACCOUNT>', | ||
# :role_name => '<AWS_ROLE_NAME>' | ||
# } | ||
# | ||
# dog = Dogapi::Client.new(api_key, app_key) | ||
# | ||
# puts dog.aws_integration_generate_external_id(config) | ||
def aws_integration_generate_external_id(config) | ||
request(Net::HTTP::Put, "/api/#{API_VERSION}/integration/aws/generate_new_external_id", nil, config, true) | ||
end | ||
|
||
# Update integrated AWS account. | ||
# :config => Hash: integration config. | ||
# config = { | ||
# "account_id": '<EXISTING_AWS_ACCOUNT>', | ||
# "role_name": '<EXISTING_AWS_ROLE_NAME>' | ||
# } | ||
# | ||
# new_config = { | ||
# "account_id": '<NEW_AWS_ACCOUNT>', | ||
# "host_tags": ['tag:example1,tag:example2'], | ||
# "filter_tags": ['datadog:true'] | ||
# } | ||
# | ||
# Access Key/Secret Access Key based accounts (GovCloud and China only) | ||
# | ||
# config = { | ||
# "access_key_id": '<EXISTING_ACCESS_KEY_ID>', | ||
# "secret_access_key": '<EXISTING_SECRET_ACCESS_KEY>' | ||
# } | ||
# | ||
# new_config = { | ||
# "access_key_id": '<NEW_ACCESS_KEY_ID>', | ||
# "host_tags": ['new:tags'], | ||
# "filter_tags": ['datadog:true'] | ||
# } | ||
# | ||
# dog = Dogapi::Client.new(api_key, app_key) | ||
|
||
# puts dog.aws_integration_update(config, new_config) | ||
def aws_integration_update(config, new_config) | ||
request(Net::HTTP::Put, "/api/#{API_VERSION}/integration/aws", config, new_config, true) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
require 'dogapi' | ||
|
||
module Dogapi | ||
class V1 # for namespacing | ||
|
||
# AwsLogsService for user interaction with AWS configs. | ||
class AwsLogsService < Dogapi::APIService | ||
|
||
API_VERSION = 'v1' | ||
|
||
# Get the list of current AWS services for which Datadog offers automatic log collection. | ||
# Use returned service IDs with the services parameter for the Enable | ||
# an AWS service log collection API endpoint. | ||
def aws_logs_list_services | ||
request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws/logs/services", nil, nil, false) | ||
end | ||
|
||
# Create an AWS integration | ||
# :config => Hash: integration config. | ||
# config = { | ||
# :account_id => '<AWS_ACCOUNT>', | ||
# :lambda_arn => '<LAMBDA_ARN>' | ||
# } | ||
# | ||
# dog = Dogapi::Client.new(api_key, app_key) | ||
# | ||
# puts dog.aws_logs_add_lambda(config) | ||
def aws_logs_add_lambda(config) | ||
request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs", nil, config, true) | ||
end | ||
|
||
# List all Datadog-AWS Logs integrations configured in your Datadog account. | ||
def aws_logs_integrations_list | ||
request(Net::HTTP::Get, "/api/#{API_VERSION}/integration/aws/logs", nil, nil, false) | ||
end | ||
|
||
# Enable automatic log collection for a list of services. | ||
# This should be run after running 'aws_logs_add_lambda' to save the config. | ||
# config = { | ||
# :account_id => '<AWS_ACCOUNT>', | ||
# :services => ['s3', 'elb', 'elbv2', 'cloudfront', 'redshift', 'lambda'] | ||
# } | ||
# | ||
# dog = Dogapi::Client.new(api_key, app_key) | ||
# | ||
# puts dog.aws_logs_save_services(config) | ||
def aws_logs_save_services(config) | ||
request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs/services", nil, config, true) | ||
end | ||
|
||
# Delete an AWS Logs integration | ||
# :config => Hash: integration config. | ||
# config = { | ||
# :account_id => '<AWS_ACCOUNT>', | ||
# :lambda_arn => '<LAMBDA_ARN>' | ||
# } | ||
# | ||
# dog = Dogapi::Client.new(api_key, app_key) | ||
# | ||
# puts dog.aws_logs_integration_delete(config) | ||
def aws_logs_integration_delete(config) | ||
request(Net::HTTP::Delete, "/api/#{API_VERSION}/integration/aws/logs", nil, config, true) | ||
end | ||
|
||
# Check function to see if a lambda_arn exists within an account. | ||
# This sends a job on our side if it does not exist, then immediately returns | ||
# the status of that job. Subsequent requests will always repeat the above, so this endpoint | ||
# can be polled intermittently instead of blocking. | ||
|
||
# Returns a status of 'created' when it's checking if the Lambda exists in the account. | ||
# Returns a status of 'waiting' while checking. | ||
# Returns a status of 'checked and ok' if the Lambda exists. | ||
# Returns a status of 'error' if the Lambda does not exist. | ||
|
||
# contents of config should be | ||
# >>> :account_id => '<AWS_ACCOUNT_ID>' | ||
# >>> :lambda_arn => '<AWS_LAMBDA_ARN>' | ||
|
||
def aws_logs_check_lambda(config) | ||
request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs/check_async", nil, config, true) | ||
end | ||
|
||
# Test if permissions are present to add log-forwarding triggers for the | ||
# given services + AWS account. Input is the same as for save_services. | ||
# Done async, so can be repeatedly polled in a non-blocking fashion until | ||
# the async request completes | ||
|
||
# Returns a status of 'created' when it's checking if the permissions exists in the AWS account. | ||
# Returns a status of 'waiting' while checking. | ||
# Returns a status of 'checked and ok' if the Lambda exists. | ||
# Returns a status of 'error' if the Lambda does not exist. | ||
|
||
# contents of config should be | ||
# :account_id => '<AWS_ACCOUNT_ID>' | ||
# :services => ['s3', 'elb', 'elbv2', 'cloudfront', 'redshift', 'lambda'] | ||
def aws_logs_check_services(config) | ||
request(Net::HTTP::Post, "/api/#{API_VERSION}/integration/aws/logs/services_async", nil, config, true) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
Oops, something went wrong.