Esempio n. 1
0
 def wait_for_config(self, session, queue_url, resource_id):
     # lazy import to avoid circular
     from c7n.sqsexec import MessageIterator
     client = session.client('sqs')
     messages = MessageIterator(client, queue_url, timeout=20)
     results = []
     while True:
         for m in messages:
             msg = json.loads(m['Body'])
             change = json.loads(msg['Message'])
             messages.ack(m)
             if change['configurationItem']['resourceId'] != resource_id:
                 continue
             results.append(change['configurationItem'])
             break
         if results:
             break
     return results
Esempio n. 2
0
    def wait_for_config(self, session, queue_url, resource_id=None):
        # lazy import to avoid circular
        from c7n.sqsexec import MessageIterator

        client = session.client("sqs")
        messages = MessageIterator(client, queue_url, timeout=20)
        results = []
        while True:
            for m in messages:
                msg = json.loads(m["Body"])
                change = json.loads(msg["Message"])
                messages.ack(m)
                if resource_id and change["configurationItem"][
                        "resourceId"] != resource_id:
                    continue
                results.append(change["configurationItem"])
                break
            if results:
                break
        return results
Esempio n. 3
0
def worker_config(queue, s3_key, period, verbose):
    """daemon queue worker for config notifications"""
    logging.basicConfig(level=(verbose and logging.DEBUG or logging.INFO))
    logging.getLogger('botocore').setLevel(logging.WARNING)
    logging.getLogger('s3transfer').setLevel(logging.WARNING)

    queue, region = get_queue(queue)
    factory = SessionFactory(region)
    session = factory()
    client = session.client('sqs')
    messages = MessageIterator(client, queue, timeout=20)

    for m in messages:
        msg = unwrap(m)
        if 'configurationItemSummary' in msg:
            rtype = msg['configurationItemSummary']['resourceType']
        else:
            rtype = msg['configurationItem']['resourceType']
        if rtype not in RESOURCE_MAPPING.values():
            log.info("skipping %s" % rtype)
            messages.ack(m)
        log.info("message received %s", m)
Esempio n. 4
0
def worker_config(queue, s3_key, period, verbose):
    """daemon queue worker for config notifications"""
    logging.basicConfig(level=(verbose and logging.DEBUG or logging.INFO))
    logging.getLogger('botocore').setLevel(logging.WARNING)
    logging.getLogger('s3transfer').setLevel(logging.WARNING)

    queue, region = get_queue(queue)
    factory = SessionFactory(region)
    session = factory()
    client = session.client('sqs')
    messages = MessageIterator(client, queue, timeout=20)

    for m in messages:
        msg = unwrap(m)
        if 'configurationItemSummary' in msg:
            rtype = msg['configurationItemSummary']['resourceType']
        else:
            rtype = msg['configurationItem']['resourceType']
        if rtype not in RESOURCE_MAPPING.values():
            log.info("skipping %s" % rtype)
            messages.ack(m)
        log.info("message received %s", m)