Getting Started with Reports API

As per your requirements, you can quickly get report data via Reporting APIs. You can build integrations to obtain specific data for various use cases. For example, you can:

  • Track the status of workloads periodically and trigger automated responses using third-party apps or custom scripts. For instance, you can create a ticket to inform an administrator if backups fail beyond a certain percentage on a specific day.
  • Keep a close eye on critical activities such as failed Restore jobs. This visibility allows you to address any issues that may arise proactively.
  • Run narrowed-down diagnostics using filters to provide evidence during audits.
  • Build personalized reports or a backup health view to monitor all your data.

Benefits

  • Common Reporting APIs for workloads and services.
  • Advanced filtering of data for a narrowed-down view.
    For example, you can obtain data for a date range with only the required fields.

Considerations

  • Data on the reports build using these APIs is not real-time. There will be a delay of two hours.
  • These reporting APIs should be used only for reporting purposes, not for frequent operations such as audit, alert, or event use cases.
  • These APIs use role-based access (RBAC) thus, depending the role of your API credentials, you will be able to view specific report's data. For example, a Druva Cloud admin will have complete access, and if the role of your API credentials is a workload admin, you will have access only to the data specific to that workload.
  • The reports are generated based on the UTC format.
  • Currently, APIs are unavailable for Endpoints Storage Status Report and Hybrid Workloads Credit Consumption report and Cost Allocation report.

Prerequisites

Before you begin, you must have the API Credentials, a combination of Client ID and Secret Key, for the application or tool you intend to integrate with the Druva products. API Credentials can be created from the Druva Cloud Platform Console.

If you do not have the API Credentials, you can request your Druva Cloud administrator to provide you the API Credentials. Refer to Integration Workflow for the steps.
Sample API Credentials:

Client ID

McNkxxxx4Vicxxxx4Ldpxxxx/09Uxxxx

Secret Key

Xmcxxxx8j5xxxx6NxxxxRbRxxxxNNyPt

Configuring the Reports SDK for GO

Ensure you have installed GO version 1.20.x and above.

Step 1: Install the GO package and SDK. Use the following code:

go get golang.org/x/oauth2
go get github.com/druvainc/gorestlib
go get github.com/druvainc/Platform/reporting-api/gosdk

Step 2: Create reports client by providing your API credentials. Use the following code:

apiURL := "https://apis-us0.druva.com"
clientID := "API credential Client ID"
secretKey := "API credential Secret Key"

reportsClient, err := reports.GetReportsClientFromCredentials(apiURL, clientID, secretKey)
if err != nil {
	log.Printf("Error in GetReportsClientFromCredentials: %v", err)
	return
}

Step 3: Get report list using reports client.

Get the list of Reports by providing:

  • version: The version supported for the report list API. If empty string is provided, the default version will be "v1".
  • queryParameters: Additional API URL query parameters if any.

Use the following code:

getReportListResponse, err := reportsClient.GetReportList(version, queryParameters)
if err != nil {
	log.Printf("Error in getting report list: %v", err)
	return
}
log.Printf("getReportListResponse: %v", getReportListResponse)

Step 4: Get report data using reports client

Get report data by providing the following:

  • reportID: The unique ID of the report.
  • version: The version supported for the report. For example - "v1". If an empty string is provided, the default version will be v1.
  • pageToken: This should be an empty string for the first call. The token is used to access the next page of results. Use the token value received in the previous response's parameter 'nextPageToken'.
  • filter: Filter to be applied.
getReportResponse, err := reportsClient.GetReport(reportID, version, "", filter)
if err != nil {
	log.Printf("Error in getting report data: %v", err)
	return
}
log.Printf("getReportResponse: %+v", getReportResponse)

pageToken := getReportResponse.NextPageToken

for len(pageToken) > 0 {
	getReportResponseWithPageToken, err := reportsClient.GetReport(reportID, version, pageToken, filter)
	if err != nil {
		log.Printf("Error in getting report data with page token: %+v", err)
		return
	}
	log.Printf("PageToken: %s, getReportResponseWithPageToken: %+v", pageToken, getReportResponseWithPageToken)
	pageToken = getReportResponseWithPageToken.NextPageToken
}

Configuring the Reports SDK for Python

Step1: Install Python SDK from Github by running the following code:

pip3 install "git+https://github.com/druvainc/Platform.git#egg=druvareportsdk&subdirectory=reporting-api/pysdk"

Step 2: Import the required statements as given below.

import json
import builtins
import logging

from druvareportsdk.authentication import authenticate
from druvareportsdk.reportingapi import reportingapi

builtins.globallogger = logging.getLogger('')
_logger = builtins.globallogger

# API credentials
client_id = ''
secret_key = ''

api_url = "https://apis-us0.druva.com"

Step 3: Fetch the access token using the API credentials.

auth_token,_ = authenticate.GetToken(_logger, client_id, secret_key, api_url)
print('Auth_token: ', auth_token)

Step 4: Use the access token obtained from Step 3 to call the reports APIs.

  • List all the available reports.

    try:
        #DCP: API call to get reports list.
        report_list_resp = reportingapi.GetReportsList(_logger, auth_token, api_url=api_url)
        if report_list_resp.status_code == 200:
            report_list = report_list_resp.json()
            print ('[RESPONSE]      :', json.dumps(report_list, indent=2))
        else:
            error_object = report_list_resp.json()
            raise Exception(error_object)
    except Exception as e:
        _logger.error("Error in API call to get reports list => %s" %str(e))
    
  • Obtain the data for a specific report.

    # The version supported for the report.
    version = "v1"
    
    # Unique reportID of the report.
    report_id = "epLastBackupStatus"
    
    body = {
        "filters":{
            "pageSize": 5,
            "filterBy": [{
                "fieldName": "status",
                "value": "Backup Failed",
                "operator": "EQUAL"
            }]
        }
    }
    
    reattempt = 1
    while True:
        try:
            # DCP: API call to fetch reports data for failed backup operations.
            report_data_resp = reportingapi.GetReportsData(_logger, auth_token, report_id, body, version=version, api_url=api_url)
            if report_data_resp.status_code == 200:
                report_data = report_data_resp.json()
                print ('[RESPONSE]      :', json.dumps(report_data, indent=2))
                nextPageToken = report_data['nextPageToken']
                if not nextPageToken:
                    break
                body['pageToken'] = nextPageToken
                reattempt = 1
            elif report_data_resp.status_code == 403 and reattempt:
                auth_token,_ = authenticate.GetToken(_logger, client_id, secret_key, api_url)
                reattempt = 0
            else:
                error_object = report_data_resp.json()
                raise Exception(error_object)
        except Exception as e:
            _logger.error("Error in API call to fetch reports data => %s" %str(e))
            break