Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Implement DirectConnectGateway status check
Browse files Browse the repository at this point in the history
  • Loading branch information
rdelcampog committed May 4, 2020
1 parent 6c0018a commit 0e1ca01
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions aws-dx-monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@

# The 'live' handler - from scheduler
def lambda_handler ( event, context ):
ver_vistate ( dxclient.describe_virtual_interfaces() )
ver_cstate ( dxclient.describe_connections() )
ver_vpgstate ( dxclient.describe_virtual_gateways() )
ver_vistate ( dxclient.describe_virtual_interfaces() )
ver_cstate ( dxclient.describe_connections() )
ver_vpgstate ( dxclient.describe_virtual_gateways() )
ver_dxgwstate ( dxclient.describe_direct_connect_gateways() )
# Only DX Service Providers can make this call without an
# exception
#
Expand Down Expand Up @@ -77,6 +78,16 @@ def ver_vpgstate( data ):
# Lookup int value in VGW enum
VirtualGatewayState[vpg['virtualGatewayState']].value )

# direct connect gateway payload evaluation
def ver_dxgwstate( data ):
if not 'directConnectGateways' in data:
logger.error("unexpected: directConnectGateways key not found in data")
return
for dxgw in data['directConnectGateways']:
put_vpgstate( dxgw['directConnectGatewayId'],
# Lookup int value in DXGW enum
DirectConnectGatewayState[dxgw['directConnectGatewayState']].value )

# Writes VirtualInterfaceState dimension data to DX custom metric
def put_vistate ( iid, state ):
response = cwclient.put_metric_data(
Expand Down Expand Up @@ -153,6 +164,25 @@ def put_vpgstate ( iid, state ):
],
)

# Writes DXGW dimension data to DX custom metric
def put_vpgstate ( iid, state ):
response = cwclient.put_metric_data(
Namespace='AWSx/DirectConnect',
MetricData=[
{
'MetricName': 'DirectConnectGatewayState',
'Dimensions': [
{
'Name': 'DirectConnectGatewayId',
'Value': iid
},
],
'Value': state,
'Unit': 'None'
},
],
)


class VirtualInterfaceState(Enum):
confirming = 1
Expand Down Expand Up @@ -187,3 +217,9 @@ class VirtualGatewayState(Enum):
available = 2
deleting = 3
deleted = 4

class DirectConnectGatewayState(Enum):
pending = 1
available = 2
deleting = 3
deleted = 4

0 comments on commit 0e1ca01

Please sign in to comment.