Created
November 8, 2022 01:28
-
-
Save asdaraujo/84bdf1ebd8b1fa39b0359d569a6a8c9a to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -u | |
set -e | |
# The following should be set if not already exported at the shell level | |
#export CDP_PROFILE=<cdp_profile_name> | |
#export AWS_PROFILE=<aws_profile_name> | |
ENV_NAME=$1 | |
LOG_DIR=./${ENV_NAME}-$(date +%Y%m%d%H%M%S) | |
TARBALL=./${ENV_NAME}-$(date +%Y%m%d%H%M%S).tar.gz | |
mkdir -p $LOG_DIR | |
echo "Collecting environment details - $ENV_NAME" | |
cdp environments describe-environment --environment-name $ENV_NAME > $LOG_DIR/environment.json | |
ENV_CRN=$(jq -r '.environment.crn' $LOG_DIR/environment.json) | |
export AWS_DEFAULT_REGION=$(jq -r '.environment.region' $LOG_DIR/environment.json) | |
DL_NAME=$(cdp datalake list-datalakes | jq -r '.datalakes[] | select(.environmentCrn == "'"$ENV_CRN"'").datalakeName') | |
echo "Collecting datalake details - $DL_NAME" | |
cdp datalake describe-datalake --datalake-name $DL_NAME > $LOG_DIR/datalake.json | |
cdp datahub list-clusters | jq -r '.clusters[] | select(.environmentCrn == "'"$ENV_CRN"'").clusterName' | while read CLUSTER_NAME; do | |
echo "Collecting datahub details - $CLUSTER_NAME" | |
cdp datahub describe-cluster --cluster-name $CLUSTER_NAME > $LOG_DIR/cluster_${CLUSTER_NAME}.json | |
done | |
VPC_ID=$(jq -r '.environment.network.aws.vpcId' $LOG_DIR/environment.json) | |
echo "Collecting VPC details - $VPC_ID" | |
aws ec2 describe-vpcs --filters Name=vpc-id,Values=$VPC_ID > $LOG_DIR/vpc.json | |
echo "Collecting subnet details - VPC $VPC_ID" | |
aws ec2 describe-subnets --filters Name=vpc-id,Values=$VPC_ID > $LOG_DIR/subnets.json | |
echo "Collecting route table details - VPC $VPC_ID" | |
aws ec2 describe-route-tables --filters Name=vpc-id,Values=$VPC_ID > $LOG_DIR/route_tables.json | |
echo "Collecting load balancers details - VPC $VPC_ID" | |
aws elb describe-load-balancers | jq '[.LoadBalancerDescriptions[] | select(.VPCId == "'"$VPC_ID"'")]' > $LOG_DIR/elb.json | |
echo "Collecting target groups details - VPC $VPC_ID" | |
aws elbv2 describe-target-groups | jq -r '[.TargetGroups[] | select(.VpcId == "'"$VPC_ID"'")]' > $LOG_DIR/elb_target_groups.json | |
jq -r '.[] | "\(.TargetGroupArn) \(.TargetGroupName)"' $LOG_DIR/elb_target_groups.json | while read TARGET_ARN TARGET_NAME; do | |
echo "Collecting target groups attributes details - $TARGET_NAME" | |
aws elbv2 describe-target-group-attributes --target-group-arn $TARGET_ARN > $LOG_DIR/elb_target_group_attributes_${TARGET_NAME}.json | |
done | |
tar -zcvf $TARBALL $LOG_DIR | |
echo -e "\nDetails file: $TARBALL" | |
rm -rf $LOG_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment