-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from leandrodamascena/developer
Developer to master
- Loading branch information
Showing
13 changed files
with
858 additions
and
616 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import functools | ||
from shared.common import * | ||
|
||
def exception(func): | ||
""" | ||
Decorator to catch exceptions and avoid stop script | ||
""" | ||
@functools.wraps(func) | ||
def wrapper(*args, **kwargs): | ||
try: | ||
return func(*args, **kwargs) | ||
except Exception as e: | ||
message = "\nError running check {}. Error message {}".format(func.__qualname__, str(e)) | ||
log_critical(message) | ||
pass | ||
return wrapper |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,94 @@ | ||
from shared.common import * | ||
import json | ||
from shared.error_handler import exception | ||
|
||
class ELASTICSEARCH(object): | ||
|
||
def __init__(self, vpc_options: VpcOptions): | ||
self.vpc_options = vpc_options | ||
|
||
@exception | ||
def run(self): | ||
try: | ||
client = self.vpc_options.client('es') | ||
|
||
response = client.list_domain_names() | ||
|
||
message_handler("\nChecking ELASTICSEARCH DOMAINS...", "HEADER") | ||
|
||
if len(response["DomainNames"]) == 0: | ||
message_handler("Found 0 Elastic Search Domains in region {0}".format(self.vpc_options.region_name), "OKBLUE") | ||
else: | ||
found = 0 | ||
message = "" | ||
for data in response["DomainNames"]: | ||
client = self.vpc_options.client('es') | ||
|
||
response = client.list_domain_names() | ||
|
||
message_handler("\nChecking ELASTICSEARCH DOMAINS...", "HEADER") | ||
|
||
elasticsearch_domain = client.describe_elasticsearch_domain(DomainName=data['DomainName']) | ||
if len(response["DomainNames"]) == 0: | ||
message_handler("Found 0 Elastic Search Domains in region {0}".format(self.vpc_options.region_name), "OKBLUE") | ||
else: | ||
found = 0 | ||
message = "" | ||
for data in response["DomainNames"]: | ||
|
||
documentpolicy = elasticsearch_domain['DomainStatus']['AccessPolicies'] | ||
elasticsearch_domain = client.describe_elasticsearch_domain(DomainName=data['DomainName']) | ||
|
||
document = json.dumps(documentpolicy, default=datetime_to_string) | ||
documentpolicy = elasticsearch_domain['DomainStatus']['AccessPolicies'] | ||
|
||
""" check either vpc_id or potencial subnet ip are found """ | ||
ipvpc_found = check_ipvpc_inpolicy(document=document, vpc_options=self.vpc_options) | ||
document = json.dumps(documentpolicy, default=datetime_to_string) | ||
|
||
""" elasticsearch uses accesspolicies too, so check both situation """ | ||
if elasticsearch_domain['DomainStatus']['VPCOptions']['VPCId'] == self.vpc_options.vpc_id \ | ||
or ipvpc_found is True: | ||
found += 1 | ||
message = message + "\nDomainId: {0} - DomainName: {1} - VpcId {2}".format( | ||
elasticsearch_domain['DomainStatus']['DomainId'], | ||
elasticsearch_domain['DomainStatus']['DomainName'], | ||
self.vpc_options.vpc_id | ||
) | ||
message_handler("Found {0} ElasticSearch Domains using VPC {1} {2}".format(str(found), self.vpc_options.vpc_id, message),'OKBLUE') | ||
|
||
except Exception as e: | ||
message = "Can't list ElasticSearch Domains\nError {0}".format(str(e)) | ||
exit_critical(message) | ||
""" check either vpc_id or potencial subnet ip are found """ | ||
ipvpc_found = check_ipvpc_inpolicy(document=document, vpc_options=self.vpc_options) | ||
|
||
""" elasticsearch uses accesspolicies too, so check both situation """ | ||
if elasticsearch_domain['DomainStatus']['VPCOptions']['VPCId'] == self.vpc_options.vpc_id \ | ||
or ipvpc_found is True: | ||
found += 1 | ||
message = message + "\nDomainId: {0} - DomainName: {1} - VpcId {2}".format( | ||
elasticsearch_domain['DomainStatus']['DomainId'], | ||
elasticsearch_domain['DomainStatus']['DomainName'], | ||
self.vpc_options.vpc_id | ||
) | ||
message_handler("Found {0} ElasticSearch Domains using VPC {1} {2}".format(str(found), self.vpc_options.vpc_id, message),'OKBLUE') | ||
|
||
return True | ||
|
||
class MSK(object): | ||
|
||
def __init__(self, vpc_options: VpcOptions): | ||
self.vpc_options = vpc_options | ||
|
||
@exception | ||
def run(self): | ||
try: | ||
client = self.vpc_options.client('kafka') | ||
|
||
""" get all cache clusters """ | ||
response = client.list_clusters() | ||
client = self.vpc_options.client('kafka') | ||
|
||
""" get all cache clusters """ | ||
response = client.list_clusters() | ||
|
||
message_handler("\nChecking MSK CLUSTERS...", "HEADER") | ||
message_handler("\nChecking MSK CLUSTERS...", "HEADER") | ||
|
||
if len(response['ClusterInfoList']) == 0: | ||
message_handler("Found 0 MSK Clusters in region {0}".format(self.vpc_options.region_name), "OKBLUE") | ||
else: | ||
found = 0 | ||
message = "" | ||
if len(response['ClusterInfoList']) == 0: | ||
message_handler("Found 0 MSK Clusters in region {0}".format(self.vpc_options.region_name), "OKBLUE") | ||
else: | ||
found = 0 | ||
message = "" | ||
|
||
""" iterate cache clusters to get subnet groups """ | ||
for data in response['ClusterInfoList']: | ||
""" iterate cache clusters to get subnet groups """ | ||
for data in response['ClusterInfoList']: | ||
|
||
msk_subnets = ", ".join(data['BrokerNodeGroupInfo']['ClientSubnets']) | ||
msk_subnets = ", ".join(data['BrokerNodeGroupInfo']['ClientSubnets']) | ||
|
||
ec2 = self.vpc_options.session.resource('ec2', region_name=self.vpc_options.region_name) | ||
ec2 = self.vpc_options.session.resource('ec2', region_name=self.vpc_options.region_name) | ||
|
||
filters = [{'Name':'vpc-id', | ||
'Values':[self.vpc_options.vpc_id]}] | ||
filters = [{'Name':'vpc-id', | ||
'Values':[self.vpc_options.vpc_id]}] | ||
|
||
subnets = ec2.subnets.filter(Filters=filters) | ||
subnets = ec2.subnets.filter(Filters=filters) | ||
|
||
for subnet in list(subnets): | ||
for subnet in list(subnets): | ||
|
||
if subnet.id in msk_subnets: | ||
if subnet.id in msk_subnets: | ||
|
||
found += 1 | ||
message = message + "\nClusterName: {0} - VpcId: {1}".format( | ||
data['ClusterName'], | ||
self.vpc_options.vpc_id | ||
) | ||
break | ||
found += 1 | ||
message = message + "\nClusterName: {0} - VpcId: {1}".format( | ||
data['ClusterName'], | ||
self.vpc_options.vpc_id | ||
) | ||
break | ||
|
||
message_handler("Found {0} MSK Clusters using VPC {1} {2}".format(str(found), self.vpc_options.vpc_id, message),'OKBLUE') | ||
message_handler("Found {0} MSK Clusters using VPC {1} {2}".format(str(found), self.vpc_options.vpc_id, message),'OKBLUE') | ||
|
||
except Exception as e: | ||
message = "Can't list MSK Clusters\nError {0}".format(str(e)) | ||
exit_critical(message) | ||
return True |
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
Oops, something went wrong.