def run_query(params, api):
    log.msg("Querying endpoint: %s" % params['endpoint'])
    results = api.api_call("GET", params['endpoint'])
    filtered_results = []
    k, v = params['filter'].split('=', 1)
    log.debug("Filter is checking that %s matches %s" % (k,v))
    for r in results:
        match = re.search(v, r[k])
        if match:
            for i, j in enumerate(match.groups()):
                # Adds group1, group2 etc. variables
                r['group%s' % (i+1)] = j
            filtered_results.append(r)

    return filtered_results
def run_query(params, api):
    log.msg("Querying endpoint: %s" % params['endpoint'])
    results = api.api_call("GET", params['endpoint'])
    filtered_results = []
    k, v = params['filter'].split('=', 1)
    log.debug("Filter is checking that %s matches %s" % (k, v))
    for r in results:
        match = re.search(v, r[k])
        if match:
            for i, j in enumerate(match.groups()):
                # Adds group1, group2 etc. variables
                r['group%s' % (i + 1)] = j
            filtered_results.append(r)

    return filtered_results
Beispiel #3
0
def tag_resources(api, resources, tags, search_field):
    log.msg("Tagging resources:")
    for r in resources:
        old_tags = set(r['tags'])
        new_tags = old_tags | set(tags)
        data = {'tags': list(new_tags)}
        # Exceptions for differnet endpoint types
        if options['endpoint'] == 'graph':
            # You have to provide title/datapoints with any graph changes
            data['title'] = r['title']
            data['datapoints'] = r['datapoints']
        log.debug("Data for %s: %s" % (r['_cid'], data))
        log.msgnb("%s: %s... " % (r['_cid'], r[search_field]))
        if old_tags == new_tags:
            log.msgnf("No change")
            continue
        try:
            api.api_call("PUT", r['_cid'], data)
            log.msgnf("Done")
        except circonusapi.CirconusAPIError, e:
            log.msgnf("Failed")
            log.error(e)
Beispiel #4
0
def tag_resources(api, resources, tags, search_field):
    log.msg("Tagging resources:")
    for r in resources:
        old_tags = set(r['tags'])
        new_tags = old_tags | set(tags)
        data = {'tags': list(new_tags)}
        # Exceptions for differnet endpoint types
        if options['endpoint'] == 'graph':
            # You have to provide title/datapoints with any graph changes
            data['title'] = r['title']
            data['datapoints'] = r['datapoints']
        log.debug("Data for %s: %s" % (r['_cid'], data))
        log.msgnb("%s: %s... " % (r['_cid'], r[search_field]))
        if old_tags == new_tags:
            log.msgnf("No change")
            continue
        try:
            api.api_call("PUT", r['_cid'], data)
            log.msgnf("Done")
        except circonusapi.CirconusAPIError, e:
            log.msgnf("Failed")
            log.error(e)