Authored by xuhui

亚马逊接口

恶意ip aws地址更改
... ... @@ -132,7 +132,11 @@
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-autoscaling</artifactId>
<version>1.11.31</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
... ... @@ -17,7 +17,7 @@ public class AWSClientComp {
public AmazonEC2 getClient() {
AWSCredentials awsCredentials = new BasicAWSCredentials(Constants.ACCESSKEYID, Constants.ACCESSKEY);
AWSCredentials awsCredentials = new BasicAWSCredentials(Constants.NEWACCESSKEYID, Constants.NEWACCESSKEY);
AmazonEC2 amazonEC2 = new AmazonEC2Client(awsCredentials);
... ... @@ -27,4 +27,17 @@ public class AWSClientComp {
return amazonEC2;
}
public AWSCredentials getAWSCredentials(){
return new BasicAWSCredentials(Constants.NEWACCESSKEYID, Constants.NEWACCESSKEY);
}
/**
* 时区
* @param regions
* @return
*/
public Region getRegion(Regions regions){
return Region.getRegion(regions);
}
}
\ No newline at end of file
... ...
... ... @@ -32,4 +32,7 @@ public class Constants {
public static final String CREATETIME = "createTime";
public static final String NEWACCESSKEYID = "AKIAPGFGVQ6I44746SYQ";
public static final String NEWACCESSKEY = "4DbP9jLY63FHeTeIhvws/v2TgKm27F0//WXFOTi7";
}
\ No newline at end of file
... ...
... ... @@ -4,10 +4,10 @@ import com.monitor.awstools.constant.Constants;
import com.monitor.awstools.constant.JobType;
import com.monitor.awstools.constant.TaskStatus;
import com.monitor.awstools.constant.TaskType;
import com.monitor.awstools.task.AwsTask;
import com.monitor.awstools.model.*;
import com.monitor.awstools.service.AwsQueryService;
import com.monitor.awstools.service.TaskService;
import com.monitor.awstools.task.AwsTask;
import com.monitor.model.response.BaseResponse;
import org.apache.commons.lang.StringUtils;
import org.quartz.CronExpression;
... ... @@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
... ... @@ -36,6 +37,19 @@ public class AwsToolController {
@Autowired
TaskService taskService;
/**
* 自动伸缩查询
* @return
*/
@RequestMapping("/autoScalingConfig")
@ResponseBody
public BaseResponse autoScalingConfig() {
List<AwsAutoScalingGroup> awsAutoScalingGroups = queryService.autoScalingConfig();
BaseResponse response = new BaseResponse();
response.setData(awsAutoScalingGroups);
return response;
}
@RequestMapping(value = "/snapshot/check")
public BaseResponse checkSnapShot(@RequestBody AwsEbsReq task) {
List<M_SnapShot> snapShotList = null;
... ...
package com.monitor.awstools.service;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.autoscaling.AmazonAutoScaling;
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
import com.amazonaws.services.autoscaling.model.*;
import com.amazonaws.services.ec2.model.*;
import com.amazonaws.services.ec2.model.Filter;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.Tag;
import com.monitor.awstools.comp.AWSClientComp;
import com.monitor.awstools.model.M_Instance;
import com.monitor.awstools.model.M_SnapShot;
import com.monitor.awstools.model.M_Volume;
import com.monitor.awstools.model.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -12,10 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.*;
/**
* Created by yoho on 2016/8/31.
... ... @@ -27,6 +30,98 @@ public class AwsQueryService {
AWSClientComp awsClientComp = new AWSClientComp();
/**
* 查询自动伸缩信息
*/
public List<AwsAutoScalingGroup> autoScalingConfig() {
List<AwsAutoScalingGroup> awsAutoScalingGroups = null;
try {
//获取AutoScaling组信息
awsAutoScalingGroups = this.getAwsAutoScaling();
} catch (Exception e) {
DEBUG.error(" - AwsController - autoScalingConfig - error", e);
}
return awsAutoScalingGroups;
}
/**
* 获取AutoScaling组的信息
* @return
*/
private List<AwsAutoScalingGroup> getAwsAutoScaling(){
List<AwsAutoScalingGroup> awsGroups = null;
try {
AmazonAutoScaling client = new AmazonAutoScalingClient(awsClientComp.getAWSCredentials());
client.setRegion(awsClientComp.getRegion(Regions.CN_NORTH_1));
DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest()
.withAutoScalingGroupNames();
DescribeAutoScalingGroupsResult result = client .describeAutoScalingGroups(request);
if(result == null || CollectionUtils.isEmpty(result.getAutoScalingGroups())){
return null;
}
awsGroups = new ArrayList<>();
AwsAutoScalingGroup awsGroup;
for(AutoScalingGroup group : result.getAutoScalingGroups()){
awsGroup = new AwsAutoScalingGroup();
awsGroup.setAutoScalingGroupName(group.getAutoScalingGroupName());
awsGroup.setMinSize(group.getMinSize());
awsGroup.setMaxSize(group.getMaxSize());
awsGroup.setDesiredCapacity(group.getDesiredCapacity());
if(CollectionUtils.isNotEmpty(group.getInstances())){
Collection<String> ids = new ArrayList<>();
for(com.amazonaws.services.autoscaling.model.Instance instance : group.getInstances()){
ids.add(instance.getInstanceId());
}
//根据InstanceId获取详细信息
awsGroup.setAwsInstancess(getDescribeInstances(ids));
awsGroups.add(awsGroup);
}
}
}catch (Exception e){
DEBUG.error(" - AwsController - getAwsAutoScaling - error", e);
}
return awsGroups;
}
/**
* 根据AutoScaling组的InstanceId获取详细信息
* @return
*/
private List<AwsInstances> getDescribeInstances(Collection<String> ids){
List<AwsInstances> awsInstancess = null;
try{
DescribeInstancesRequest request = new DescribeInstancesRequest()
.withInstanceIds(ids);
DescribeInstancesResult result = awsClientComp.getClient().describeInstances(request);
if(result == null || CollectionUtils.isEmpty(result.getReservations())){
return null;
}
awsInstancess = new ArrayList<>();
AwsInstances awsInstances;
for(Reservation res : result.getReservations()){
List<Instance> instances = res.getInstances();
if(CollectionUtils.isEmpty(instances)){
continue;
}
for(Instance instance : instances) {
awsInstances = new AwsInstances();
awsInstances.setId(instance.getInstanceId());
awsInstances.setIp(instance.getPrivateIpAddress());
awsInstancess.add(awsInstances);
}
}
}catch(Exception e){
DEBUG.error(" - AwsController - getDescribeInstances - error", e);
}
return awsInstancess;
}
/**
* 查询volume信息
*
* @param volumeId
... ...
... ... @@ -24,8 +24,8 @@ malicious.ip.redis.read.port=6379
malicious.ip.redis.write.qq.host1=10.66.0.3
malicious.ip.redis.write.qq.host2=10.66.0.2
malicious.ip.redis.write.aws.host1=172.31.20.188
malicious.ip.redis.write.aws.host2=172.31.20.187
malicious.ip.redis.write.aws.host1=172.31.70.163
malicious.ip.redis.write.aws.host2=172.31.70.53
malicious.ip.redis.write.port=6379
#restTemplate
... ...