kibana

package module
v0.0.0-...-33e1750 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 12 Imported by: 0

README

go-kibana

A Kibana API client enabling Go programs to interact with Kibana in a simple and uniform way

Build Status Sourcegraph GoDoc Go Report Card

Coverage

This API client package covers most of the existing Kibana API calls and is updated regularly to add new and/or missing endpoints. Currently, the following services are supported:

  • Get features API
  • Get Task Manager health
  • Spaces
    • Create space
    • Update space
    • Get space
    • Get all spaces
    • Delete space
    • Copy saved objects to space
    • Resolve copy to space conflicts
    • Disable legacy URL aliases
  • Roles
    • Create or update role
    • Get specific role
    • Get all roles
    • Delete role
  • User Sessions
    • Invalidate user sessions
  • Saved Objects
    • Get object
    • Bulk get objects
    • Find objects
    • Create saved objects
    • Bulk create saved objects
    • Update object
    • Delete object
    • Export objects
    • Import objects
    • Resolve import errors
    • Resolve object
    • Bulk resolve objects
    • Rotate encryption key
  • Index Patterns
    • Get index pattern
    • Create index pattern
    • Update index pattern
    • Delete index pattern
    • Get default index pattern
    • Set default index pattern
    • Update index pattern fields metadata
    • Get runtime field
    • Create runtime field
    • Upsert runtime field
    • Update runtime field
    • Delete runtime field
  • Alerting
    • Create rule
    • Update rule
    • Get rule
    • Delete rule
    • Find rules
    • List rule types
    • Enable rule
    • Disable rule
    • Mute all alerts
    • Mute alert
    • Unmute all alerts
    • Unmute alert
    • Get Alerting framework health
  • Actions and Connectors
    • Get connector
    • Get all connectors
    • List all connector types
    • Create connector
    • Update connector
    • Execute connector
    • Delete connector
  • Import & Export Dashboards
    • Import dashboard
    • Export dashboard
  • Logstash Configuration Management
    • Delete pipeline
    • List pipeline
    • Create Logstash pipeline
    • Retrieve pipeline
  • Machine Learning
    • Sync machine learning saved objects
  • Short URLs
    • Create short URL
    • Get short URL
    • Delete short URL
    • Resolve short URL
  • Upgrade Assistant
    • Upgrade readiness status
    • Start or resume reindex
    • Batch start or resume reindex
    • Batch reindex queue
    • Add default field
    • Check reindex status
    • Cancel reindex

Usage

import "github.com/ottramst/go-kibana"

Construct a new Kibana client, then use the various services on the client to access different parts of the Kibana API. For example, to list all spaces:

kib, err := kibana.NewClient("<APIKEY>")
if err != nil {
  log.Fatalf("Failed to create client: %v", err)
}
spaces, _, err := kib.Spaces.GetAllSpaces(&kibana.GetAllSpacesOptions{})

There are a few With... option functions that can be used to customize the API client. For example, to set a custom base URL:

kib, err := kibana.NewClient("<APIKEY>", kibana.WithBaseURL("https://kibana.com"))
if err != nil {
  log.Fatalf("Failed to create client: %v", err)
}
spaces, _, err := kib.Spaces.GetAllSpaces(&kibana.GetAllSpacesOptions{})

Some API methods have optional parameters that can be passed. For example, to update a specific space:

kib, _ := kibana.NewClient("<APIKEY>")
opt := &UpdateSpaceOptions{Name: kibana.String("Test Space"), Description: kibana.String("This is a test space")}
projects, _, err := kib.Spaces.UpdateSpace("test-space", opt)
Examples

TODO

For complete usage of go-kibana, see the full package docs.

Issues

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it

Types

type AuthType

type AuthType int

AuthType represents an authentication type within Kibana

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/api.html

const (
	BasicAuth AuthType = iota
	APIKey
)

List of available authentication types

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/api.html

type Client

type Client struct {

	// User agent used when communicating with the Kibana API
	UserAgent string

	// Services used for talking to different parts of the Kibana API
	Roles  *RolesService
	Spaces *SpacesService
	// contains filtered or unexported fields
}

A Client manages communication with the Kibana API

func NewBasicAuthClient

func NewBasicAuthClient(username, password string, options ...ClientOptionFunc) (*Client, error)

NewBasicAuthClient returns a new Kibana API client. To use API methods which require authentication, provide a valid username and password.

func NewClient

func NewClient(apiKey string, options ...ClientOptionFunc) (*Client, error)

NewClient returns a new Kibana API client. To use API methods which require authentication, provide a valid API key

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

BaseURL return a copy of the baseURL.

func (Client) Do

func (c Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, opt interface{}, options []RequestOptionFunc) (*http.Request, error)

NewRequest creates a new API request. The method expects a relative URL path that will be resolved relative to the base URL of the Client. Relative URL paths should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type ClientOptionFunc

type ClientOptionFunc func(*Client) error

ClientOptionFunc can be used to customize a new Kibana API client

func WithBaseURL

func WithBaseURL(urlStr string) ClientOptionFunc

WithBaseURL sets the base URL for API requests to a custom endpoint

type CreateOrUpdateRoleOptions

type CreateOrUpdateRoleOptions struct {
	Metadata *struct {
		Version *int `url:"version,omitempty" json:"version,omitempty"`
	} `url:"metadata,omitempty" json:"metadata,omitempty"`
	Elasticsearch *struct {
		Cluster *[]string             `url:"cluster,omitempty" json:"cluster,omitempty"`
		Indices *[]ElasticsearchIndex `url:"indices,omitempty" json:"indices,omitempty"`
		RunAs   *[]string             `url:"run_as,omitempty" json:"run_as,omitempty"`
	} `url:"elasticsearch,omitempty" json:"elasticsearch,omitempty"`
	Kibana *[]Privilege `url:"kibana" json:"kibana"`
}

CreateOrUpdateRoleOptions represents the available CreateOrUpdateRole() options

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/role-management-api-put.html

type CreateSpaceOptions

type CreateSpaceOptions struct {
	ID               *string   `url:"id" json:"id"`
	Name             *string   `url:"name" json:"name"`
	Description      *string   `url:"description,omitempty" json:"description,omitempty"`
	Color            *string   `url:"color,omitempty" json:"color,omitempty"`
	Initials         *string   `url:"initials,omitempty" json:"initials,omitempty"`
	DisabledFeatures *[]string `url:"disabledFeatures,omitempty" json:"disabledFeatures,omitempty"`
	ImageURL         *string   `url:"imageUrl,omitempty" json:"imageUrl,omitempty"`
}

CreateSpaceOptions represents the available CreateSpace() options

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-post.html

type ElasticsearchIndex

type ElasticsearchIndex struct {
	Names         []string `json:"names"`
	Privileges    []string `json:"privileges"`
	FieldSecurity struct {
		Grant  []string `json:"grant"`
		Except []string `json:"except"`
	} `json:"field_security"`
	// TODO: Query
	AllowRestrictedIndices bool `json:"allow_restricted_indices"`
}

ElasticsearchIndex represents an Elasticsearch index privilege

Elasticsearch API docs: https://www.elastic.co/guide/en/elasticsearch/reference/7.17/defining-roles.html

type ErrorResponse

type ErrorResponse struct {
	Body     []byte
	Response *http.Response
	Message  string
}

An ErrorResponse reports one or more errors caused by an API request

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type Feature

type Feature struct {
	Discover         []string `json:"discover,omitempty"`
	Visualize        []string `json:"visualize,omitempty"`
	Dashboard        []string `json:"dashboard,omitempty"`
	DevTools         []string `json:"dev_tools,omitempty"`
	AdvancedSettings []string `json:"advancedSettings,omitempty"`
	IndexPatterns    []string `json:"indexPatterns,omitempty"`
	Graph            []string `json:"graph,omitempty"`
	APM              []string `json:"apm,omitempty"`
	Maps             []string `json:"maps,omitempty"`
	Canvas           []string `json:"canvas,omitempty"`
	Infrastructure   []string `json:"infrastructure,omitempty"`
	Logs             []string `json:"logs,omitempty"`
	Uptime           []string `json:"uptime,omitempty"`
}

Feature represents a single Kibana feature privileges

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/kibana-privileges.html

type GetAllSpacesOptions

type GetAllSpacesOptions struct {
	Purpose                  *string `url:"purpose,omitempty" json:"purpose,omitempty"`
	IncludeAuthorizedPurpose *bool   `url:"include_authorized_purpose,omitempty" json:"include_authorized_purpose,omitempty"`
}

GetAllSpacesOptions represents the available ListAllSpaces() options

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-get-all.html

type Privilege

type Privilege struct {
	Base    []string `json:"base"`
	Feature *Feature `json:"feature"`
	Spaces  []string `json:"spaces"`
}

Privilege represents a Kibana feature privilege

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/kibana-privileges.html

type RequestOptionFunc

type RequestOptionFunc func(*http.Request) error

RequestOptionFunc can be passed to all API requests to customize the API request

type Response

type Response struct {
	*http.Response
}

Response is a Kibana API response. This wraps the standard http.Response returned from Kibana

type Role

type Role struct {
	Name     string `json:"name"`
	Metadata struct {
		Version int `json:"version"`
	} `json:"metadata"`
	TransientMetadata struct {
		Enabled bool `json:"enabled"`
	} `json:"transient_metadata"`
	Elasticsearch struct {
		Cluster []string              `json:"cluster"`
		Indices *[]ElasticsearchIndex `json:"indices"`
		RunAs   []string              `json:"run_as"`
	} `json:"elasticsearch"`
	Kibana *[]Privilege `json:"kibana"`
}

Role represents a Kibana Role

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/role-management-api.html

type RolesService

type RolesService struct {
	// contains filtered or unexported fields
}

RolesService handles communication with the roles related methods of the Kibana API

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/role-management-api.html

func (RolesService) CreateOrUpdateRole

func (s RolesService) CreateOrUpdateRole(rName string, opt *CreateOrUpdateRoleOptions, options ...RequestOptionFunc) (*Role, *Response, error)

CreateOrUpdateRole creates or updates a Kibana role

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/role-management-api-put.html

func (RolesService) DeleteRole

func (s RolesService) DeleteRole(rName string, options ...RequestOptionFunc) (*Response, error)

DeleteRole deletes a single Kibana role

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/role-management-api-delete.html

func (RolesService) GetAllRoles

func (s RolesService) GetAllRoles(options ...RequestOptionFunc) ([]*Role, *Response, error)

GetAllRoles lists all Kibana roles

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/role-management-api-get.html

func (RolesService) GetRole

func (s RolesService) GetRole(rName string, options ...RequestOptionFunc) (*Role, *Response, error)

GetRole lists a single Kibana role

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/role-management-specific-api-get.html

type Space

type Space struct {
	ID               string   `json:"id"`
	Name             string   `json:"name"`
	Description      string   `json:"description"`
	Color            string   `json:"color"`
	Initials         string   `json:"initials"`
	DisabledFeatures []string `json:"disabledFeatures"`
	ImageURL         string   `json:"imageUrl"`
}

Space represents a Kibana Space

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api.html

type SpacesService

type SpacesService struct {
	// contains filtered or unexported fields
}

SpacesService handles communication with the spaces related methods of the Kibana API

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api.html

func (SpacesService) CreateSpace

func (s SpacesService) CreateSpace(opt *CreateSpaceOptions, options ...RequestOptionFunc) (*Space, *Response, error)

CreateSpace creates a Kibana space

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-post.html

func (SpacesService) DeleteSpace

func (s SpacesService) DeleteSpace(sid string, options ...RequestOptionFunc) (*Response, error)

DeleteSpace deletes a single Kibana space

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-delete.html

func (SpacesService) GetAllSpaces

func (s SpacesService) GetAllSpaces(opt *GetAllSpacesOptions, options ...RequestOptionFunc) ([]*Space, *Response, error)

GetAllSpaces lists all the available Kibana spaces

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-get-all.html

func (SpacesService) GetSpace

func (s SpacesService) GetSpace(sid string, options ...RequestOptionFunc) (*Space, *Response, error)

GetSpace lists a single Kibana space

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-get.html

func (SpacesService) UpdateSpace

func (s SpacesService) UpdateSpace(sid string, opt *UpdateSpaceOptions, options ...RequestOptionFunc) (*Space, *Response, error)

UpdateSpace updates a Kibana space

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-put.html

type UpdateSpaceOptions

type UpdateSpaceOptions struct {
	ID               *string   `url:"id" json:"id"`
	Name             *string   `url:"name" json:"name"`
	Description      *string   `url:"description,omitempty" json:"description,omitempty"`
	Color            *string   `url:"color,omitempty" json:"color,omitempty"`
	Initials         *string   `url:"initials,omitempty" json:"initials,omitempty"`
	DisabledFeatures *[]string `url:"disabledFeatures,omitempty" json:"disabledFeatures,omitempty"`
	ImageURL         *string   `url:"imageUrl,omitempty" json:"imageUrl,omitempty"`
}

UpdateSpaceOptions represents the available UpdateSpace() options

Kibana API docs: https://www.elastic.co/guide/en/kibana/current/spaces-api-put.html

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL