Checks de service

Checks de service

L’endpoint de check de service vous permet d’envoyer des statuts de check afin de les utiliser avec des monitors. Les messages de check de service ne peuvent pas dépasser 500 caractères. Si un check est envoyé avec un message contenant plus de 500 caractères, seuls les 500 premiers caractères seront affichés.

POST https://api.datadoghq.eu/api/v1/check_runhttps://api.ddog-gov.com/api/v1/check_runhttps://api.datadoghq.com/api/v1/check_runhttps://api.us3.datadoghq.com/api/v1/check_run

Présentation

Envoyez une liste de checks de service.

Remarque : une clé d’API valide est requise.

Requête

Body Data (required)

Corps de requête pour l’envoi de check de service.

Expand All

Champ

Type

Description

check

string

The check.

host_name

string

The host name correlated with the check.

message

string

Message containing check status.

status

enum

The status of a service check. Allowed enum values: 0,1,2,3

tags

[string]

Tags related to a check.

timestamp

int64

Time of check.

{
  "check": "app.ok",
  "host_name": "app.host1",
  "message": "app is running",
  "status": 0,
  "tags": [
    "environment:test"
  ],
  "timestamp": "integer"
}

Réponse

Payload accepted

The payload accepted for intake.

Expand All

Champ

Type

Description

status

string

The status of the intake payload.

{
  "status": "ok"
}

Bad Request

Error response object.

Expand All

Champ

Type

Description

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Authentication Error

Error response object.

Expand All

Champ

Type

Description

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Request timeout

Error response object.

Expand All

Champ

Type

Description

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Payload too large

Error response object.

Expand All

Champ

Type

Description

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Exemple de code


# Curl command
curl -X POST "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v1/check_run" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-d @- << EOF
{
  "check": "app.ok",
  "host_name": "app.host1",
  "status": 0,
  "tags": [
    "environment:test"
  ]
}
EOF
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "os"
    datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)

func main() {
    ctx := datadog.NewDefaultContext(context.Background())

    body := []datadog.ServiceCheck{*datadog.NewServiceCheck("app.ok", "app.host1", datadog.ServiceCheckStatus(0), []string{"Tags_example"})} // []ServiceCheck | Service Check request body.

    configuration := datadog.NewConfiguration()

    apiClient := datadog.NewAPIClient(configuration)
    resp, r, err := apiClient.ServiceChecksApi.SubmitServiceCheck(ctx, body)
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `ServiceChecksApi.SubmitServiceCheck`: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    // response from `SubmitServiceCheck`: IntakePayloadAccepted
    responseContent, _ := json.MarshalIndent(resp, "", "  ")
    fmt.Fprintf(os.Stdout, "Response from ServiceChecksApi.SubmitServiceCheck:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v1 import ApiClient, ApiException, Configuration
from datadog_api_client.v1.api import service_checks_api
from datadog_api_client.v1.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()

# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = service_checks_api.ServiceChecksApi(api_client)
    body = ServiceChecks([
        ServiceCheck(
            check="app.ok",
            host_name="app.host1",
            message="app is running",
            status=ServiceCheckStatus(0),
            tags=["environment:test"],
            timestamp=1,
        ),
    ])  # ServiceChecks | Service Check request body.

    # example passing only required values which don't have defaults set
    try:
        # Submit a Service Check
        api_response = api_instance.submit_service_check(body)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling ServiceChecksApi->submit_service_check: %s\n" % e)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
require 'datadog_api_client'
api_instance = DatadogAPIClient::V1::ServiceChecksAPI.new
body = [DatadogAPIClient::V1::ServiceCheck.new({check: 'app.ok', host_name: 'app.host1', status: DatadogAPIClient::V1::ServiceCheckStatus::OK, tags: ['tags_example']})] # Array<ServiceCheck> | Service Check request body.

begin
  # Submit a Service Check
  result = api_instance.submit_service_check(body)
  p result
rescue DatadogAPIClient::V1::APIError => e
  puts "Error when calling ServiceChecksAPI->submit_service_check: #{e}"
end

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"
import { v1 } from "@datadog/datadog-api-client";
import * as fs from "fs";

const configuration = v1.createConfiguration();
const apiInstance = new v1.ServiceChecksApi(configuration);

let params: v1.ServiceChecksApiSubmitServiceCheckRequest = {
  // Array<ServiceCheck> | Service Check request body.
  body: [
    {
      check: "app.ok",
      hostName: "app.host1",
      message: "app is running",
      status: 0,
      tags: ["environment:test"],
      timestamp: 1,
    },
  ],
};

apiInstance
  .submitServiceCheck(params)
  .then((data: any) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));

Instructions

First install the library and its dependencies and then save the example to example.ts and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" tsc "example.ts"
import java.util.*;
import com.datadog.api.v1.client.ApiClient;
import com.datadog.api.v1.client.ApiException;
import com.datadog.api.v1.client.Configuration;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.ServiceChecksApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        ServiceChecksApi apiInstance = new ServiceChecksApi(defaultClient);
        List<ServiceCheck> body = Arrays.asList(); // List<ServiceCheck> | Service Check request body.
        try {
            IntakePayloadAccepted result = apiInstance.submitServiceCheck(body);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling ServiceChecksApi#submitServiceCheck");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
from datadog import initialize, api
from datadog.api.constants import CheckStatus

options = {'api_key': '<DATADOG_API_KEY>',
           'app_key': '<DATADOG_APPLICATION_KEY>'}

initialize(**options)

check = 'app.ok'
host = 'app1'
status = CheckStatus.OK  # equals 0
tags = ['env:test']

api.ServiceCheck.check(check=check, host_name=host, status=status, message='Response: 200 OK', tags=tags)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python "example.py"
require 'rubygems'
require 'dogapi'

api_key = '<DATADOG_API_KEY>'
app_key = '<DATADOG_APPLICATION_KEY>'

dog = Dogapi::Client.new(api_key, app_key)

# submitting a check doesn't require an app_key
dog = Dogapi::Client.new(api_key)

dog.service_check('app.is_ok', 'app1', 0, :message => 'Response: 200 OK', :tags => ['env:test'])

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"