Path: blob/develop/awscli/customizations/configservice/getstatus.py
1567 views
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import sys1314from awscli.customizations.commands import BasicCommand15from awscli.utils import create_nested_client1617def register_get_status(cli):18cli.register('building-command-table.configservice', add_get_status)192021def add_get_status(command_table, session, **kwargs):22command_table['get-status'] = GetStatusCommand(session)232425class GetStatusCommand(BasicCommand):26NAME = 'get-status'27DESCRIPTION = ('Reports the status of all of configuration '28'recorders and delivery channels.')2930def __init__(self, session):31self._config_client = None32super(GetStatusCommand, self).__init__(session)3334def _run_main(self, parsed_args, parsed_globals):35self._setup_client(parsed_globals)36self._check_configuration_recorders()37self._check_delivery_channels()38return 03940def _setup_client(self, parsed_globals):41client_args = {42'verify': parsed_globals.verify_ssl,43'region_name': parsed_globals.region,44'endpoint_url': parsed_globals.endpoint_url45}46self._config_client = create_nested_client(self._session, 'config',47**client_args)4849def _check_configuration_recorders(self):50status = self._config_client.describe_configuration_recorder_status()51sys.stdout.write('Configuration Recorders:\n\n')52for configuration_recorder in status['ConfigurationRecordersStatus']:53self._check_configure_recorder_status(configuration_recorder)54sys.stdout.write('\n')5556def _check_configure_recorder_status(self, configuration_recorder):57# Get the name of the recorder and print it out.58name = configuration_recorder['name']59sys.stdout.write('name: %s\n' % name)6061# Get the recording status and print it out.62recording = configuration_recorder['recording']63recording_map = {False: 'OFF', True: 'ON'}64sys.stdout.write('recorder: %s\n' % recording_map[recording])6566# If the recorder is on, get the last status and print it out.67if recording:68self._check_last_status(configuration_recorder)6970def _check_delivery_channels(self):71status = self._config_client.describe_delivery_channel_status()72sys.stdout.write('Delivery Channels:\n\n')73for delivery_channel in status['DeliveryChannelsStatus']:74self._check_delivery_channel_status(delivery_channel)75sys.stdout.write('\n')7677def _check_delivery_channel_status(self, delivery_channel):78# Get the name of the delivery channel and print it out.79name = delivery_channel['name']80sys.stdout.write('name: %s\n' % name)8182# Obtain the various delivery statuses.83stream_delivery = delivery_channel['configStreamDeliveryInfo']84history_delivery = delivery_channel['configHistoryDeliveryInfo']85snapshot_delivery = delivery_channel['configSnapshotDeliveryInfo']8687# Print the statuses out if they exist.88if stream_delivery:89self._check_last_status(stream_delivery, 'stream delivery ')90if history_delivery:91self._check_last_status(history_delivery, 'history delivery ')92if snapshot_delivery:93self._check_last_status(snapshot_delivery, 'snapshot delivery ')9495def _check_last_status(self, status, status_name=''):96last_status = status['lastStatus']97sys.stdout.write('last %sstatus: %s\n' % (status_name, last_status))98if last_status == "FAILURE":99sys.stdout.write('error code: %s\n' % status['lastErrorCode'])100sys.stdout.write('message: %s\n' % status['lastErrorMessage'])101102103