1
- import boto3
2
- from shared . common import *
1
+ from shared . common import *
2
+
3
3
4
4
class RDS (object ):
5
5
6
- def __init__ (self , vpc_id , region_name ):
7
- self .vpc_id = vpc_id
8
- self .region_name = region_name
9
-
6
+ def __init__ (self , vpc_options : VpcOptions ):
7
+ self .vpc_options = vpc_options
8
+
10
9
def run (self ):
11
10
try :
12
- client = boto3 . client ('rds' , region_name = self .region_name )
11
+ client = self . vpc_options . session . client ('rds' , region_name = self . vpc_options .region_name )
13
12
14
13
response = client .describe_db_instances ()
15
14
16
15
message_handler ("\n Checking RDS INSTANCES..." , "HEADER" )
17
16
18
- if ( len (response ["DBInstances" ]) == 0 ) :
19
- message_handler ("Found 0 RDS Instances in region {0}" .format (self .region_name ), "OKBLUE" )
17
+ if len (response ["DBInstances" ]) == 0 :
18
+ message_handler ("Found 0 RDS Instances in region {0}" .format (self .vpc_options . region_name ), "OKBLUE" )
20
19
else :
21
20
found = 0
22
21
message = ""
23
22
for data in response ["DBInstances" ]:
24
- if ( data ['DBSubnetGroup' ]['VpcId' ] == self .vpc_id ) :
23
+ if data ['DBSubnetGroup' ]['VpcId' ] == self .vpc_options . vpc_id :
25
24
found += 1
26
25
message = message + "\n DBInstanceIdentifier: {0} - Engine: {1} - VpcId {2}" .format (
27
26
data ["DBInstanceIdentifier" ],
28
27
data ["Engine" ],
29
28
data ['DBSubnetGroup' ]['VpcId' ]
30
29
)
31
- message_handler ("Found {0} RDS Instances using VPC {1} {2}" .format (str (found ), self .vpc_id , message ),'OKBLUE' )
32
-
33
-
30
+ message_handler ("Found {0} RDS Instances using VPC {1} {2}" .format (str (found ), self .vpc_options .vpc_id , message ),'OKBLUE' )
34
31
except Exception as e :
35
32
message = "Can't list RDS Instances\n Error {0}" .format (str (e ))
36
33
exit_critical (message )
37
34
35
+
38
36
class ELASTICACHE (object ):
39
37
40
- def __init__ (self , vpc_id , region_name ):
41
- self .vpc_id = vpc_id
42
- self .region_name = region_name
43
-
38
+ def __init__ (self , vpc_options : VpcOptions ):
39
+ self .vpc_options = vpc_options
40
+
44
41
def run (self ):
45
42
try :
46
- client = boto3 . client ('elasticache' , region_name = self .region_name )
43
+ client = self . vpc_options . session . client ('elasticache' , region_name = self . vpc_options .region_name )
47
44
48
45
""" get all cache clusters """
49
46
response = client .describe_cache_clusters ()
50
47
51
48
message_handler ("\n Checking ELASTICACHE CLUSTERS..." , "HEADER" )
52
49
53
- if ( len (response ['CacheClusters' ]) == 0 ) :
54
- message_handler ("Found 0 Elasticache Clusters in region {0}" .format (self .region_name ), "OKBLUE" )
50
+ if len (response ['CacheClusters' ]) == 0 :
51
+ message_handler ("Found 0 Elasticache Clusters in region {0}" .format (self .vpc_options . region_name ), "OKBLUE" )
55
52
else :
56
53
found = 0
57
54
message = ""
@@ -61,17 +58,15 @@ def run(self):
61
58
62
59
cachesubnet = client .describe_cache_subnet_groups (CacheSubnetGroupName = data ['CacheSubnetGroupName' ])
63
60
64
- if ( cachesubnet ['CacheSubnetGroups' ][0 ]['VpcId' ] == self .vpc_id ) :
61
+ if cachesubnet ['CacheSubnetGroups' ][0 ]['VpcId' ] == self .vpc_options . vpc_id :
65
62
found += 1
66
63
message = message + "\n CacheClusterId: {0} - CacheSubnetGroupName: {1} - Engine: {2} - VpcId: {3}" .format (
67
64
data ["CacheClusterId" ],
68
65
data ["CacheSubnetGroupName" ],
69
66
data ["Engine" ],
70
67
cachesubnet ['CacheSubnetGroups' ][0 ]['VpcId' ]
71
68
)
72
- message_handler ("Found {0} Elasticache Clusters using VPC {1} {2}" .format (str (found ), self .vpc_id , message ),'OKBLUE' )
73
-
74
-
69
+ message_handler ("Found {0} Elasticache Clusters using VPC {1} {2}" .format (str (found ), self .vpc_options .vpc_id , message ),'OKBLUE' )
75
70
except Exception as e :
76
71
message = "Can't list Elasticache Clusters\n Error {0}" .format (str (e ))
77
72
exit_critical (message )
0 commit comments