Skip to content

Commit

Permalink
Resolves #50: Add Available Services API call
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Torrey committed Jun 13, 2019
1 parent 4931756 commit 280b925
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.graylog.integrations.aws.CloudWatchService;
import org.graylog.integrations.aws.KinesisService;
import org.graylog.integrations.aws.resources.requests.KinesisHealthCheckRequest;
import org.graylog.integrations.aws.resources.responses.AvailableAWSServiceSummmary;
import org.graylog.integrations.aws.resources.responses.KinesisHealthCheckResponse;
import org.graylog.integrations.aws.resources.responses.RegionResponse;
import org.graylog.integrations.aws.service.AWSService;
Expand Down Expand Up @@ -58,6 +59,23 @@ public List<RegionResponse> getAwsRegions() {
return awsService.getAvailableRegions();
}

/**
* Performs an AWS HealthCheck
*
* Sample CURL command for executing this method. Use this to model the UI request.
* Note the --data-binary param that includes the put body JSON with region and AWS credentials.
*
* curl http://someuser:somepass@localhost:9000/api/plugins/org.graylog.integrations/aws/availableServices
*/
@GET
@Timed
@Path("/availableServices")
@ApiOperation(value = "Get all available AWS services")
public AvailableAWSServiceSummmary getAvailableServices() {

return awsService.getAvailableServices();
}

// GET CloudWatch log group names
@GET
@Timed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.graylog.integrations.aws.resources.responses;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import org.graylog.autovalue.WithBeanGetter;

@JsonAutoDetect
@AutoValue
@WithBeanGetter
public abstract class AvailableAWSService {

private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String POLICY = "policy";
private static final String HELPER_TEXT = "helper_text";
private static final String LEARN_MORE_LINK = "learn_more_link";

@JsonProperty(NAME)
public abstract String name();

@JsonProperty(DESCRIPTION)
public abstract String description();

@JsonProperty(POLICY)
public abstract String policy();

@JsonProperty(HELPER_TEXT)
public abstract String helperText();

@JsonProperty(LEARN_MORE_LINK)
public abstract String LearnMoreLink();

public static AvailableAWSService create(@JsonProperty(NAME) String name,
@JsonProperty(DESCRIPTION) String description,
@JsonProperty(POLICY) String policy,
@JsonProperty(HELPER_TEXT) String helperText,
@JsonProperty(LEARN_MORE_LINK) String LearnMoreLink) {
return new AutoValue_AvailableAWSService(name, description, policy, helperText, LearnMoreLink);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.graylog.integrations.aws.resources.responses;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import org.graylog.autovalue.WithBeanGetter;

import java.util.List;

@JsonAutoDetect
@AutoValue
@WithBeanGetter
public abstract class AvailableAWSServiceSummmary {

private static final String SERVICES = "services";
private static final String TOTAL = "total";

@JsonProperty(SERVICES)
public abstract List<AvailableAWSService> services();

@JsonProperty(TOTAL)
public abstract long total();

public static AvailableAWSServiceSummmary create(@JsonProperty(SERVICES) List<AvailableAWSService> services,
@JsonProperty(TOTAL) long total) {
return new AutoValue_AvailableAWSServiceSummmary(services, total);
}
}
50 changes: 50 additions & 0 deletions src/main/java/org/graylog/integrations/aws/service/AWSService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.graylog.integrations.aws.service;

import org.graylog.integrations.aws.resources.responses.AvailableAWSService;
import org.graylog.integrations.aws.resources.responses.AvailableAWSServiceSummmary;
import org.graylog.integrations.aws.resources.responses.RegionResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.regions.RegionMetadata;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -34,6 +37,53 @@ public List<RegionResponse> getAvailableRegions() {
}).collect(Collectors.toList());
}

/**
* @return A list of available AWS services supported by the AWS Graylog AWS integration.
*/
public AvailableAWSServiceSummmary getAvailableServices() {

ArrayList<AvailableAWSService> services = new ArrayList<>();
AvailableAWSService cloudWatchService =
AvailableAWSService.create("CloudWatch",
"Retrieve CloudWatch logs via Kinesis. Kinesis allows streaming of the logs" +
"in real time. Amazon CloudWatch is a monitoring and management service built" +
"for developers, system operators, site reliability engineers (SRE), " +
"and IT managers.",
"{\n" +
" \"Version\": \"2012-10-17\",\n" +
" \"Statement\": [\n" +
" {\n" +
" \"Sid\": \"VisualEditor0\",\n" +
" \"Effect\": \"Allow\",\n" +
" \"Action\": [\n" +
" \"cloudwatch:PutMetricData\",\n" +
" \"dynamodb:CreateTable\",\n" +
" \"dynamodb:DescribeTable\",\n" +
" \"dynamodb:GetItem\",\n" +
" \"dynamodb:PutItem\",\n" +
" \"dynamodb:Scan\",\n" +
" \"dynamodb:UpdateItem\",\n" +
" \"ec2:DescribeInstances\",\n" +
" \"ec2:DescribeNetworkInterfaceAttribute\",\n" +
" \"ec2:DescribeNetworkInterfaces\",\n" +
" \"elasticloadbalancing:DescribeLoadBalancerAttributes\",\n" +
" \"elasticloadbalancing:DescribeLoadBalancers\",\n" +
" \"kinesis:GetRecords\",\n" +
" \"kinesis:GetShardIterator\",\n" +
" \"kinesis:ListShards\"\n" +
" ],\n" +
" \"Resource\": \"*\"\n" +
" }\n" +
" ]\n" +
"}",
"Requires Kinesis",
"https://aws.amazon.com/cloudwatch/"
);
services.add(cloudWatchService);

return AvailableAWSServiceSummmary.create(services, services.size());
}

//TODO Add getAWSServices List
//List that contains all the supported AWS services (i.e. Cloudwatch, Kinesis)

Expand Down

0 comments on commit 280b925

Please sign in to comment.