Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/configservice/getstatus.py
1567 views
1
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import sys
14
15
from awscli.customizations.commands import BasicCommand
16
from awscli.utils import create_nested_client
17
18
def register_get_status(cli):
19
cli.register('building-command-table.configservice', add_get_status)
20
21
22
def add_get_status(command_table, session, **kwargs):
23
command_table['get-status'] = GetStatusCommand(session)
24
25
26
class GetStatusCommand(BasicCommand):
27
NAME = 'get-status'
28
DESCRIPTION = ('Reports the status of all of configuration '
29
'recorders and delivery channels.')
30
31
def __init__(self, session):
32
self._config_client = None
33
super(GetStatusCommand, self).__init__(session)
34
35
def _run_main(self, parsed_args, parsed_globals):
36
self._setup_client(parsed_globals)
37
self._check_configuration_recorders()
38
self._check_delivery_channels()
39
return 0
40
41
def _setup_client(self, parsed_globals):
42
client_args = {
43
'verify': parsed_globals.verify_ssl,
44
'region_name': parsed_globals.region,
45
'endpoint_url': parsed_globals.endpoint_url
46
}
47
self._config_client = create_nested_client(self._session, 'config',
48
**client_args)
49
50
def _check_configuration_recorders(self):
51
status = self._config_client.describe_configuration_recorder_status()
52
sys.stdout.write('Configuration Recorders:\n\n')
53
for configuration_recorder in status['ConfigurationRecordersStatus']:
54
self._check_configure_recorder_status(configuration_recorder)
55
sys.stdout.write('\n')
56
57
def _check_configure_recorder_status(self, configuration_recorder):
58
# Get the name of the recorder and print it out.
59
name = configuration_recorder['name']
60
sys.stdout.write('name: %s\n' % name)
61
62
# Get the recording status and print it out.
63
recording = configuration_recorder['recording']
64
recording_map = {False: 'OFF', True: 'ON'}
65
sys.stdout.write('recorder: %s\n' % recording_map[recording])
66
67
# If the recorder is on, get the last status and print it out.
68
if recording:
69
self._check_last_status(configuration_recorder)
70
71
def _check_delivery_channels(self):
72
status = self._config_client.describe_delivery_channel_status()
73
sys.stdout.write('Delivery Channels:\n\n')
74
for delivery_channel in status['DeliveryChannelsStatus']:
75
self._check_delivery_channel_status(delivery_channel)
76
sys.stdout.write('\n')
77
78
def _check_delivery_channel_status(self, delivery_channel):
79
# Get the name of the delivery channel and print it out.
80
name = delivery_channel['name']
81
sys.stdout.write('name: %s\n' % name)
82
83
# Obtain the various delivery statuses.
84
stream_delivery = delivery_channel['configStreamDeliveryInfo']
85
history_delivery = delivery_channel['configHistoryDeliveryInfo']
86
snapshot_delivery = delivery_channel['configSnapshotDeliveryInfo']
87
88
# Print the statuses out if they exist.
89
if stream_delivery:
90
self._check_last_status(stream_delivery, 'stream delivery ')
91
if history_delivery:
92
self._check_last_status(history_delivery, 'history delivery ')
93
if snapshot_delivery:
94
self._check_last_status(snapshot_delivery, 'snapshot delivery ')
95
96
def _check_last_status(self, status, status_name=''):
97
last_status = status['lastStatus']
98
sys.stdout.write('last %sstatus: %s\n' % (status_name, last_status))
99
if last_status == "FAILURE":
100
sys.stdout.write('error code: %s\n' % status['lastErrorCode'])
101
sys.stdout.write('message: %s\n' % status['lastErrorMessage'])
102
103