@@ -21,3 +21,84 @@ def run(self):
21
21
except Exception as e :
22
22
message = "There is no VpcID \" {0}\" in region {1}.\n Error {2}" .format (self .vpc_options .vpc_id , self .vpc_options .region_name , str (e ))
23
23
exit_critical (message )
24
+
25
+ class INTERNETGATEWAY (object ):
26
+
27
+ def __init__ (self , vpc_options : VpcOptions ):
28
+ self .vpc_options = vpc_options
29
+
30
+ def run (self ):
31
+
32
+ try :
33
+ client = self .vpc_options .client ('ec2' )
34
+
35
+ filters = [{'Name' : 'attachment.vpc-id' ,
36
+ 'Values' : [self .vpc_options .vpc_id ]}]
37
+
38
+ response = client .describe_internet_gateways (Filters = filters )
39
+
40
+ message_handler ("\n Checking INTERNET GATEWAYS..." , "HEADER" )
41
+
42
+ """ One VPC has only 1 IGW then it's a direct check """
43
+ if len (response ["InternetGateways" ]) == 0 :
44
+ message_handler ("Found 0 Internet Gateway in region {0}" .format (self .vpc_options .region_name ), "OKBLUE" )
45
+ else :
46
+
47
+ found = 1
48
+
49
+ message = "\n InternetGatewayId: {} -> VPC id {}" .format (
50
+ response ['InternetGateways' ][0 ]['InternetGatewayId' ],
51
+ self .vpc_options .vpc_id
52
+ )
53
+
54
+ message_handler ("Found {0} Internet Gateway using VPC {1} {2}" .format (str (found ), \
55
+ self .vpc_options .vpc_id , message ), \
56
+ 'OKBLUE' )
57
+
58
+ except Exception as e :
59
+ message = "Can't list Internet Gateway\n Error {0}" .format (str (e ))
60
+ exit_critical (message )
61
+
62
+
63
+ class NATGATEWAY (object ):
64
+
65
+ def __init__ (self , vpc_options : VpcOptions ):
66
+ self .vpc_options = vpc_options
67
+
68
+ def run (self ):
69
+
70
+ try :
71
+ client = self .vpc_options .client ('ec2' )
72
+
73
+ filters = [{'Name' : 'vpc-id' ,
74
+ 'Values' : [self .vpc_options .vpc_id ]}]
75
+
76
+ response = client .describe_nat_gateways (Filters = filters )
77
+
78
+ message_handler ("\n Checking NAT GATEWAYS..." , "HEADER" )
79
+
80
+ if len (response ["NatGateways" ]) == 0 :
81
+ message_handler ("Found 0 NAT Gateways in region {0}" .format (self .vpc_options .region_name ), "OKBLUE" )
82
+ else :
83
+
84
+ found = 0
85
+ message = ""
86
+
87
+ for data in response ["NatGateways" ]:
88
+
89
+ if data ['VpcId' ] == self .vpc_options .vpc_id :
90
+
91
+ found += 1
92
+ message = message + "\n NatGatewayId: {} -> VPC id {}" .format (
93
+ data ['NatGatewayId' ],
94
+ self .vpc_options .vpc_id
95
+ )
96
+
97
+ message_handler ("Found {0} NAT Gateways using VPC {1} {2}" .format (str (found ), self .vpc_options .vpc_id , message ),'OKBLUE' )
98
+
99
+ except Exception as e :
100
+ message = "Can't list NAT Gateways\n Error {0}" .format (str (e ))
101
+ exit_critical (message )
102
+
103
+ """ alias """
104
+ IGW = INTERNETGATEWAY
0 commit comments