def s3Missing(self, current, aconnect, itemlist, lfound): objs = [] objs.append(['Name', 'Audit', 'Owner', 'Size']) for unit in itemlist: name = unit['Name'] if name in lfound: continue objs = self.s3Define(current, aconnect, objs, unit, name) printColor([ '[E] s3 [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def elbMissing(self, current, aconnect, itemlist, lfound): objs = [] objs.append( ['Name', 'Audit', 'Owner', 'Total Instances', 'DNS', 'VPC']) for unit in itemlist: name = unit['LoadBalancerName'] if name in lfound: continue objs = self.elbDefine(current, aconnect, objs, unit, name) printColor([ '[E] ELB [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def ec2Missing(self, current, aconnect, itemlist, lfound): objs = [] objs.append([ 'Name', 'Audit', 'Owner', 'type', 'Platform', 'SecurityGroups', 'Instance', 'Zone', 'VPC', 'State' ]) for unit in itemlist: name = unit['Name'] if name in lfound: continue objs = self.ec2Define(current, aconnect, objs, unit, name) printColor([ '[E] EC2 [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def lambdaMissing(self, current, aconnect, itemlist, lfound): objs = [] objs.append([ 'Name', 'Audit', 'Owner', 'Runtime', 'Role', 'CodeSize', 'MemorySize', 'VPC', 'Description', 'last_Modified' ]) for unit in itemlist: name = unit['FunctionName'] if name in lfound: continue objs = self.lambdaDefine(current, aconnect, objs, unit, name) printColor([ '[E] Lambda [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def rdsMissing(self, current, aconnect, itemlist, lfound): objs = [] objs.append([ 'Name', 'Audit', 'Owner', 'Engine', 'Size (GB)', 'Instance', 'MutliAZ', 'VPC', 'last_Modified' ]) for unit in itemlist: name = unit['DBInstanceIdentifier'] if name in lfound: continue objs = self.rdsDefine(current, aconnect, objs, unit, name) printColor([ '[E] RDS [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def cloudformationMissing(self, current, aconnect, itemlist, lfound): objs = [] objs.append([ 'Name', 'Audit', 'Owner', 'Account', 'Status', 'Description', 'last_Modified' ]) for unit in itemlist: name = unit['StackName'] if name in lfound: continue objs = self.cloudformationDefine(current, aconnect, objs, unit, name) printColor([ '[E] ELB [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def apiMissing(self, current, aconnect, itemlist, lfound): objs = [] objs.append([ 'Name', 'Audit', 'Owner', 'Id', 'Description', 'StageName', 'CacheClstrEnabled', 'CacheClstrStatus', 'CacheClstrSize', 'last_Modified' ]) for unit in itemlist: name = unit['name'] if name in lfound: continue objs = self.apiDefine(current, aconnect, objs, unit, name) printColor([ '[E] apiGateway [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def dynamoMissing(self, current, aconnect, itemlist, lfound): objs = [] objs.append([ 'Name', 'Audit', 'Owner', 'Status', 'Partition key', 'indexes', 'totalRead', 'totalWrite' ]) client = aconnect.__get_client__(current.svc) for name in itemlist: unit = client.describe_table(TableName=name)['Table'] if name in lfound: continue objs = self.dynamoDefine(current, aconnect, objs, unit, name) printColor([ '[E] DynamoDB [%s] Missing correct naming....in .%s' % (name, aconnect._region) ]) return objs
def s3Item(self, current, aconnect, itemlist): added = False printColor(['_____LISTING s3 [] now....in .%s' % (aconnect._region)]) lfound = [] objs = [] rows = [] nEnv = aconnect._env for unit in itemlist: name = unit['Name'] account = '' #unit['StackId'] cleint.get_bucket_policy(Bucket=l['Name'])['Policy']['Statement'] if nEnv in name or aconnect._useAccounts: lfound.append(name) if not added: added = True objs.append( ['Name[%s]' % (current.svc), 'Audit', 'Owner', 'Size']) objs, row = self.s3Define(current, aconnect, objs, unit, name) rows.append(row) return (lfound, objs, rows)
def elbItem(self, current, aconnect, itemlist): added = False printColor(['_____LISTING ELB [] now....in .%s' % (aconnect._region)]) lfound = [] objs = [] rows = [] nEnv = aconnect._env for unit in itemlist: name = unit['LoadBalancerName'] account = unit['SourceSecurityGroup']['OwnerAlias'] if str(nEnv) in name or aconnect._useAccounts: lfound.append(name) if not added: added = True objs.append([ 'Name[%s]' % (current.svc), 'Audit', 'Owner', 'TotalInstances', 'VPC', 'DNS' ]) objs, row = self.elbDefine(current, aconnect, objs, unit, name) rows.append(row) return (lfound, objs, rows)
def apiItem(self, current, aconnect, itemlist): added = False printColor( ['_____LISTING apiGateway [] now....in .%s' % (aconnect._region)]) objs = [] rows = [] lfound = [] nEnv = aconnect._env for unit in itemlist: name = unit['name'] account = '' if nEnv in name or aconnect._useAccounts: lfound.append(name) if not added: added = True objs.append([ 'Name[%s]' % (current.svc), 'Audit', 'Owner', 'Id', 'Description', 'StageName', 'CacheClstrEnabled', 'CacheClstrStatus', 'CacheClstrSize', 'last_Modified' ]) objs, row = self.apiDefine(current, aconnect, objs, unit, name) rows.append(row) return (lfound, objs, rows)
def cloudformationItem(self, current, aconnect, itemlist): added = False printColor([ '_____LISTING CloudFORMATION [] now....in .%s' % (aconnect._region) ]) nEnv = aconnect._env objs = [] lfound = [] rows = [] for unit in itemlist: name = unit['StackName'] account = unit['StackId'] if nEnv in name or aconnect._useAccounts: lfound.append(name) if not added: added = True objs.append([ 'Name[%s]' % (current.svc), 'Audit', 'Owner', 'Account', 'Status', 'Description', 'last_Modified' ]) objs, row = self.cloudformationDefine(current, aconnect, objs, unit, name) rows.append(row) return (lfound, objs, rows)
def lambdaItem(self, current, aconnect, itemlist): added = False printColor( ['_____LISTING Lambdas [] now....in .%s' % (aconnect._region)]) nEnv = aconnect._env lfound = [] objs = [] rows = [] for unit in itemlist: name = unit['FunctionName'] account = unit['FunctionArn'] if str(nEnv) in name or aconnect._useAccounts: lfound.append(name) if not added: added = True objs.append([ 'Name[%s]' % (current.svc), 'Audit', 'Owner', 'Runtime', 'Role', 'CodeSize', 'MemorySize', 'VPC', 'Description', 'last_Modified' ]) objs, row = self.lambdaDefine(current, aconnect, objs, unit, name) rows.append(row) return (lfound, objs, rows)
def dynamoItem(self, current, aconnect, itemlist): added = False printColor( ['_____LISTING DynamoDB [] now....in .%s' % (aconnect._region)]) threaded = aconnect.getMultiThread() nEnv = aconnect._env lfound = [] objs = [] rows = [] pools = 2 # 171.35 seconds #168 seconds totalItems = len(itemlist) if threaded: pools = auditMeth.poolThreadNumber(totalItems, mp.cpu_count()) if pools > 0: p = mp.Pool(pools) elif pools == 0: threaded = False else: p = mp.Pool() m = mp.Manager() q = m.Queue() if totalItems > 0: objs.append([ 'Name[%s]' % (current.svc), 'Audit', 'Owner', 'Status', 'PartitionKey', 'indexes', 'totalRead', 'totalWrite' ]) client = aconnect.__get_client__('dynamodb') if not threaded: for name in itemlist: unit = client.describe_table(TableName=name)['Table'] #account = dunit['TableArn'] if nEnv in name or aconnect._useAccounts: if pools == 0: objs, row = dynamoDefine(unit, name, q) else: getit = p.apply_async(dynamoDefine, (unit, name, q)) #getit.get() lfound.append(name) #objs,row=self.dynamoDefine(current,aconnect,objs,unit,name) #rows.append(row) else: #print itemlist lfound = [name for name in itemlist] #print lfound #print 'client ready?' #dd = client.describe_table(TableName='Tags')['Table'] #print dd results = p.map(dynamoDefine, (client.describe_table(TableName=name)['Table'] for name in itemlist)) if pools > 0: p.close() p.join() if threaded: for que in results: newobjs, row = que #print ' RDS --got[C] result', row objs = objs + newobjs rows.append(row) else: while not q.empty(): newobjs, row = q.get() objs = objs + newobjs # print newobjs rows.append(row) return (lfound, objs, rows)
def rdsItem(self, current, aconnect, itemlist): added = False printColor(['_____LISTING RDS [] now....in .%s' % (aconnect._region)]) threaded = aconnect.getMultiThread() nEnv = aconnect._env lfound = [] objs = [] rows = [] pools = 2 # 171.35 seconds #168 seconds totalItems = len(itemlist) q = None if threaded: pools = auditMeth.poolThreadNumber(totalItems, mp.cpu_count()) p = mp.Pool(1 if pools == 0 else pools) else: p = mp.Pool() m = mp.Manager() q = m.Queue() if totalItems > 0: objs.append([ 'Name[%s]' % (current.svc), 'Audit', 'Owner', 'Engine', 'Size (GB)', 'Instance', 'MutliAZ', 'VPC', 'last_Modified', 'connections', 'cost' ]) if not threaded: for unit in itemlist: name = unit['DBInstanceIdentifier'] #sg=unit['VpcSecurityGroups'][0]['VpcSecurityGroupId'] #ec2 = aconnect.__get_client__('ec2') #sgUnit = ec2.describe_security_groups(GroupIds=[sg])['SecurityGroups'][0] #account = sgUnit['OwnerId'] if nEnv in name or aconnect._useAccounts: if pools == 0: objs, row = rdsDefine(unit, name, q) else: getit = p.apply_async(rdsDefine, (unit, name, q)) #getit.get() lfound.append(name) #objs,row = self.rdsDefine(current,aconnect,objs,unit,name) #rows.append(row) else: #print itemlist lfound = [unit['DBInstanceIdentifier'] for unit in itemlist] results = p.map(rdsDefine, (unit for unit in itemlist)) if pools > 0: p.close() p.join() if threaded: for que in results: newobjs, row = que #print ' DYNAMO --got[C] result', row objs = objs + newobjs rows.append(row) else: while not q.empty(): newobjs, row = q.get() objs = objs + newobjs # print newobjs rows.append(row) print objs return (lfound, objs, rows)
def ec2Item(self, current, aconnect, itemlist): printColor(['_____LISTING EC2 [] now....in .%s' % (aconnect._region)]) threaded = aconnect.getMultiThread() objs = [] lfound = [] rows = [] #processes = mp.cpu_count()*2 #p = mp.Pool(processes) #m = mp.Manager(processes=processes*2) #q = m.Queue(processes*2) #print itemlist pools = 2 #171.35 seconds #168 seconds totalItems = len(itemlist) if threaded: pools = auditMeth.poolThreadNumber(totalItems, mp.cpu_count()) if pools > 0: p = mp.Pool(pools) elif pools == 0: threaded = False else: p = mp.Pool() m = mp.Manager() q = m.Queue() nEnv = aconnect._env if totalItems > 0: objs.append([ 'Name[%s]' % (current.svc), 'Audit', 'Owner', 'type', 'Platform', 'SecurityGroups', 'Instance', 'Zone', 'VPC', 'State', 'cpu_week', 'cost', 'spot' ]) if not threaded: for unit in itemlist: name = unit['Name'] account = unit['OwnerId'] if str(nEnv) in name or aconnect._useAccounts: #p = Process(target=self.ec2Define,args=(current,aconnect,unit,name)) if pools == 0: newobjs, row = ec2Define(unit, name) else: getit = p.apply_async(ec2Define, (unit, name, q)) #getit.get() lfound.append(name) #newobjs,row = ec2Define(current,aconnect,unit,name) #objs = objs+newobjs #rows.append(row) else: #print itemlist lfound = [unit['Name'] for unit in itemlist] results = p.map(ec2Define, (unit for unit in itemlist)) if pools > 0: p.close() p.join() print results if threaded: for que in results: newobjs, row = que #print ' compute --got[C] result', row objs = objs + newobjs rows.append(row) else: while not q.empty(): newobjs, row = q.get() objs = objs + newobjs #print row #print newobjs rows.append(row) return (lfound, objs, rows)
def printcolor(self, msg): if not self._ansible: printColor(msg)