1
1
from shared .common import *
2
2
import json
3
+ from shared .error_handler import exception
3
4
4
5
class ELASTICSEARCH (object ):
5
6
6
7
def __init__ (self , vpc_options : VpcOptions ):
7
8
self .vpc_options = vpc_options
8
9
10
+ @exception
9
11
def run (self ):
10
- try :
11
- client = self .vpc_options .client ('es' )
12
-
13
- response = client .list_domain_names ()
14
-
15
- message_handler ("\n Checking ELASTICSEARCH DOMAINS..." , "HEADER" )
16
12
17
- if len (response ["DomainNames" ]) == 0 :
18
- message_handler ("Found 0 Elastic Search Domains in region {0}" .format (self .vpc_options .region_name ), "OKBLUE" )
19
- else :
20
- found = 0
21
- message = ""
22
- for data in response ["DomainNames" ]:
13
+ client = self .vpc_options .client ('es' )
14
+
15
+ response = client .list_domain_names ()
16
+
17
+ message_handler ("\n Checking ELASTICSEARCH DOMAINS..." , "HEADER" )
23
18
24
- elasticsearch_domain = client .describe_elasticsearch_domain (DomainName = data ['DomainName' ])
19
+ if len (response ["DomainNames" ]) == 0 :
20
+ message_handler ("Found 0 Elastic Search Domains in region {0}" .format (self .vpc_options .region_name ), "OKBLUE" )
21
+ else :
22
+ found = 0
23
+ message = ""
24
+ for data in response ["DomainNames" ]:
25
25
26
- documentpolicy = elasticsearch_domain [ 'DomainStatus' ][ 'AccessPolicies' ]
26
+ elasticsearch_domain = client . describe_elasticsearch_domain ( DomainName = data [ 'DomainName' ])
27
27
28
- document = json . dumps ( documentpolicy , default = datetime_to_string )
28
+ documentpolicy = elasticsearch_domain [ 'DomainStatus' ][ 'AccessPolicies' ]
29
29
30
- """ check either vpc_id or potencial subnet ip are found """
31
- ipvpc_found = check_ipvpc_inpolicy (document = document , vpc_options = self .vpc_options )
30
+ document = json .dumps (documentpolicy , default = datetime_to_string )
32
31
33
- """ elasticsearch uses accesspolicies too, so check both situation """
34
- if elasticsearch_domain ['DomainStatus' ]['VPCOptions' ]['VPCId' ] == self .vpc_options .vpc_id \
35
- or ipvpc_found is True :
36
- found += 1
37
- message = message + "\n DomainId: {0} - DomainName: {1} - VpcId {2}" .format (
38
- elasticsearch_domain ['DomainStatus' ]['DomainId' ],
39
- elasticsearch_domain ['DomainStatus' ]['DomainName' ],
40
- self .vpc_options .vpc_id
41
- )
42
- message_handler ("Found {0} ElasticSearch Domains using VPC {1} {2}" .format (str (found ), self .vpc_options .vpc_id , message ),'OKBLUE' )
43
-
44
- except Exception as e :
45
- message = "Can't list ElasticSearch Domains\n Error {0}" .format (str (e ))
46
- exit_critical (message )
32
+ """ check either vpc_id or potencial subnet ip are found """
33
+ ipvpc_found = check_ipvpc_inpolicy (document = document , vpc_options = self .vpc_options )
34
+
35
+ """ elasticsearch uses accesspolicies too, so check both situation """
36
+ if elasticsearch_domain ['DomainStatus' ]['VPCOptions' ]['VPCId' ] == self .vpc_options .vpc_id \
37
+ or ipvpc_found is True :
38
+ found += 1
39
+ message = message + "\n DomainId: {0} - DomainName: {1} - VpcId {2}" .format (
40
+ elasticsearch_domain ['DomainStatus' ]['DomainId' ],
41
+ elasticsearch_domain ['DomainStatus' ]['DomainName' ],
42
+ self .vpc_options .vpc_id
43
+ )
44
+ message_handler ("Found {0} ElasticSearch Domains using VPC {1} {2}" .format (str (found ), self .vpc_options .vpc_id , message ),'OKBLUE' )
45
+
46
+ return True
47
47
48
48
class MSK (object ):
49
49
50
50
def __init__ (self , vpc_options : VpcOptions ):
51
51
self .vpc_options = vpc_options
52
52
53
+ @exception
53
54
def run (self ):
54
- try :
55
- client = self .vpc_options .client ('kafka' )
56
55
57
- """ get all cache clusters """
58
- response = client .list_clusters ()
56
+ client = self .vpc_options .client ('kafka' )
57
+
58
+ """ get all cache clusters """
59
+ response = client .list_clusters ()
59
60
60
- message_handler ("\n Checking MSK CLUSTERS..." , "HEADER" )
61
+ message_handler ("\n Checking MSK CLUSTERS..." , "HEADER" )
61
62
62
- if len (response ['ClusterInfoList' ]) == 0 :
63
- message_handler ("Found 0 MSK Clusters in region {0}" .format (self .vpc_options .region_name ), "OKBLUE" )
64
- else :
65
- found = 0
66
- message = ""
63
+ if len (response ['ClusterInfoList' ]) == 0 :
64
+ message_handler ("Found 0 MSK Clusters in region {0}" .format (self .vpc_options .region_name ), "OKBLUE" )
65
+ else :
66
+ found = 0
67
+ message = ""
67
68
68
- """ iterate cache clusters to get subnet groups """
69
- for data in response ['ClusterInfoList' ]:
69
+ """ iterate cache clusters to get subnet groups """
70
+ for data in response ['ClusterInfoList' ]:
70
71
71
- msk_subnets = ", " .join (data ['BrokerNodeGroupInfo' ]['ClientSubnets' ])
72
+ msk_subnets = ", " .join (data ['BrokerNodeGroupInfo' ]['ClientSubnets' ])
72
73
73
- ec2 = self .vpc_options .session .resource ('ec2' , region_name = self .vpc_options .region_name )
74
+ ec2 = self .vpc_options .session .resource ('ec2' , region_name = self .vpc_options .region_name )
74
75
75
- filters = [{'Name' :'vpc-id' ,
76
- 'Values' :[self .vpc_options .vpc_id ]}]
76
+ filters = [{'Name' :'vpc-id' ,
77
+ 'Values' :[self .vpc_options .vpc_id ]}]
77
78
78
- subnets = ec2 .subnets .filter (Filters = filters )
79
+ subnets = ec2 .subnets .filter (Filters = filters )
79
80
80
- for subnet in list (subnets ):
81
+ for subnet in list (subnets ):
81
82
82
- if subnet .id in msk_subnets :
83
+ if subnet .id in msk_subnets :
83
84
84
- found += 1
85
- message = message + "\n ClusterName: {0} - VpcId: {1}" .format (
86
- data ['ClusterName' ],
87
- self .vpc_options .vpc_id
88
- )
89
- break
85
+ found += 1
86
+ message = message + "\n ClusterName: {0} - VpcId: {1}" .format (
87
+ data ['ClusterName' ],
88
+ self .vpc_options .vpc_id
89
+ )
90
+ break
90
91
91
- message_handler ("Found {0} MSK Clusters using VPC {1} {2}" .format (str (found ), self .vpc_options .vpc_id , message ),'OKBLUE' )
92
+ message_handler ("Found {0} MSK Clusters using VPC {1} {2}" .format (str (found ), self .vpc_options .vpc_id , message ),'OKBLUE' )
92
93
93
- except Exception as e :
94
- message = "Can't list MSK Clusters\n Error {0}" .format (str (e ))
95
- exit_critical (message )
94
+ return True
0 commit comments