def PublishConfigStatustoCloudwatchforEveryRegion()

in awsconfigstatuscheck-app/aws_config_status_check/WorkerFunction.py [0:0]


    def PublishConfigStatustoCloudwatchforEveryRegion(self):

        for self.region in self.regions:

            awsconfig = boto3.client(
                'config',
                aws_access_key_id=self.ACCESS_KEY,
                aws_secret_access_key=self.SECRET_KEY,
                aws_session_token=self.SESSION_TOKEN,
                region_name=self.region,
                config=self.config
            )
            self.config_recorder_response = awsconfig.describe_configuration_recorder_status()
            print("region:", self.region)
            response = self.config_recorder_response["ConfigurationRecordersStatus"]
            print("len of response", len(response))
            if len(response) > 0:
                index = 0
                self.AWSConfigRecordersTotal += 1
                print("Value of recording:",
                        response[index]['recording'])
                if response[index]['recording'] == True:
                    print("SUCCESS: {}".format(response))
                    print("SUCCESS: {}".format(
                        response[index]['lastStatus']))
                    print("PUBLISHING SUCCESS")
                    self.AWSConfigRecordersEnabled += 1
                    response = self.cloudwatch.put_metric_data(
                        MetricData=[
                            {
                                'MetricName': 'AWSConfigRecordersStatusFlag',
                                'Dimensions': [
                                    {
                                    'Name': "AccountId",
                                    'Value': self.accountid
                                },
                                    {
                                    'Name': "Region",
                                    'Value': self.region
                                },
                                    ],
                                'Value': 1
                            },
                        ],
                        Namespace='AWSConfigStatus'
                    )
                else:
                    print("PUBLISHING FAILURE")
                    response = self.cloudwatch.put_metric_data(
                        MetricData=[
                            {
                                'MetricName': 'AWSConfigRecordersStatusFlag',
                                'Dimensions': [
                                    {
                                    'Name': "AccountId",
                                    'Value': self.accountid
                                    },
                                    {
                                    'Name': "Region",
                                    'Value': self.region
                                    },
                                ],
                                'Value': 0
                            },
                        ],
                        Namespace='AWSConfigStatus'
                    )

        print("PUBLISHING SUMMARY")
        cloudwatch = boto3.client(
            'cloudwatch', config=self.config, region_name='us-east-1')
        response = cloudwatch.put_metric_data(
            MetricData=[
                {
                    'MetricName': 'TotalAWSConfigRecordersEnabled',
                    'Dimensions': [
                        {
                        'Name': "AccountId",
                        'Value': self.accountid
                        }
                    ],
                    'Value': self.AWSConfigRecordersTotal
                }
            ],
            Namespace='AWSConfigStatus'
        )
        response = cloudwatch.put_metric_data(
            MetricData=[
                {
                    'MetricName': 'TotalRegions',
                    'Dimensions': [
                        {
                        'Name': "AccountId",
                        'Value': self.accountid
                        }
                    ],
                    'Value': len(self.regions)
                }
            ],
            Namespace='AWSConfigStatus'
        )
        response = self.cloudwatch.put_metric_data(
            MetricData=[
                {
                    'MetricName': 'AWSConfigRecordersRunning',
                    'Dimensions': [
                        {
                        'Name': "AccountId",
                        'Value': self.accountid
                        }
                    ],
                    'Value': self.AWSConfigRecordersEnabled
                }
            ],
            Namespace='AWSConfigStatus'
        )