File: logs_pipelines.go

package info (click to toggle)
golang-github-zorkian-go-datadog-api 2.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,612 kB
  • sloc: makefile: 28; sh: 13
file content (65 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Datadog API for Go
 *
 * Please see the included LICENSE file for licensing information.
 *
 * Copyright 2019 by authors and contributors.
 */

package datadog

import (
	"fmt"
)

const (
	logsPipelinesPath = "/v1/logs/config/pipelines"
)

// LogsPipeline struct to represent the json object received from Logs Public Config API.
type LogsPipeline struct {
	Id         *string              `json:"id,omitempty"`
	Type       *string              `json:"type,omitempty"`
	Name       *string              `json:"name"`
	IsEnabled  *bool                `json:"is_enabled,omitempty"`
	IsReadOnly *bool                `json:"is_read_only,omitempty"`
	Filter     *FilterConfiguration `json:"filter"`
	Processors []LogsProcessor      `json:"processors,omitempty"`
}

// FilterConfiguration struct to represent the json object of filter configuration.
type FilterConfiguration struct {
	Query *string `json:"query"`
}

// GetLogsPipeline queries Logs Public Config API with given a pipeline id for the complete pipeline object.
func (client *Client) GetLogsPipeline(id string) (*LogsPipeline, error) {
	var pipeline LogsPipeline
	if err := client.doJsonRequest("GET", fmt.Sprintf("%s/%s", logsPipelinesPath, id), nil, &pipeline); err != nil {
		return nil, err
	}
	return &pipeline, nil
}

// CreateLogsPipeline sends pipeline creation request to Config API
func (client *Client) CreateLogsPipeline(pipeline *LogsPipeline) (*LogsPipeline, error) {
	var createdPipeline = &LogsPipeline{}
	if err := client.doJsonRequest("POST", logsPipelinesPath, pipeline, createdPipeline); err != nil {
		return nil, err
	}
	return createdPipeline, nil
}

// UpdateLogsPipeline updates the pipeline object of a given pipeline id.
func (client *Client) UpdateLogsPipeline(id string, pipeline *LogsPipeline) (*LogsPipeline, error) {
	var updatedPipeline = &LogsPipeline{}
	if err := client.doJsonRequest("PUT", fmt.Sprintf("%s/%s", logsPipelinesPath, id), pipeline, updatedPipeline); err != nil {
		return nil, err
	}
	return updatedPipeline, nil
}

// DeleteLogsPipeline deletes the pipeline for a given id, returns 200 OK when operation succeed
func (client *Client) DeleteLogsPipeline(id string) error {
	return client.doJsonRequest("DELETE", fmt.Sprintf("%s/%s", logsPipelinesPath, id), nil, nil)
}