def handler()

in rules/customer-fc/ack_cluster_node_monitor_enabled.py [0:0]


def handler(event, context):
    evt = validate_event(event)
    if not evt:
        return None

    result_token = evt.get('resultToken')
    ordering_timestamp = evt.get('orderingTimestamp')
    invoking_event = evt.get('invokingEvent')
    account_id = invoking_event.get('accountId')
    # regionId = invoking_event.get('configurationItem')['regionId']
    client = AcsClient(AK, SK, CONFIG_SERVICE_REGION)
    evaluations = []
    # ResourceType supported by the config
    resource_type = "ACS::ACK::Cluster"
    # 查询集群列表并逐个校验集群检查情况
    page_number = 1
    page_size = 50
    cluster_total = 0
    while page_number == 1 or (cluster_total > page_size * page_number):
        cluster_page_json = query_cluster_page(client, page_size, page_number)
        if "clusters" in cluster_page_json and cluster_page_json["clusters"]:
            for cluster in cluster_page_json["clusters"]:
                logger.info(cluster["cluster_id"])
                compliant_result = query_nodes_evaluation(client, cluster["cluster_id"])
                if compliant_result:
                    evaluation = {
                        'accountId': account_id,
                        'complianceResourceId': cluster["cluster_id"],
                        'complianceResourceType': resource_type,
                        'orderingTimestamp': ordering_timestamp,
                        'complianceType': COMPLIANCE_TYPE_COMPLIANT,
                        'annotation': json.dumps({}),
                        'complianceRegionId': cluster["region_id"]
                    }
                    evaluations.append(evaluation)
                else:
                    evaluation = {
                        'accountId': account_id,
                        'complianceResourceId': cluster["cluster_id"],
                        'complianceResourceType': resource_type,
                        'orderingTimestamp': ordering_timestamp,
                        'complianceType': COMPLIANCE_TYPE_NON_COMPLIANT,
                        'annotation': json.dumps(
                            {'configuration': 'Not all nodes installed monitor agent.',
                             'desiredValue': 'All nodes installed monitor agent.'}),
                        'complianceRegionId': cluster["region_id"]
                    }
                    evaluations.append(evaluation)
        else:
            break

        page_number = page_number + 1
        if "page_info" in cluster_page_json and cluster_page_json["page_info"] and "total_count" \
                in cluster_page_json["page_info"] and cluster_page_json["page_info"]["total_count"]:
            cluster_total = cluster_page_json["page_info"]["total_count"]

    put_evaluations(context, result_token, evaluations)
    return evaluations