Lightweight client for accessing several Datadog APIs

Lightweight client for accessing several Datadog APIs

/x/datadog_api`: Deno library for Datadog Very incomplete Typescript client for Datadog's API.

/x/datadog_api: Deno library for Datadog

Very incomplete Typescript client for Datadog's API.

Purpose

My primary goal is to give important parts of the Datadog API a typed interface for use in Deno scripts. I'm comparing API docs with actual API payloads as much as possible. If you just want to make calls and get JSON back, you can use the datadog.fetchJson({...}) function.

PS: This library doesn't really depend on Deno APIs, it's just targetting Deno as a runtime (Typescript, URL imports, fetch, etc).

Implemented APIs

  • v1Metrics: submit custom data series points to Datadog
    • For a full example of metrics submission, see examples/emit-metrics.ts
  • v1Monitors: get by id, get all, search by query
  • v1ServiceChecks: submit 'check run' statuses to Datadog
  • v1UsageMetering: get billable summary, get top custom metrics
  • v2Roles: list and describe roles & permissions
  • v2Users: list, search, and describe datadog users

If you want a different API not listed here, please open a Github issue or PR into v1/ or v2/ as appropriate. In the meantime you can use fetchJson for such APIs.

Usage

Importing mod.ts gives you the whole implemented API surface.

import DatadogApi from "https://deno.land/x/datadog_api/mod.ts";

// Set up an API client using DATADOG_API_KEY and such
const datadog = DatadogApi.fromEnvironment(Deno.env);

// Optionally check that our API key works, without actually doing anything
await datadog.validateAccess();

// Perform a monitor search by tag
const {monitors} = await datadog.v1Monitors.search('env:"prod"');
console.log("First monitor:", monitors[0]);

// Or, directly fetch JSON (for using APIs that don't have functions yet)
const dashboardLists = await datadog.fetchJson({
  path: '/api/v2/dashboard/lists/manual',
});

Selective Imports

You can also import specific parts of this module by starting with client.ts and adding specific APIs from v1/ or v2/. This lets you skip downloading APIs you don't plan on using.

// Assemble an API client manually
import ApiClient from "https://deno.land/x/datadog_api/client.ts";
const datadog = new ApiClient({
  apiKey: Deno.env.get("DATADOG_API_KEY"),
  appKey: Deno.env.get("DATADOG_APP_KEY"),
  apiBase: Deno.env.get("DATADOG_HOST"), // defaults to US server
});

// Set up a Monitors API client
import V1MonitorsApi from "https://deno.land/x/datadog_api/v1/monitors.ts";
const monitorsApi = new V1MonitorsApi(datadog);

// Get a monitor
console.log(await monitorsApi.getOne("234231"));

Download Details:

Author: danopia

Source Code: https://github.com/danopia/deno-datadog_api

deno nodejs node javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

AEM Querybuilder for JavaScript (Browser, Node, Deno)

Helix Querybuilder .AEM Querybuilder for JavaScript (Browser, Node, Deno)

NKeys for JavaScript - Node.js, Browsers, and Deno

A public-key signature system based on Ed25519 for the NATS ecosystem system for JavaScript. The nkeys.js library works in Deno, Node.js, and the browser!

Javascript module for easily generating mazes,compatible with both Deno and Node

A work-in-progress Javascript maze generator module, compatible with both Deno and Node.

Deno Tutorial for Beginners: Deno vs. Node: Better Than NodeJS?

Deno is released, it’s time to find out if it can prove a worthy competition for Node.js. What is Deno? Why Deno can be considered an alternative to Node? The main differences between Deno and Node. Write a simple Deno app.

What is Deno? The Node.JS Killer? The Deno-minator to Node?

What is Deno? The Node.JS Killer? The Deno-minator to Node? Deno is the new hype and will it be better than node.js? Deno is a secure runtime for JavaScript and TypeScript that is based on the V8 JavaScript engine and the Rust programming language that addresses Node’s shortcomings