def add_checks(params):
    for name, idx in sorted(params['ports'].items()):
        log.msgnb("Adding port %s..." % name)
        check_bundle = {
            "brokers": [ "/broker/%s" % params['broker'] ],
            "config": {
                "community": params['community'],
                "port": params['snmp_port']
            },
            "display_name" : "%s port %s interface stats" % (
                        params['friendly_name'], name),
            "metrics": [],
            "period": 60,
            "status": "active",
            "target": params['target'],
            "timeout": 10,
            "type": "snmp"
        }

        for m in metrics:
            check_bundle["metrics"].append(m)
            check_bundle['config']["oid_%s" % m['name']] = "%s.%s" % (
                    oids[m['name']], idx)

        try:
            api.add_check_bundle(check_bundle)
            log.msgnf("Success")
        except circonusapi.CirconusAPIError, e:
            log.msgnf("Failed")
            log.error(e)
Beispiel #2
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 #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 add_checks(params):
    for name, idx in sorted(params['ports'].items()):
        log.msgnb("Adding port %s..." % name)
        check_bundle = {
            "brokers": ["/broker/%s" % params['broker']],
            "config": {
                "community": params['community'],
                "port": params['snmp_port']
            },
            "display_name":
            "%s port %s interface stats" % (params['friendly_name'], name),
            "metrics": [],
            "period":
            60,
            "status":
            "active",
            "target":
            params['target'],
            "timeout":
            10,
            "type":
            "snmp"
        }

        for m in metrics:
            check_bundle["metrics"].append(m)
            check_bundle['config']["oid_%s" %
                                   m['name']] = "%s.%s" % (oids[m['name']],
                                                           idx)

        try:
            api.add_check_bundle(check_bundle)
            log.msgnf("Success")
        except circonusapi.CirconusAPIError, e:
            log.msgnf("Failed")
            log.error(e)
        processed = t.sub(merged_params)
        to_add.append(processed)
    log.msg("Adding the following:")
    # Mapping of endpoints to which attribute is used as a friendly name
    # TODO - add this as a library function?
    title_fields = {
        "/graph": "title",
        "/check_bundle": "display_name",
        "/rule_set": "metric_name",
        "/worksheet": "description",
        "/template": "name",
        "/contact_group": "name",
        "/account": "name",
        "/broker": "_name",
        "/user": "******"
    }
    for r in to_add:
        field = title_fields[r['_cid']]
        log.msg(r[field])
    if util.confirm("%s additions to be made. Continue?" % len(to_add)):
        for r in to_add:
            field = title_fields[r['_cid']]
            log.msgnb("Adding entry %s..." % r[field])
            try:
                api.api_call("POST", r['_cid'], r)
            except circonusapi.CirconusAPIError, e:
                log.msgnf("Failed")
                log.error(e)
                continue
            log.msgnf("Success")
Beispiel #6
0
            log.error(e)

if __name__ == '__main__':
    args = parse_options()
    if options['debug']:
        log.debug_enabled = True
    if len(args) < 2:
        usage()
        sys.exit(2)
    api = get_api()
    pattern = args[0]
    tags = args[1:]

    for t in tags:
        if ':' not in t:
            log.error("Tag '%s' should be of the form category:tag" % t)
            sys.exit(1)

    # What field to search on for a given resource type
    search_fields = {
        'check_bundle': 'display_name',
        'graph': 'title',
        'worksheet': 'title'
    }
    # Default to 'title' as a guess for unknown resource types
    search_field = search_fields.get(options['endpoint'], 'title')
    resources = get_matching_resources(api, search_field, pattern)
    log.msg("Matching resources:")
    for r in resources:
        print "    %5s: %s" % (r['_cid'], r[search_field])
    if util.confirm("Do you want to tag these resources with: %s?" % (
Beispiel #7
0

if __name__ == '__main__':
    args = parse_options()
    if options['debug']:
        log.debug_enabled = True
    if len(args) < 2:
        usage()
        sys.exit(2)
    api = get_api()
    pattern = args[0]
    tags = args[1:]

    for t in tags:
        if ':' not in t:
            log.error("Tag '%s' should be of the form category:tag" % t)
            sys.exit(1)

    # What field to search on for a given resource type
    search_fields = {
        'check_bundle': 'display_name',
        'graph': 'title',
        'worksheet': 'title'
    }
    # Default to 'title' as a guess for unknown resource types
    search_field = search_fields.get(options['endpoint'], 'title')
    resources = get_matching_resources(api, search_field, pattern)
    log.msg("Matching resources:")
    for r in resources:
        print "    %5s: %s" % (r['_cid'], r[search_field])
    if util.confirm("Do you want to tag these resources with: %s?" %
        else:
            to_add.append(processed)
    log.msg("Adding the following:")
    # Mapping of endpoints to which attribute is used as a friendly name
    # TODO - add this as a library function?
    title_fields = {
        "/graph": "title",
        "/check_bundle": "display_name",
        "/rule_set": "metric_name",
        "/worksheet": "description",
        "/template": "name",
        "/contact_group": "name",
        "/account": "name",
        "/broker": "_name",
        "/user": "******"
    }
    for r in to_add:
        field = title_fields[r['_cid']]
        log.msg(r[field])
    if util.confirm("%s additions to be made. Continue?" % len(to_add)):
        for r in to_add:
            field = title_fields[r['_cid']]
            log.msgnb("Adding entry %s..." % r[field])
            try:
                api.api_call("POST", r['_cid'], r)
            except circonusapi.CirconusAPIError, e:
                log.msgnf("Failed")
                log.error(e)
                continue
            log.msgnf("Success")