Skip to content

API Reference

Garot Conklin edited this page Feb 6, 2025 · 1 revision

API Reference

Complete reference for the DataDog Dashboard Deployer Python API.

Core Classes

DashboardDeployer

Main class for handling dashboard deployment operations.

from datadog_dashboard_deployer import DashboardDeployer

deployer = DashboardDeployer(
    api_key="your-api-key",
    app_key="your-app-key",
    site="datadoghq.com"
)

Methods

deploy(config_path: str, dry_run: bool = False) -> Dict

Deploy dashboards from configuration file.

result = deployer.deploy("config/dashboard.yaml", dry_run=False)

Returns:

{
    "status": "success",
    "results": [
        {
            "status": "success",
            "dashboard_id": "abc-123",
            "name": "My Dashboard",
            "action": "create"  # or "update"
        }
    ]
}

ConfigParser

Parser for dashboard configuration files.

from datadog_dashboard_deployer import ConfigParser

parser = ConfigParser("config/dashboard.yaml")
config = parser.parse()

Methods

parse() -> Dict

Parse and validate configuration file.

config = parser.parse()

Utility Functions

setup_logging(level: Optional[str] = None) -> None

Configure logging for the package.

from datadog_dashboard_deployer import setup_logging

setup_logging("DEBUG")

validate_environment() -> None

Validate required environment variables.

from datadog_dashboard_deployer.utils import validate_environment

validate_environment()

Configuration Schema

Dashboard Configuration

DASHBOARD_SCHEMA = {
    "type": "object",
    "required": ["version", "dashboards"],
    "properties": {
        "version": {"type": "string"},
        "defaults": {
            "type": "object",
            "properties": {
                "layout_type": {"type": "string", "enum": ["ordered", "free"]},
                "refresh_interval": {"type": "integer", "minimum": 0},
                "tags": {"type": "array", "items": {"type": "string"}},
            },
        },
        "dashboards": {
            "type": "array",
            "items": {
                "type": "object",
                "required": ["name", "widgets"],
                "properties": {
                    "name": {"type": "string"},
                    "description": {"type": "string"},
                    "layout_type": {"type": "string"},
                    "widgets": {"type": "array"}
                }
            }
        }
    }
}

Error Handling

Custom Exceptions

from datadog_dashboard_deployer.exceptions import (
    ConfigurationError,
    ValidationError,
    DeploymentError
)

try:
    deployer.deploy("config.yaml")
except ConfigurationError as e:
    print(f"Configuration error: {e}")
except ValidationError as e:
    print(f"Validation error: {e}")
except DeploymentError as e:
    print(f"Deployment error: {e}")

Examples

Basic Usage

from datadog_dashboard_deployer import DashboardDeployer

# Initialize deployer
deployer = DashboardDeployer(
    api_key="your-api-key",
    app_key="your-app-key"
)

# Deploy dashboards
result = deployer.deploy("config/dashboard.yaml")

# Check results
if result["status"] == "success":
    print("Deployment successful!")
    for dashboard in result["results"]:
        print(f"- {dashboard['action']}: {dashboard['name']}")

Advanced Usage

import logging
from datadog_dashboard_deployer import DashboardDeployer, setup_logging

# Configure logging
setup_logging("DEBUG")

# Initialize deployer
deployer = DashboardDeployer(
    api_key="your-api-key",
    app_key="your-app-key",
    site="datadoghq.eu"
)

# Validate configuration
result = deployer.deploy("config/dashboard.yaml", dry_run=True)

# Deploy if valid
if result["status"] == "validated":
    result = deployer.deploy("config/dashboard.yaml")

Related Resources

Clone this wiki locally