def save_orgs(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug):
    orgs = get_all_orgs_in_grafana(grafana_url, http_get_headers, verify_ssl,
                                   client_cert, debug)
    print_horizontal_line()
    get_individual_org_info_and_save(orgs, folder_path, log_file, grafana_url, http_get_headers,
                                     verify_ssl, client_cert, debug)
    print_horizontal_line()
示例#2
0
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    limit = settings.get('SEARCH_API_LIMIT')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    api_version = settings.get('API_VERSION')
    basic_auth = settings.get('GRAFANA_BASIC_AUTH')

    folder_path = '{0}/organizations/{1}'.format(backup_dir, timestamp)
    log_file = 'organaizations_{0}.txt'.format(timestamp)

    if basic_auth:
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)

        http_get_headers.update(
            {'Authorization': 'Basic {0}'.format(basic_auth)})
        save_orgs(folder_path, log_file, grafana_url, http_get_headers,
                  verify_ssl, client_cert, debug)
    else:
        print(
            '[ERROR] Backing up organizations needs to set GRAFANA_ADMIN_ACCOUNT and GRAFANA_ADMIN_PASSWORD first.'
        )
        print_horizontal_line()
示例#3
0
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers_basic_auth = settings.get('HTTP_GET_HEADERS_BASIC_AUTH')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    pretty_print = settings.get('PRETTY_PRINT')

    folder_path = '{0}/organizations/{1}'.format(backup_dir, timestamp)
    log_file = 'organizations_{0}.txt'.format(timestamp)

    if http_get_headers_basic_auth:
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)

        save_orgs(folder_path, log_file, grafana_url,
                  http_get_headers_basic_auth, verify_ssl, client_cert, debug,
                  pretty_print)
    else:
        print(
            '[ERROR] Backing up organizations needs to set GRAFANA_ADMIN_ACCOUNT and GRAFANA_ADMIN_PASSWORD first.'
        )
        print_horizontal_line()
示例#4
0
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    limit = settings.get('SEARCH_API_LIMIT')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers_basic_auth = settings.get('HTTP_GET_HEADERS_BASIC_AUTH')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    api_version = settings.get('API_VERSION')
    pretty_print = settings.get('PRETTY_PRINT')
    flat = args.get('--flat', False)

    if http_get_headers_basic_auth:       
        if flat:
            folder_path = '{0}/users/'.format(backup_dir)        
            log_file = 'users.txt'
        else:
            folder_path = '{0}/users/{1}'.format(backup_dir, timestamp)
            log_file = 'users_{0}.txt'.format(timestamp)    

        if not os.path.exists(folder_path):
            os.makedirs(folder_path)

        save_users(folder_path, log_file, limit, grafana_url, http_get_headers_basic_auth, verify_ssl, client_cert, debug, pretty_print)
    else:
        print('[ERROR] Backing up users needs to set ENV GRAFANA_ADMIN_ACCOUNT and GRAFANA_ADMIN_PASSWORD first. \n')
        print_horizontal_line()
示例#5
0
def save_users(folder_path, log_file, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print):
    current_page = 1
    users = get_all_users(current_page, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug)
    print_horizontal_line()
    get_individual_user_and_save(users, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert,
                                 debug, pretty_print)
    print_horizontal_line()
示例#6
0
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    pretty_print = settings.get('PRETTY_PRINT')
    flat = args.get('--flat', False)

    if flat:
        folder_path = '{0}/alert_channels/'.format(backup_dir)
        log_file = 'alert_channels.txt'
    else:
        folder_path = '{0}/alert_channels/{1}'.format(backup_dir, timestamp)
        log_file = 'alert_channels_{0}.txt'.format(timestamp)

    if not os.path.exists(folder_path):
        os.makedirs(folder_path)

    alert_channels = get_all_alert_channels_in_grafana(grafana_url,
                                                       http_get_headers,
                                                       verify_ssl, client_cert,
                                                       debug)
    get_individual_alert_channel_and_save(alert_channels, folder_path,
                                          log_file, pretty_print)
    print_horizontal_line()
示例#7
0
def main(settings):
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')

    (status, json_resp) = health_check(grafana_url, http_get_headers,
                                       verify_ssl, client_cert, debug)
    if not status == 200:
        return (status, json_resp, None, None)

    (status, json_resp) = auth_check(grafana_url, http_get_headers, verify_ssl,
                                     client_cert, debug)
    if not status == 200:
        return (status, json_resp, None, None)

    uid_support = uid_feature_check(grafana_url, http_get_headers, verify_ssl,
                                    client_cert, debug)
    if isinstance(uid_support, str):
        raise Exception(uid_support)

    paging_support = paging_feature_check(grafana_url, http_get_headers,
                                          verify_ssl, client_cert, debug)
    if isinstance(paging_support, str):
        raise Exception(paging_support)

    print_horizontal_line()
    if status == 200:
        print("[Pre-Check] Server status is 'OK' !!")
    else:
        print("[Pre-Check] Server status is NOT OK !!: {0}".format(json_resp))
    print_horizontal_line()

    return (status, json_resp, uid_support, paging_support)
示例#8
0
def main(args, settings):
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    pretty_print = settings.get('PRETTY_PRINT')

    get_all_snapshots_and_delete(grafana_url, http_get_headers, verify_ssl,
                                 client_cert, debug, pretty_print)
    print_horizontal_line()
示例#9
0
def save_dashboards(folder_path, log_file, limit, grafana_url,
                    http_get_headers, verify_ssl, client_cert, debug):
    current_page = 1
    dashboards = get_all_dashboards_in_grafana(current_page, limit,
                                               grafana_url, http_get_headers,
                                               verify_ssl, client_cert, debug)
    print_horizontal_line()
    get_individual_dashboard_setting_and_save(dashboards, folder_path,
                                              log_file, grafana_url,
                                              http_get_headers, verify_ssl,
                                              client_cert, debug)
    print_horizontal_line()
示例#10
0
def delete_dashboards(limit, grafana_url, http_get_headers, verify_ssl,
                      client_cert, debug, pretty_print, uid_support):
    current_page = 1
    dashboards = get_all_dashboards_in_grafana(current_page, limit,
                                               grafana_url, http_get_headers,
                                               verify_ssl, client_cert, debug)
    print_horizontal_line()
    get_individual_dashboard_and_delete(dashboards, grafana_url,
                                        http_get_headers, verify_ssl,
                                        client_cert, debug, pretty_print,
                                        uid_support)
    print_horizontal_line()
def save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version):
    limit = 5000 # limit is 5000 above V6.2+
    current_page = 1
    while True:
        dashboards = get_all_dashboards_in_grafana(current_page, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug)
        print_horizontal_line()
        if len(dashboards) == 0:
            break
        else:
            current_page += 1
        get_individual_dashboard_setting_and_save(dashboards, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, api_version)
        print_horizontal_line()
def main(args, settings):
    debug = settings.get('DEBUG')
    verify_ssl = settings.get('VERIFY_SSL')
    grafana_url = settings.get('GRAFANA_URL')
    client_cert = settings.get('CLIENT_CERT')
    uid_support = settings.get('DATASOURCE_UID_SUPPORT')
    pretty_print = settings.get('PRETTY_PRINT')
    http_get_headers = settings.get('HTTP_POST_HEADERS')

    get_all_datasources_and_delete(grafana_url, http_get_headers, verify_ssl,
                                   client_cert, debug, pretty_print,
                                   uid_support)
    print_horizontal_line()
def save_dashboards_above_Ver6_2(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug):
    limit = 5000 # limit is 5000 above V6.2+
    current_page = 1
    while True:
        dashboards = get_all_dashboards_in_grafana(current_page, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug)
        print_horizontal_line()
        if len(dashboards) == 0:
            cmd = 'permanent_counter set grafana.dashboards.count ' + str(len(dashboards))
            subprocess.check_output(cmd.split())
            break
        else:
            current_page += 1
        cmd = 'permanent_counter set grafana.dashboards.count ' + str(len(dashboards))
        subprocess.call(cmd, shell=True)
        print_horizontal_line()
示例#14
0
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    debug = settings.get('DEBUG')

    folder_path = '{0}/datasources/{1}'.format(backup_dir, timestamp)
    log_file = 'datasources_{0}.txt'.format(timestamp)

    if not os.path.exists(folder_path):
        os.makedirs(folder_path)

    datasources = get_all_datasources_and_save(folder_path, grafana_url, http_get_headers, verify_ssl, debug)
    print_horizontal_line()
示例#15
0
def main(args, settings):
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    pretty_print = settings.get('PRETTY_PRINT')
    uid_support = settings.get('UID_SUPPORT')

    folders = get_all_folders_in_grafana(grafana_url, http_get_headers,
                                         verify_ssl, client_cert, debug)
    print_horizontal_line()
    get_individual_folder_setting_and_save(folders, grafana_url,
                                           http_get_headers, verify_ssl,
                                           client_cert, debug, pretty_print,
                                           uid_support)
    print_horizontal_line()
示例#16
0
def main(settings):
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')

    (status, json_resp) = health_check(grafana_url, http_get_headers, verify_ssl, client_cert, debug)
    if not status == 200:
        return (status, json_resp, None)

    api_version = json_resp['version']

    (status, json_resp) = auth_check(grafana_url, http_get_headers, verify_ssl, client_cert, debug)
    print_horizontal_line()

    return (status, json_resp, api_version)
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    pretty_print = settings.get('PRETTY_PRINT')

    folder_path = '{0}/annotations/{1}'.format(backup_dir, timestamp)
    'annotations_{0}.txt'.format(timestamp)

    if not os.path.exists(folder_path):
        os.makedirs(folder_path)

    get_all_annotations_and_save(folder_path, grafana_url, http_get_headers,
                                 verify_ssl, client_cert, debug, pretty_print)
    print_horizontal_line()
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    debug = settings.get('DEBUG')

    folder_path = '{0}/alert_channels/{1}'.format(backup_dir, timestamp)
    log_file = 'alert_channels_{0}.txt'.format(timestamp)

    if not os.path.exists(folder_path):
        os.makedirs(folder_path)

    alert_channels = get_all_alert_channels_in_grafana(grafana_url,
                                                       http_get_headers,
                                                       verify_ssl, debug)
    get_individual_alert_channel_and_save(alert_channels, folder_path,
                                          log_file)
    print_horizontal_line()
示例#19
0
def save_dashboard_versions(folder_path, log_file, grafana_url,
                            http_get_headers, verify_ssl, client_cert, debug,
                            pretty_print, uid_support):
    limit = 5000
    current_page = 1

    while True:
        dashboards = get_all_dashboards_in_grafana(current_page, limit,
                                                   grafana_url,
                                                   http_get_headers,
                                                   verify_ssl, client_cert,
                                                   debug)
        print_horizontal_line()
        if len(dashboards) == 0:
            break
        else:
            current_page += 1
        get_versions_and_save(dashboards, folder_path, log_file, grafana_url,
                              http_get_headers, verify_ssl, client_cert, debug,
                              pretty_print, uid_support)
        print_horizontal_line()
示例#20
0
def delete_dashboards_above_Ver6_2(grafana_url, http_get_headers, verify_ssl,
                                   client_cert, debug, pretty_print,
                                   uid_support):
    limit = 5000  # limit is 5000 above V6.2+
    current_page = 1
    while True:
        dashboards = get_all_dashboards_in_grafana(current_page, limit,
                                                   grafana_url,
                                                   http_get_headers,
                                                   verify_ssl, client_cert,
                                                   debug)
        print_horizontal_line()
        if len(dashboards) == 0:
            break
        else:
            current_page += 1
        get_individual_dashboard_and_delete(dashboards, grafana_url,
                                            http_get_headers, verify_ssl,
                                            client_cert, debug, pretty_print,
                                            uid_support)
        print_horizontal_line()
def main(args, settings):
    backup_dir = settings.get('BACKUP_DIR')
    timestamp = settings.get('TIMESTAMP')
    grafana_url = settings.get('GRAFANA_URL')
    http_get_headers = settings.get('HTTP_GET_HEADERS')
    verify_ssl = settings.get('VERIFY_SSL')
    client_cert = settings.get('CLIENT_CERT')
    debug = settings.get('DEBUG')
    pretty_print = settings.get('PRETTY_PRINT')
    uid_support = settings.get('DASHBOARD_UID_SUPPORT')

    folder_path = '{0}/folders/{1}'.format(backup_dir, timestamp)
    log_file = 'folders_{0}.txt'.format(timestamp)

    if not os.path.exists(folder_path):
        os.makedirs(folder_path)

    folders = get_all_folders_in_grafana(grafana_url, http_get_headers, verify_ssl, client_cert, debug)
    print_horizontal_line()
    get_individual_folder_setting_and_save(folders, folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print, uid_support)
    print_horizontal_line()
def save_dashboards(folder_path, log_file, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug):
    current_page = 1
    dashboards = get_all_dashboards_in_grafana(current_page, limit, grafana_url, http_get_headers, verify_ssl, client_cert, debug)
    cmd = 'permanent_counter set grafana.dashboards.count ' + str(len(dashboards))
    subprocess.call(cmd, shell=True)
    print_horizontal_line()