Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getRegion into AWSResource #43

Merged
merged 2 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ static GetLogEventsRequest createGetLogEventRequest(String logGroupName, String
return getLogEventsRequest;
}

public ArrayList<String> getGroupNameList(String region) {
public ArrayList<String> getLogGroupNames(String region) {

ArrayList<String> groupNameList = new ArrayList<>();
ArrayList<String> logGroupNames = new ArrayList<>();
// TODO optimize this
Iterator<DescribeLogGroupsResponse> logGroupsIterator = CloudWatchService.createCloudWatchLogClient(region).describeLogGroupsPaginator().iterator();
DescribeLogGroupsResponse response = logGroupsIterator.next();
for (int c = 0; c < response.logGroups().size(); c++) {
response.logGroups().get(c).logGroupName();
groupNameList.add(response.logGroups().get(c).logGroupName());
logGroupNames.add(response.logGroups().get(c).logGroupName());
}
return groupNameList;
return logGroupNames;
}

static ArrayList<String> getStreamNameList(CloudWatchLogsClient cloudWatchLogsClient, String logGroupName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ public List<String> getKinesisStreams(String regionName, String accessKeyId, Str
return streamNames;
}

// TODO Create Kinesis Stream

// TODO Subscribe to Kinesis Stream

// TODO getRecord

}
40 changes: 1 addition & 39 deletions src/main/java/org/graylog/integrations/aws/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient;
import software.amazon.awssdk.services.cloudwatchlogs.model.FilterLogEventsRequest;
import software.amazon.awssdk.services.cloudwatchlogs.model.GetLogEventsRequest;
import software.amazon.awssdk.services.kinesis.KinesisClient;
import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
import software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest;

import java.util.ArrayList;

Expand All @@ -15,16 +12,14 @@ public static void main(String[] args) {
boolean fromStart = true;

// CONFIGURATION

String region = "us-east-1";


// CLOUDWATCH
CloudWatchLogsClient cloudWatchLogsClient = CloudWatchService.createCloudWatchLogClient(region);

//Get all the logGroupName(s) available
// TODO optimize this
ArrayList<String> logGroupNameList = new CloudWatchService().getGroupNameList(region);
ArrayList<String> logGroupNameList = new CloudWatchService().getLogGroupNames(region);
String logGroupName = "/var/log/messages";

//Get all the logStreamName(s) available
Expand All @@ -36,41 +31,8 @@ public static void main(String[] args) {
FilterLogEventsRequest filterLogEventsRequest = FilterLogEventsRequest.builder()
.logGroupName(logGroupName)
.logStreamNames(logStreamNameList)
//logStreamNames(String... var1);
//startTime(Long var1);
//endTime(Long var1);
//filterPattern(String var1);
//nextToken(String var1);
//limit(Integer var1);
.interleaved(false) //false produces more logs
.build();

// cloudWatchLogsClient.filterLogEvents(filterLogEventsRequest);
// cloudWatchLogsClient.getLogEventsPaginator(getLogEventsRequest).iterator();

logGroupNameList.iterator();

// Set next token
String nextToken = cloudWatchLogsClient.getLogEvents(getLogEventsRequest).nextForwardToken();

KinesisClient kinesisClient = KinesisService.getKinesisClient();
kinesisClient.describeLimits();
SubscribeToShardRequest subscribeToShardRequest = SubscribeToShardRequest.builder().shardId("shardID").build();
GetRecordsRequest getRecordsRequest = GetRecordsRequest.builder().shardIterator("somethingGoesHere?").build();

String shardIterator;
// GetShardIteratorRequest getShardIteratorRequest = new GetShardIteratorRequest(); //GetShardIteratorRequest();
// getShardIteratorRequest.setStreamName(myStreamName);
// getShardIteratorRequest.setShardId(shard.getShardId());
// getShardIteratorRequest.setShardIteratorType("TRIM_HORIZON");

//GetShardIteratorResult getShardIteratorResult = client.getShardIterator(getShardIteratorRequest);
// shardIterator = getShardIteratorResult.getShardIterator();

// TODO resolve nextToken issue
// Designate getLogEventsRequest from LAST REQUEST
//cloudWatchLogsClient.getLogEvents(logEventObject02);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.graylog.integrations.aws.KinesisService;
import org.graylog.integrations.aws.resources.requests.KinesisHealthCheckRequest;
import org.graylog.integrations.aws.resources.responses.KinesisHealthCheckResponse;
import org.graylog.integrations.aws.resources.responses.RegionResponse;
import org.graylog.integrations.aws.service.AWSService;
import org.graylog2.plugin.rest.PluginRestResource;

Expand All @@ -31,8 +32,8 @@
*/

@RequiresAuthentication
@Api(value = "System/AWS", description = "AWS integrations")
@Path("/system/aws")
@Api(value = "AWS", description = "AWS integrations")
@Path("/aws")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class AWSResource implements PluginRestResource {
Expand All @@ -48,30 +49,42 @@ public AWSResource(AWSService awsService, KinesisService kinesisService, CloudWa
this.cloudWatchService = cloudWatchService;
}

// GET AWS regions
@GET
@Timed
@Path("/Cloudwatch/{regionName}")
@Path("/regions")
@ApiOperation(value = "Get all available AWS regions")
public List<RegionResponse> getAwsRegions() {
return awsService.getAvailableRegions();
}

// GET CloudWatch log group names
@GET
@Timed
@Path("/cloudWatch/logGroups/{regionName}")
@ApiOperation(value = "Get all available AWS CloudWatch log groups names for the specified region")
public List<String> getLogGroupNames(@ApiParam(name = "regionName", required = true)
@PathParam("regionName") String regionName) {

return cloudWatchService.getGroupNameList(regionName);
return cloudWatchService.getLogGroupNames(regionName);
}

// GET Kinesis Streams
// TODO: Rework to accept a form post body with credentials
@GET
@Timed
@Path("/kinesisStreams/{regionName}")
@Path("/kinesis/streams/{regionName}")
@ApiOperation(value = "Get all available AWS Kinesis streams for the specified region")
public List<String> getKinesisStreams(@ApiParam(name = "regionName", required = true)
@PathParam("regionName") String regionName) throws ExecutionException {

return kinesisService.getKinesisStreams(regionName, null, null);
}

// PUT Kinesis Health Check
@PUT
@Timed
@Path("/kinesisHealthCheck")
@Path("/kinesis/healthCheck")
@ApiOperation(
value = "Attempt to retrieve logs from the indicated AWS log group with the specified credentials.",
response = KinesisHealthCheckResponse.class
Expand All @@ -85,4 +98,7 @@ public Response kinesisHealthCheck(@ApiParam(name = "JSON body", required = true

return Response.accepted().entity(response).build();
}

// TODO GET kinesisAutomatedSetup
// getRegion, getlogGroupNames, subscribeToStream
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ public List<RegionResponse> getAvailableRegions() {
}).collect(Collectors.toList());
}

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

// TODO GET getUserCredentials

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ public void setUp() {
kinesisService = new KinesisService(kinesisClientBuilder);
}

@Test
public void name() {

Main.main(null);
}

@Test
public void testLogIdentification() {

Expand Down