@@ -0,0 +1,2812 @@
+#!/usr/bin/env python3%0A%22%22%22manage-dashboards.py is a small Python tool for getting and creating%0Ametrics dashboards using the Datadog API. For more information, please see%0A%0A  http://docs.datadoghq.com/api/?lang=python#timeboards%0A%22%22%22%0Aimport argparse%0Aimport json%0A%0A%0Atry:%0A    from datadog import initialize, api%0Aexcept:%0A    print(%22%22%22Error: failed to import the 'datadog' module. Is it installed?%0AYou can install the 'datadog' module by running the following command:%0A%0A    pip install --upgrade datadog%0A%0A%22%22%22)%0A    exit(1)%0A%0A%0Adef create(dash_title, dash_desc, dash_file):%0A    %22%22%22Create a dashboard.%0A    %22%22%22%0A    dash_def = %7B%7D%0A    with open(dash_file) as d:%0A        dash_def = json.load(d)%0A%0A    try:%0A        dash_def%5B'dash'%5D%0A    except KeyError:%0A        print(%22Error: %7B%7D does not appear to contain a valid Datadog dashboard!%22%0A              .format(dash_file))%0A        exit(1)%0A%0A    template_variables = %5B%7B%7D%5D%0A    try:%0A        template_variables = dash_def%5B'dash'%5D%5B'template_variables'%5D%0A    except KeyError:%0A        # defaults to empty dict in empty array above%0A        pass%0A%0A    print(json.dumps(api.Timeboard.create(%0A        title=dash_title,%0A        description=dash_desc,%0A        graphs=dash_def%5B'dash'%5D%5B'graphs'%5D,%0A        template_variables=template_variables,%0A        read_only=False), indent=2))%0A%0A%0Adef get(dash_id):%0A    %22%22%22Get a dashboard.%0A    %22%22%22%0A    print(json.dumps(api.Timeboard.get(dash_id), indent=2))%0A%0A%0A# Main.%0Aif __name__ == '__main__':%0A    parser = argparse.ArgumentParser(description='Manage Datadog dashboards.')%0A    parser.add_argument('--api_key', type=str, help='API key', required=True)%0A    parser.add_argument('--app_key', type=str, help='App key', required=True)%0A%0A    subparsers = parser.add_subparsers(dest='action')%0A%0A    parser_get = subparsers.add_parser('get', help='Get a single dashboard.')%0A    parser_get.add_argument(%0A        '--id', type=int, help='The ID of the dashboard.', required=True)%0A%0A    parser_create = subparsers.add_parser(%0A        'create', help='Create a single dashboard.')%0A    parser_create.add_argument(%0A        '--title', type=str, help='The name of the dashboard.', required=True)%0A    parser_create.add_argument(%0A        '--description', type=str, help='The description of the dashboard.',%0A        required=False)%0A    parser_create.add_argument(%0A        '--file', type=str, help='Path to a dashboard in JSON format.',%0A        required=True)%0A%0A    args = parser.parse_args()%0A%0A    options = %7B%0A        'api_key': args.api_key,%0A        'app_key': args.app_key%0A    %7D%0A    initialize(**options)%0A%0A    if args.action == 'get':%0A        get(args.id)%0A    elif args.action == 'create':%0A        if not args.description:%0A            args.description = ''%0A        create(args.title, args.description, args.file)%0A    else:%0A        print('Unknown action %7B%7D'.format(args.action))%0A        exit(1)%0A

add datadog dashboard example script