def describe(nextToken=None): #client = boto3.client('sns') client = hp.getBotoClient('sns') if nextToken is not None: topics = client.list_topics(NextToken=nextToken)['Topics'] else: topics = client.list_topics()['Topics'] topicnames, protocols, endpoints = [], [], [] shownames = [] # print(topics) for topic in topics: arn = hp.getFromJSON(topic, 'TopicArn') attr = client.get_topic_attributes(TopicArn=arn)['Attributes'] displayname = hp.getFromJSON(attr, 'DisplayName') # response = client.get_topic_attributes(TopicArn=arn) # print(arn) # print(response) showname = arn.split(':')[-1] subs = client.list_subscriptions_by_topic( TopicArn=arn)['Subscriptions'] for sub in subs: protocol = hp.getFromJSON(sub, 'Protocol') endpoint = hp.getFromJSON(sub, 'Endpoint') topicnames.append(displayname) protocols.append(protocol) endpoints.append(endpoint) shownames.append(showname) df = pd.DataFrame({ "Topic Display Name": topicnames, "Subscription Protocol": protocols, "Subscription Endpoint": endpoints, "Topic Name": shownames }) return df
def describe_flow(filters, client): flows = client.describe_flow_logs(Filters=filters)['FlowLogs'] flowIds = [] destTypes = [] dests = [] traffics = [] statuses = [] for flow in flows: id = hp.getFromJSON(flow, 'FlowLogId') destType = hp.getFromJSON(flow, 'LogDestinationType') dest = hp.getFromJSON(flow, 'LogDestination') traffic = hp.getFromJSON(flow, 'TrafficType') status = hp.getFromJSON(flow, 'DeliverLogsStatus') flowIds.append(id) destTypes.append(destType) dests.append(dest) traffics.append(traffic) statuses.append(status) flowdf = pd.DataFrame({ "Flow ID": flowIds, "Traffic Type": traffics, "Destination Type": destTypes, "Destination Name": dests, "Status": statuses }) return flowdf
def describe(): #client = boto3.client('lambda') client = hp.getBotoClient('lambda') functions = client.list_functions()['Functions'] names, runtimes, handlers, memories, timeouts, vpcs, envs = [],[],[],[],[],[],[] for function in functions: name = hp.getFromJSON(function, 'FunctionName') runtime = hp.getFromJSON(function, 'Runtime') handler = hp.getFromJSON(function, 'Handler') memory = hp.getFromJSON(function, 'MemorySize') timeout = hp.getFromJSON(function, 'Timeout') vpc = hp.getFromJSON(hp.getFromJSON(function, 'VpcConfig'), 'VpcId') env = hp.getFromJSON(hp.getFromJSON(function, 'Environment'), 'Variables') names.append(name) runtimes.append(runtime) handlers.append(handler) memories.append(memory) timeouts.append(timeout) vpcs.append(vpc) envs.append(str(env)) df = pd.DataFrame({ "Function Name": names, "Runtime": runtimes, "Handler": handlers, "Timeout(s)": timeouts, "Memory(MB)": memories, "VPC": vpcs, "Environment Variables": envs }) return df
def parsePortRange(rule): ip_range = np.NaN fromPort = hp.getFromJSON(rule, 'FromPort') toPort = hp.getFromJSON(rule, 'ToPort') if not np.isnan(fromPort) and not np.isnan(toPort): if fromPort == toPort: ip_range = str(fromPort) else: ip_range = str(fromPort) + " - " + str(toPort) if ip_range == '-1': return 'All' return ip_range
def parseProtocol(rule): protocol = hp.getFromJSON(rule, 'IpProtocol') if protocol == "-1": protocol = "All Traffic" elif protocol == "tcp" or protocol == 'udp' or protocol == 'icmp': protocol = protocol.upper() return protocol
def describe(): #print("Start describing IAM") iam = hp.getBotoClient('iam', region_name="us-east-1") users = iam.list_users()['Users'] usernames = [] inlines = [] attacheds = [] for user in users: username = hp.getFromJSON(user, 'UserName') usernames.append(username) inline = iam.list_user_policies(UserName=username)['PolicyNames'] attached = iam.list_attached_user_policies( UserName=username)['AttachedPolicies'] # find inline policies inline = hp.listToString(inline, None) inlines.append(inline) # find attached policy attached = hp.listToString(attached, 'PolicyName') attacheds.append(attached) df = pd.DataFrame({ "Username": usernames, "Inline policy": inlines, "Attached policy": attacheds }) return df
def parseSourceDest(permission): ipRanges = hp.getFromJSON(permission, 'IpRanges') ipRanges = hp.listToString(ipRanges, 'CidrIp') groups = hp.getFromJSON(permission, 'UserIdGroupPairs') groups = hp.listToString(groups, 'GroupId') prefixlist = hp.getFromJSON(permission, 'PrefixListIds') prefixlist = hp.listToString(prefixlist, 'PrefixListId') # print(ipRanges, groups, prefixlist) if not isinstance(ipRanges, str): ipRanges = '' if not isinstance(groups, str): groups = '' if not isinstance(prefixlist, str): prefixlist = '' ret = checktype(ipRanges) + ';' + checktype(groups) + ';' + checktype( prefixlist) # print(ret) return ret.strip(';')
def describe(nextPageMarker=None): #client = boto3.client('route53domains', region_name='us-east-1') client = hp.getBotoClient('route53domains', region_name='us-east-1') if nextPageMarker is not None: domains = client.list_domains(NextPageMarker=nextPageMarker)['Domains'] else: domains = client.list_domains()['Domains'] names, renews, expiries = [], [], [] for domain in domains: names.append(hp.getFromJSON(domain, 'DomainName')) renews.append(hp.getFromJSON(domain, 'AutoRenew')) expiries.append(hp.getFromJSON(domain, 'Expiry')) df = pd.DataFrame({ "Domain": names, "Auto Renew": renews, "Expiry Date": expiries }) return df
def describe(): #client = boto3.client('') client = hp.getBotoClient('s3') buckets = client.list_buckets()['Buckets'] names = [] for bucket in buckets: name = hp.getFromJSON(bucket, 'Name') names.append(name) return pd.DataFrame({"S3 Bucket": names})
def describe_subnet(filters, client): subnets = client.describe_subnets(Filters=filters)['Subnets'] subnetIDs = [] subnetCIDRs = [] subnetNames = [] subnetAZs = [] subnetVPCs = [] routeNames = [] routeIDs = [] routeAssociates = [] for subnet in subnets: id = hp.getFromJSON(subnet, 'SubnetId') cidr = hp.getFromJSON(subnet, 'CidrBlock') vpcid = hp.getFromJSON(subnet, 'VpcId') name = hp.findNameinTags(subnet) az = hp.getFromJSON(subnet, 'AvailabilityZone') subnetIDs.append(id) subnetCIDRs.append(cidr) subnetNames.append(name) subnetAZs.append(az) subnetVPCs.append(vpcid) # RouteTable filters = [{'Name': "association.subnet-id", 'Values': [id]}] routes = client.describe_route_tables(Filters=filters)['RouteTables'] if routes: route = routes[0] name = hp.findNameinTags(route) routeNames.append(name) routeId = hp.getFromJSON(route, 'RouteTableId') routeIDs.append(routeId) routeAssociates.append(id) subnetdf = pd.DataFrame({ "Subnet Name": subnetNames, "Subnet ID": subnetIDs, "AZ": subnetAZs, "CIDR": subnetCIDRs, }) vpcrtdf = pd.DataFrame({ "Route Table Name": routeNames, "Route Table ID": routeIDs, "Subnet Associations": routeAssociates }) return subnetdf, vpcrtdf
def parseCloudFrontBehaviour(behaviour, default=False): if default: path = "*" else: path = hp.getFromJSON(behaviour, 'PathPattern') viewer = hp.getFromJSON(behaviour, 'ViewerProtocolPolicy') allowed = hp.getFromJSON(behaviour, 'AllowedMethods') allowed = hp.listToString(hp.getFromJSON(allowed, 'Items')) minTTL = hp.getFromJSON(behaviour, 'MinTTL') maxTTL = hp.getFromJSON(behaviour, 'MaxTTL') defaultTTL = hp.getFromJSON(behaviour, 'DefaultTTL') smooth = hp.getFromJSON(behaviour, 'SmoothStreaming') return path, viewer, allowed, minTTL, defaultTTL, maxTTL, smooth
def describe_EIP(): client = hp.getBotoClient('ec2') eips = client.describe_addresses()['Addresses'] #placeholder names, ips = [], [] for eip in eips: name = hp.findNameinTags(eip) ip = hp.getFromJSON(eip, 'PublicIp') names.append(name) ips.append(ip) df = pd.DataFrame({"EIP Name": names, "EIP": ips}) return df
def describe_nat(filters, client): nats = client.describe_nat_gateways(Filters=filters)['NatGateways'] natNames = [] natIDs = [] publicIPs = [] privateIPs = [] for nat in nats: name = hp.findNameinTags(nat) id = hp.getFromJSON(nat, 'NatGatewayId') public = hp.getFromJSON(nat, 'NatGatewayAddresses')[0]['PublicIp'] private = hp.getFromJSON(nat, 'NatGatewayAddresses')[0]['PrivateIp'] natNames.append(name) natIDs.append(id) publicIPs.append(public) privateIPs.append(private) natdf = pd.DataFrame({ "NAT Name": natNames, "NAT ID": natIDs, "Public IP": publicIPs, "Private IP": privateIPs }) return natdf
def describe(): #client = boto3.client('ec2') client = hp.getBotoClient('ec2') securityGroups = client.describe_security_groups()['SecurityGroups'] #placehodler names = [] ids = [] boundTypes = [] protocols = [] portRanges = [] sourceDests = [] for sg in securityGroups: name = hp.getFromJSON(sg, 'GroupName') id = hp.getFromJSON(sg, 'GroupId') inbounds = hp.getFromJSON(sg, 'IpPermissions') outbounds = hp.getFromJSON(sg, 'IpPermissionsEgress') for inbound in inbounds: names.append(name) ids.append(id) boundTypes.append("Inbound") protocols.append(parseProtocol(inbound)) portRanges.append(parsePortRange(inbound)) sourceDests.append(parseSourceDest(inbound)) # for outbound in outbounds: # names.append(name) # ids.append(id) # protocols.append(parseProtocol(outbound)) # boundTypes.append("Outbound") # portRanges.append(parsePortRange(outbound)) # sourceDests.append(parseSourceDest(outbound)) df = pd.DataFrame({ "Security Group Name": names, "Security Group ID": ids, "Protocol": protocols, "Ports": portRanges, "Source/Destination": sourceDests }) return df
def describe_VPN(): # client = boto3.client('ec2') client = hp.getBotoClient('ec2') vpns = client.describe_vpn_connections()['VpnConnections'] vpnnames, vpnids, vgwnames, vgwids, cgwnames, cgwids, statics, routeses = [],[],[],[],[],[],[],[] vgw_vpcs, cgw_ips = [], [] for vpn in vpns: vgwid = hp.getFromJSON(vpn, 'VpnGatewayId') # get vgw name from vgw id if not hp.isEmpty(vgwid): vgw = client.describe_vpn_gateways( VpnGatewayIds=[vgwid])['VpnGateways'][0] vgwname = hp.findNameinTags(vgw) else: vgwname = vgwid cgwid = hp.getFromJSON(vpn, 'CustomerGatewayId') # get cgw name from cgw id if not hp.isEmpty(cgwid): cgw = client.describe_customer_gateways( CustomerGatewayIds=[cgwid])['CustomerGateways'][0] cgwname = hp.findNameinTags(cgw) else: cgwname = cgwid vpnid = hp.getFromJSON(vpn, 'VpnConnectionId') vpnname = hp.findNameinTags(vpn) static = hp.getFromJSON(hp.getFromJSON(vpn, 'Options'), 'StaticRoutesOnly') routes = hp.getFromJSON(vpn, 'Routes') routes = hp.listToString(routes, 'DestinationCidrBlock') if vgwname not in vgwnames: vgwnames.append(vgwname) vgwids.append(vgwid) vgw_vpcs.append(get_vgw_vpc(vgwid)) cgwnames.append(cgwname) cgwids.append(cgwid) vpnnames.append(vpnname) vpnids.append(vpnid) statics.append(static) routeses.append(routes) cgw_ips.append(get_cgw_ip(cgwid)) cgwdf = pd.DataFrame({ "CGW Name": cgwnames, "CGW ID": cgwids, "CGW IP": cgw_ips }) vgwdf = pd.DataFrame({ "VGW Name": vgwnames, "VGW ID": vgwids, "VGW VPC": vgw_vpcs }) vpndf = pd.DataFrame({ "VPN Name": vpnnames, "VPN ID": vpnids, "Routes": routeses }) return cgwdf, vgwdf, vpndf
def describe(): # client = boto3.client('cloudtrail') client = hp.getBotoClient('cloudtrail') trails = client.describe_trails()['trailList'] trailNames = [] s3BucketNames = [] arns = [] regions = [] multi = [] for trail in trails: trailNames.append(hp.getFromJSON(trail, 'Name')) s3BucketNames.append(hp.getFromJSON(trail, 'S3BucketName')) arns.append(hp.getFromJSON(trail, 'TrailARN')) regions.append(hp.getFromJSON(trail, 'HomeRegion')) multi.append(hp.getFromJSON(trail, 'IsMultiRegionTrail')) df = pd.DataFrame({ "Name": trailNames, "S3 Bucket": s3BucketNames, "ARN": arns, "Region": regions, "Multi Region Enabled": multi }) return df
def describe(): client = hp.getBotoClient('rds') #placeholder names, dbNames, endpoints, rendpoints, multiAZs, engines, engineVersions, ports, masterUsers, sgs, instanceClasses = [],[],[],[],[],[],[],[],[],[],[] DBids, storage_types, storage_sizes, MaxAllocatedStorages, DBSecurityGroups, DeletionProtections, PerformanceInsightsEnableds, EnabledCloudwatchLogsExports = [],[],[],[],[],[],[],[] # AuroraćCluster #TODO: currently only show the first 100 clusters = client.describe_db_clusters()['DBClusters'] for cluster in clusters: name = hp.getFromJSON(cluster, 'DBClusterIdentifier') dbName = hp.getFromJSON(cluster, 'DatabaseName') endpoint= hp.getFromJSON(cluster,'Endpoint') rendpoint= hp.getFromJSON(cluster,'ReaderEndpoint') multiAZ = hp.getFromJSON(cluster,'MultiAZ') engine = hp.getFromJSON(cluster,'Engine') engineVersion = hp.getFromJSON(cluster, 'EngineVersion') port = hp.getFromJSON(cluster, 'Port') masterUser = hp.getFromJSON(cluster, 'MasterUsername') sg = hp.getFromJSON(cluster, 'VpcSecurityGroups') sg = hp.listToString(sg,'VpcSecurityGroupId') arn = hp.getFromJSON(cluster, 'DBClusterArn') instances = client.describe_db_instances(Filters=[{'Name': "db-cluster-id", "Values":[arn]}])['DBInstances'] instanceClass = hp.listToString(instances, 'DBInstanceClass') names.append(name) dbNames.append(dbName) endpoints.append(endpoint) rendpoints.append(rendpoint) multiAZs.append(multiAZ) engines.append(engine) engineVersions.append(engineVersion) ports.append(port) masterUsers.append(masterUser) sgs.append(sg) instanceClasses.append(instanceClass) DBids.append('') storage_types.append('') storage_sizes.append('') MaxAllocatedStorages.append('') DBSecurityGroups.append(get_security_group_name(cluster['VpcSecurityGroups'])) DeletionProtections.append(cluster['DeletionProtection']) PerformanceInsightsEnableds.append('N/A') if 'EnabledCloudwatchLogsExports' in cluster: EnabledCloudwatchLogsExports.append(','.join(cluster['EnabledCloudwatchLogsExports'])) else: EnabledCloudwatchLogsExports.append('') # RDS Instance # TODO: currently only showing the first 100 instances = client.describe_db_instances()['DBInstances'] for instance in instances: engine = hp.getFromJSON(instance,'Engine') if engine == "aurora": continue name = hp.getFromJSON(instance,'DBInstanceIdentifier') instanceClass = hp.getFromJSON(instance, 'DBInstanceClass') dbName = hp.getFromJSON(instance,'DBName') endpoint=hp.getFromJSON(hp.getFromJSON(instance,'Endpoint'), 'Address') port = hp.getFromJSON(hp.getFromJSON(instance,'Endpoint'), 'Port') multiAZ = hp.getFromJSON(instance,'MultiAZ') engineVersion = hp.getFromJSON(instance, 'EngineVersion') masterUser = hp.getFromJSON(instance,'MasterUsername') sg = hp.getFromJSON(instance, 'VpcSecurityGroups') sg = hp.listToString(sg,'VpcSecurityGroupId') names.append(name) dbNames.append(dbName) endpoints.append(endpoint) rendpoints.append(np.NaN) multiAZs.append(multiAZ) engines.append(engine) engineVersions.append(engineVersion) ports.append(port) masterUsers.append(masterUser) sgs.append(sg) instanceClasses.append(instanceClass) DBids.append(instance['DbiResourceId']) storage_types.append(instance['StorageType']) storage_sizes.append(instance['AllocatedStorage']) if 'MaxAllocatedStorage' in instance: MaxAllocatedStorages.append(instance['MaxAllocatedStorage']) else: MaxAllocatedStorages.append('') DBSecurityGroups.append(get_security_group_name(instance['VpcSecurityGroups'])) DeletionProtections.append(instance['DeletionProtection']) PerformanceInsightsEnableds.append(instance['PerformanceInsightsEnabled']) if 'EnabledCloudwatchLogsExports' in instance: EnabledCloudwatchLogsExports.append(','.join(instance['EnabledCloudwatchLogsExports'])) else: EnabledCloudwatchLogsExports.append('') df = pd.DataFrame({"Identifier": names, "Engine": engines, "Engine Version": engineVersions, "Multi AZ": multiAZs, \ "Endpoint": endpoints, "Reader Endpoint": rendpoints, "DB Name": dbNames,"Port": ports ,"User Name": masterUsers, \ "Security Group": sgs, "Instance Class": instanceClasses, "DB instance id": DBids, "Storage type": storage_types, \ "Storage Size": storage_sizes, "Maximum storage threshold": MaxAllocatedStorages, "Deletion protection" : DeletionProtections, \ "Performance Insights enabled": PerformanceInsightsEnableds, "CloudWatch Logs": EnabledCloudwatchLogsExports }) return df
def describe(): #client = boto3.client('ec2') client = hp.getBotoClient('ec2') reservations = client.describe_instances()['Reservations'] names = [] instancetypes = [] azs = [] amis = [] publicips = [] publicDNSes = [] privateips = [] privateDNSes = [] vpcIds = [] subnets = [] keys = [] securitygroups = [] ebsVolumes = [] ebsSizes = [] encrypteds, deletonterminates = [], [] for reservation in reservations: instances = reservation['Instances'] for instance in instances: if instance['State']['Name'] == 'terminated': continue name = hp.findNameinTags(instance) instanceType = hp.getFromJSON(instance,'InstanceType') az = hp.getFromJSON(hp.getFromJSON(instance,'Placement'),'AvailabilityZone') ami = hp.getFromJSON(instance,'ImageId') publicip = hp.getFromJSON(instance, 'PublicIpAddress') if not isinstance(publicip, str): publicip = 'N/A' publicDNS = hp.getFromJSON(instance, 'PublicDnsName') if publicDNS == '': publicDNS = 'N/A' privateip = hp.getFromJSON(instance, 'PrivateIpAddress') privateDNS = hp.getFromJSON(instance, 'PrivateDnsName') vpcId = hp.getFromJSON(instance, 'VpcId') subnetId = hp.getFromJSON(instance, 'SubnetId') key = hp.getFromJSON(instance, 'KeyName') sgs = hp.getFromJSON(instance, 'SecurityGroups') sgs = hp.listToString(sgs, 'GroupName') #EBS id = hp.getFromJSON(instance, 'InstanceId') filters = [{'Name': "attachment.instance-id", 'Values': [id]}] volumes = client.describe_volumes(Filters=filters)['Volumes'] types = hp.listToString(volumes, 'VolumeType') sizes = hp.listToString(volumes,'Size') size_list = sizes.split(';') tmp = [] for item in size_list: tmp.append(item + 'GB') sizes = ';'.join(tmp) ebs_id = hp.listToString(volumes,'VolumeId') names.append(name) instancetypes.append(instanceType) azs.append(az) amis.append(ami) publicips.append(publicip) publicDNSes.append(publicDNS) if privateip == np.NaN: privateip = 'N/A' privateips.append(privateip) privateDNSes.append(privateDNS) vpcIds.append(vpcId) subnets.append(subnetId) keys.append(key) securitygroups.append(sgs) ebsVolumes.append(types) ebsSizes.append(sizes) ebs_attr = get_volumes_attribute(ebs_id) # ebs_attr = get_volume_attribute(ebs_id) encrypteds.append(ebs_attr['Encrypted']) deletonterminates.append(ebs_attr['DeleteOnTermination']) print(publicDNSes) df = pd.DataFrame({"EC2 Name": names, "Instance Type": instancetypes, "AZ": azs, "AMI": amis, "Public IP": publicips, "Public DNS": publicDNSes, "Private IP": privateips, "Private DNS": privateDNSes, "VPC ID": vpcIds, "Subnet ID": subnets, "Key": keys,"Security Groups": securitygroups, "EBS Type": ebsVolumes, "EBS Size": ebsSizes, "Encrypted": encrypteds}) return df
def describe_ELB(): #TODO: Change sg -> name # instance -> name # client = boto3.client('elbv2') client = hp.getBotoClient('elbv2') elbs = client.describe_load_balancers()['LoadBalancers'] #place holder for elb elbname, elbdns, elbscheme, elbVpc, elbType, elbAZ, elbSubnet, elbSG = [],[],[], [], [], [], [], [] #place holder for listener listenerProtocol,listenerPort,listenerDefaultSSL,listenerOtherSSL,listenerElb = [],[],[], [], [] #place holder for tg targetELB, targetNames, protocols, ports, unhealthys, healthys, healthpaths, healthports, healthprotocols, healthTimeouts, healthIntervals, registereds = [],[],[], [], [], [], [], [], [], [], [], [] targettypes = [] for elb in elbs: name = hp.getFromJSON(elb, 'LoadBalancerName') dns = hp.getFromJSON(elb, 'DNSName') scheme = hp.getFromJSON(elb, 'Scheme') vpc = hp.getFromJSON(elb, 'VpcId') type = hp.getFromJSON(elb, 'Type') azs = hp.listToString(hp.getFromJSON(elb, 'AvailabilityZones'), 'ZoneName') subnets = hp.listToString(hp.getFromJSON(elb, 'AvailabilityZones'), 'SubnetId') sgs = hp.listToString(hp.getFromJSON(elb, 'SecurityGroups'), None) arn = hp.getFromJSON(elb, 'LoadBalancerArn') elbname.append(name) elbdns.append(dns) elbscheme.append(scheme) elbType.append(type) elbVpc.append(vpc) elbAZ.append(azs) elbSubnet.append(subnets) elbSG.append(sgs) # Listeners listeners = client.describe_listeners(LoadBalancerArn=arn)['Listeners'] for listener in listeners: protocol = hp.getFromJSON(listener, 'Protocol') port = hp.getFromJSON(listener, 'Port') sslids = hp.getFromJSON(listener, 'Certificates') default_ssl = np.NaN other_ssls = [] if not hp.isEmpty(sslids): for sslid in sslids: ssl = hp.getFromJSON(sslid, 'CertificateArn') ssl = ssl + " (" + hp.getDomainsFromACM(ssl) + ")" if hp.getFromJSON(sslid, 'IsDefault'): default_ssl = ssl else: other_ssls.append(ssl) other_ssls = hp.listToString(other_ssls, None) listenerElb.append(name) listenerProtocol.append(protocol) listenerPort.append(port) listenerDefaultSSL.append(default_ssl) listenerOtherSSL.append(other_ssls) # Target Group targets = client.describe_target_groups( LoadBalancerArn=arn)['TargetGroups'] for target in targets: targetName = hp.getFromJSON(target, 'TargetGroupName') protocol = hp.getFromJSON(target, 'Protocol') port = hp.getFromJSON(target, 'Port') arn = hp.getFromJSON(target, 'TargetGroupArn') targetType = hp.getFromJSON(target, 'TargetType') #Health Check unhealthy = hp.getFromJSON(target, 'UnhealthyThresholdCount') healthy = hp.getFromJSON(target, 'HealthyThresholdCount') healthpath = hp.getFromJSON(target, 'HealthCheckPath') healthport = hp.getFromJSON(target, 'HealthCheckPort') healthprotocol = hp.getFromJSON(target, 'HealthCheckProtocol') healthTimeout = hp.getFromJSON(target, 'HealthCheckTimeoutSeconds') healthInterval = hp.getFromJSON(target, 'HealthCheckIntervalSeconds') #Instances healths = client.describe_target_health( TargetGroupArn=arn)['TargetHealthDescriptions'] instances = [] for health in healths: instance = hp.getFromJSON(health, 'Target') instanceId = hp.getFromJSON(instance, 'Id') instances.append(instanceId) instances = hp.listToString(instances, None) targetELB.append(name) targetNames.append(targetName) protocols.append(protocol) ports.append(port) unhealthys.append(unhealthy) healthys.append(healthy) healthpaths.append(healthpath) healthports.append(healthport) healthprotocols.append(healthprotocol) healthTimeouts.append(healthTimeout) healthIntervals.append(healthInterval) registereds.append(instances) targettypes.append(target['TargetType']) elbdf = pd.DataFrame({ "ELB Name": elbname, "Type": elbType, "DNS": elbdns, "Internal/Internet Facing": elbscheme, "VPC": elbVpc, "AZ": elbAZ, "Subnet": elbSubnet, "SG": elbSG }) listenerdf = pd.DataFrame({ "ELB Name": listenerElb, "Protocol": listenerProtocol, "Port": listenerPort, "Default Cert": listenerDefaultSSL, "Other Certs": listenerOtherSSL }) tgdf = pd.DataFrame({ "ELB Name": targetELB, "Target Group Name": targetNames, "Protocol": protocols, "Port": ports, "Registered Instances": registereds, "Healthy Threshold": healthys, "Unhealthy Threshold": unhealthys, "Health Check Path": healthpaths, "Health Check Protocol": healthprotocols, "Health Check Port": healthports, "Health Check Timeout": healthTimeouts, "Health Check Interval": healthIntervals, 'Target Type': targettypes }) return elbdf, listenerdf, tgdf
def describe_CLB(): #client = boto3.client('elb') client = hp.getBotoClient('elb') clbs = client.describe_load_balancers()['LoadBalancerDescriptions'] # placeholder for clb names, dnses, schemes, vpcs, listenerProtocols, listenerPorts, instanceProtocols, instancePorts, ssls, azes, subnetIds,securitys, registereds, healthTargets, healthIntervals, healthTimeouts, unhealthys, healthys= [], [],[],[], [], [], [], [], [], [], [], [], [], [], [], [], [], [] for clb in clbs: name = hp.getFromJSON(clb, 'LoadBalancerName') dns = hp.getFromJSON(clb, 'DNSName') scheme = hp.getFromJSON(clb, 'Scheme') vpc = hp.getFromJSON(clb, 'VPCId') azs = hp.listToString(hp.getFromJSON(clb, 'AvailabilityZones'), None) subnets = hp.listToString(hp.getFromJSON(clb, 'Subnets'), None) sgs = hp.listToString(hp.getFromJSON(clb, 'SecurityGroups'), None) instances = hp.getFromJSON(clb, 'Instances') instances = hp.listToString(instances, 'InstanceId') healthCheck = hp.getFromJSON(clb, 'HealthCheck') target = hp.getFromJSON(healthCheck, 'Target') interval = hp.getFromJSON(healthCheck, 'Interval') timeout = hp.getFromJSON(healthCheck, 'Timeout') unhealthy = hp.getFromJSON(healthCheck, 'UnhealthyThreshold') healthy = hp.getFromJSON(healthCheck, 'HealthyThreshold') listeners = hp.getFromJSON(clb, 'ListenerDescriptions') for listener in listeners: listener = hp.getFromJSON(listener, 'Listener') protocol = hp.getFromJSON(listener, 'Protocol') port = hp.getFromJSON(listener, 'LoadBalancerPort') instanceProtocol = hp.getFromJSON(listener, 'InstanceProtocol') instancePort = hp.getFromJSON(listener, 'InstancePort') sslid = hp.getFromJSON(listener, 'SSLCertificateId') ssl = sslid + " (" + hp.getDomainsFromACM(sslid) + ")" names.append(name) dnses.append(dns) schemes.append(scheme) vpcs.append(vpc) registereds.append(instances) azes.append(azs) subnetIds.append(subnets) securitys.append(sgs) listenerProtocols.append(protocol) listenerPorts.append(port) instanceProtocols.append(instanceProtocol) instancePorts.append(instancePort) ssls.append(ssl) healthTargets.append(target) healthIntervals.append(interval) healthTimeouts.append(timeout) unhealthys.append(unhealthy) healthys.append(healthy) #TODO: Change security group -> name # Change instance -> instance name df = pd.DataFrame({ "CLB Name": names, "CLB DNS": dnses, "Internal/Internet Facing": schemes, "VPC": vpcs, "Registered Instances": registereds, "AZ": azes, "Subnet": subnetIds, "Security Group": securitys, "Listener Protocol": listenerProtocols, "Listener Port": listenerPorts, "Instance Protocol": instancePorts, "SSL": ssls, "Health Check": healthTargets, "Health Check Interval": healthIntervals, "Health Check Timeout": healthTimeouts, "Unhealthy Threshold": unhealthys, "Healthy Threshold": healthys }) return df
def describe(): # client = boto3.client('ec2') client = hp.getBotoClient('ec2') #VPC vpcs = client.describe_vpcs()['Vpcs'] vpcIDs = [] vpcCIDRs = [] vpcNames = [] igwNames = [] igwIDs = [] regions = [] #Region region_dict = { 'us-east-1': 'N. Virginia', 'us-east-2': 'Ohio', 'N. California': 'us-west-1', 'us-west-2': 'Oregon', 'af-south-1': 'Cape Town', 'ap-east-1': 'Hong Kong', 'ap-south-1': 'Mumbai', 'ap-northeast-2': 'Seoul', 'ap-southeast-1': 'Singapore', 'ap-southeast-2': 'Sydney', 'ap-northeast-1': 'Tokyo', 'ca-central-1': 'Central', 'eu-central-1': 'Frankfurt', 'eu-west-1': 'Ireland', 'eu-west-2': 'London', 'eu-south-1': 'Milan', 'eu-west-3': 'Paris', 'eu-north-1': 'Stockholm', 'me-south-1': 'Bahrain', 'sa-east-1': 'Sao Paulo' } region = boto3._get_default_session().region_name for vpc in vpcs: if vpc['IsDefault'] == True: continue id = hp.getFromJSON(vpc, 'VpcId') cidr = hp.getFromJSON(vpc, 'CidrBlock') vpcIDs.append(id) vpcCIDRs.append(cidr) name = hp.findNameinTags(vpc) vpcNames.append(name) regions.append(region_dict[region]) # IGW filters = [{'Name': "attachment.vpc-id", 'Values': [id]}] igws = client.describe_internet_gateways( Filters=filters)['InternetGateways'] if igws: igw = igws[0] name = hp.findNameinTags(igw) igwNames.append(name) igwId = igw['InternetGatewayId'] igwIDs.append(igwId) vpcdf = pd.DataFrame({ "Region": regions, "VPC Name": vpcNames, "VPC ID": vpcIDs, "CIDR": vpcCIDRs }) igwdf = pd.DataFrame({"IGW Name": igwNames, "IGW ID": igwIDs}) #Subnet filters = [{'Name': "vpc-id", 'Values': vpcIDs}] subnetdf, vpcrtdf = describe_subnet(filters, client) #NAT filters = [{'Name': "vpc-id", 'Values': vpcIDs}] natdf = describe_nat(filters, client) #VPC Flow Log filters = [{'Name': "resource-id", 'Values': vpcIDs}] flowdf = describe_flow(filters, client) return vpcdf, subnetdf, vpcrtdf, igwdf, natdf, flowdf
def describe(): #client = boto3.client('elasticache') client = hp.getBotoClient('elasticache') # For Memcached clusters = client.describe_cache_clusters( ShowCacheClustersNotInReplicationGroups=True)['CacheClusters'] names, endpoints, ports, engines, engineversions, subnetgroups, nodeTypes, azs, sgs, maintenances, backups = [],[],[],[],[],[],[],[],[], [], [] for cluster in clusters: name = hp.getFromJSON(cluster, 'CacheClusterId') engine = hp.getFromJSON(cluster, 'Engine') engineversion = hp.getFromJSON(cluster, 'EngineVersion') endpoint = hp.getFromJSON( hp.getFromJSON(cluster, 'ConfigurationEndpoint'), 'Address') port = hp.getFromJSON(hp.getFromJSON(cluster, 'ConfigurationEndpoint'), 'Port') subnetgroup = hp.getFromJSON(cluster, 'CacheSubnetGroupName') nodeType = hp.getFromJSON(cluster, 'CacheNodeType') az = hp.getFromJSON(cluster, 'PreferredAvailabilityZone') sg = hp.getFromJSON(cluster, 'SecurityGroups') sg = hp.listToString(sg, 'SecurityGroupId') maintenance = hp.getFromJSON(cluster, 'PreferredMaintenanceWindow') backup = hp.getFromJSON(cluster, 'SnapshotWindow') names.append(name) endpoints.append(endpoint) ports.append(port) engines.append(engine) engineversions.append(engineversion) subnetgroups.append(subnetgroup) nodeTypes.append(nodeType) azs.append(az) sgs.append(sg) maintenances.append(maintenance) backups.append(backup) # For Redis replications = client.describe_replication_groups()['ReplicationGroups'] for replication in replications: name = hp.getFromJSON(replication, 'ReplicationGroupId') if hp.getFromJSON(replication, 'ClusterEnabled'): endpoint = hp.getFromJSON( hp.getFromJSON(replication, 'ConfigurationEndpoint'), 'Address') port = hp.getFromJSON( hp.getFromJSON(replication, 'ConfigurationEndpoint'), 'Port') else: endpoint = hp.getFromJSON( hp.getFromJSON( hp.getFromJSON(replication, 'NodeGroups')[0], 'PrimaryEndpoint'), 'Address') port = hp.getFromJSON( hp.getFromJSON( hp.getFromJSON(replication, 'NodeGroups')[0], 'PrimaryEndpoint'), 'Port') backup = hp.getFromJSON(replication, 'SnapshotWindow') # Get Info from one of the cluster under the replication group cluster = hp.getFromJSON(replication, 'MemberClusters')[0] cluster = client.describe_cache_clusters( CacheClusterId=cluster)['CacheClusters'][0] engineversion = hp.getFromJSON(cluster, 'EngineVersion') subnetgroup = hp.getFromJSON(cluster, 'CacheSubnetGroupName') sg = hp.getFromJSON(cluster, 'SecurityGroups') sg = hp.listToString(sg, 'SecurityGroupId') maintenance = hp.getFromJSON(cluster, 'PreferredMaintenanceWindow') names.append(name) endpoints.append(endpoint) ports.append(port) engines.append("redis") nodeType = hp.getFromJSON(replication, 'CacheNodeType') engineversions.append(engineversion) subnetgroups.append(subnetgroup) nodeTypes.append(nodeType) azs.append("Multiple") sgs.append(sg) maintenances.append(maintenance) backups.append(backup) df = pd.DataFrame({ "Name": names, "Endpoint": endpoints, "Port": ports, "Engine": engines, "Engine Version": engineversions, "Subnet Group": subnetgroups, "Node Type": nodeTypes, "AZ": azs, "Security Group": sgs, "Maintenance Window": maintenances, "Back Up Window": backups }) return df
def describe(): #client = boto3.client('cloudfront') client = hp.getBotoClient('cloudfront', region_name="us-east-1") dists = client.list_distributions()['DistributionList'].get('Items') if dists is None: # set to emmpty to list if no distribution found dists = [] ids, dnses, cnames, prices, originIDs, originDNSs, defaultPaths, defaultViewers, defaultAlloweds, defaultminTTL, defaultDefaultTTL, defaultMaxTTL, defaultSmooth, others = [ ], [], [], [], [], [], [], [], [], [], [], [], [], [] # OriginProtocolPolicys = [] for dist in dists: id = hp.getFromJSON(dist, 'Id') dns = hp.getFromJSON(dist, 'DomainName') cname = hp.getFromJSON(dist, 'Aliases') if hp.getFromJSON(cname, 'Quantity') is not 0: cname = hp.listToString(hp.getFromJSON(cname, 'Items ')) else: cname = np.NaN price = hp.getFromJSON(dist, 'PriceClass') origin = hp.getFromJSON(hp.getFromJSON(dist, 'Origins'), 'Items') originID = hp.listToString(origin, 'Id') originDNS = hp.listToString(origin, 'DomainName') default = hp.getFromJSON(dist, 'DefaultCacheBehavior') path, viewer, allowed, minTTL, defaultTTL, maxTTL, smooth = parseCloudFrontBehaviour( default, True) other = formatOtherCloudFrontBehaviours( hp.getFromJSON(hp.getFromJSON(dist, 'CacheBehaviors'), 'Items')) ids.append(id) dnses.append(dns) prices.append(price) cnames.append(cname) originIDs.append(originID) originDNSs.append(originDNS) defaultPaths.append(path) defaultViewers.append(viewer) defaultAlloweds.append(allowed) defaultminTTL.append(minTTL) defaultDefaultTTL.append(defaultTTL) defaultMaxTTL.append(maxTTL) defaultSmooth.append(smooth) others.append(other) # OriginProtocolPolicys.append(dist['Origins']['Items'][0]['CustomOriginConfig']['OriginProtocolPolicy']) df = pd.DataFrame({ "ID": ids, "DNS": dnses, "Cname": cnames, "Price Class": prices, "Origin ID": originIDs, "Origin DNS": originDNSs, "Default Behaviour: Path": defaultPaths, "Viewer Protocol Policy": defaultViewers, "Allowed Methods": defaultAlloweds, "Min TTL": defaultminTTL, "Default TTL": defaultDefaultTTL, "Max TTL": defaultMaxTTL, "Smooth Streaming": defaultSmooth, "Other Cache Behaviours": others }) return df