splunk

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

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 Float64

func Float64(v float64) *float64

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

func Int

func Int(v int) *int

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

func Int64

func Int64(v int64) *int64

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

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.

func TestDefaultContext

func TestDefaultContext() context.Context

TestDefaultContext returns a context set up for use in a Splunk client.

See also: APIParams.NewAPI

func WithTestMainSetup

func WithTestMainSetup(runner TestMainRunner)

WithTestMainSetup provides global test setup for integration tests with Splunk.

During the life-time of a test run, a Splunk container is provided, and a client, which is configured to access the Splunk instance. Configuration details (e.g., admin user and password) can be obtained from the client.

See also: TestGlobalSplunkClient

Types

type ACL

type ACL struct {
	App            string `json:"app"`
	CanChangePerms bool   `json:"can_change_perms"`
	CanShareApp    bool   `json:"can_share_app"`
	CanShareGlobal bool   `json:"can_share_global"`
	CanShareUser   bool   `json:"can_share_user"`
	CanWrite       bool   `json:"can_write"`
	Modifiable     bool   `json:"modifiable"` // XXX doc mismatch
	Owner          string `json:"owner"`
	Perms          struct {
		Read  []string `json:"read"`
		Write []string `json:"write"`
	} `json:"perms"`
	Removable bool   `json:"removable"`
	Sharing   string `json:"sharing"`
}

ACL https://docs.splunk.com/Documentation/Splunk/7.2.4/RESTUM/RESTusing#Access_Control_List

type API

type API struct {
	Introspection *IntrospectionService
	AccessControl *AccessControlService
	Properties    *PropertiesService
	Deployment    *DeploymentService
	// contains filtered or unexported fields
}

API https://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTprolog

func NewTestSplunkClient

func NewTestSplunkClient(url, username, password string) *API

NewTestSplunkClient returns a new Splunk API client using the context provided by TestDefaultContext.

func NewTestSplunkService

func NewTestSplunkService() (cleanup func(), conn *API, err error)

NewTestSplunkService spins up a new Splunk service, and returns a Splunk API configured to access it.

If the SPLUNK_ADDR environment variable is set, the tests will run against the specified Splunk. If also the SPLUNK_PASSWORD environment variable is set, this password will be used for admin access, instead of a default password ("test1234").

Example:

		export SPLUNK_ADDR='https://localhost:8089'
     export SPLUNK_PASSWORD='SECRET'

func NewTestSplunkServiceWithTempAdmin

func NewTestSplunkServiceWithTempAdmin() (cleanup func(), conn *API, err error)

NewTestSplunkServiceWithTempAdmin spins up a new Splunk instance, and also creates a new test admin user.

See also: NewTestSplunkService

func TestGlobalSplunkClient

func TestGlobalSplunkClient(t *testing.T) *API

TestGlobalSplunkClient returns a Splunk API client that is configured to access a test Splunk instance.

If no Splunk instance has been set up via WithTestMainSetup, the calling test is skipped.

func (*API) Params

func (api *API) Params() *APIParams

Params returns the configuration for this API instance.

type APIError

type APIError struct {
	Messages []APIErrorMessage `json:"messages"`
}

The APIError type encapsulates API errors and status responses.

func (APIError) Empty

func (e APIError) Empty() bool

Empty returns true if empty. Otherwise, at least 1 error message is present and false is returned.

func (APIError) Error

func (e APIError) Error() string

Error is an implementation of the error interface

type APIErrorMessage

type APIErrorMessage struct {
	Type string `json:"type"`
	Text string `json:"text"`
	Code string `json:"code"`
}

The APIErrorMessage type encapsulates a single API error or status message.

type APIParams

type APIParams struct {
	BaseURL   string
	UserAgent string
	TokenTTL  time.Duration

	// pass in an actual OAuth2 client, if supported by Splunk; if nil, use Splunk's basic auth/sessionkey token flow
	AuthClient *http.Client
	oauth2.Config
}

APIParams provides the configuration for setting up a new API client with the NewClient() function.

func (*APIParams) NewAPI

func (params *APIParams) NewAPI(ctx context.Context) *API

NewAPI creates a new instance to access the API of the configured Splunk instance.

func (*APIParams) NewClient

func (p *APIParams) NewClient(ctx context.Context) *Client

NewClient creates a new transport for the Splunk API.

func (*APIParams) TokenSource

func (p *APIParams) TokenSource(ctx context.Context) oauth2.TokenSource

TokenSource returns a TokenSource using the configuration in params and the HTTP client from the provided context.

type AccessControlService

type AccessControlService struct {
	Authentication *AuthenticationService
	// contains filtered or unexported fields
}

AccessControlService encapsulates the Access Control portion of the Splunk API.

type AuthenticationService

type AuthenticationService struct {
	Users *UserService
	// contains filtered or unexported fields
}

AuthenticationService encapsulates the Authentication portion of the Splunk API.

func (*AuthenticationService) Login

func (s *AuthenticationService) Login(username, password string) (*LoginResponse, error)

Login returns a valid session key, or an error.

type Client

type Client struct {
	*sling.Sling
}

The Client type wraps the underlying API transport.

func (*Client) New

func (c *Client) New() *Client

New returns a copy of a Client for creating a new client with properties from a parent client.

Note that query and body values are copied so if pointer values are used, mutating the original value will mutate the value within the child client.

func (*Client) Path

func (c *Client) Path(pathURL string) *Client

Path extends the current API client with the given path by resolving the reference to an absolute URL. If parsing errors occur, the client is left unmodified.

type CreateUserOptions

type CreateUserOptions struct {
	CreateRole            *bool    `url:"createrole,omitempty"`
	DefaultApp            string   `url:"defaultApp,omitempty"`
	Email                 string   `url:"email,omitempty"`
	ForceChangePass       *bool    `url:"force-change-pass,omitempty"`
	Name                  string   `url:"name"`
	Password              string   `url:"password,omitempty"`
	Realname              string   `url:"realname,omitempty"`
	RestartBackgroundJobs *bool    `url:"restart_background_jobs,omitempty"`
	Roles                 []string `url:"roles,omitempty"`
	TZ                    string   `url:"tz,omitempty"`
}

The CreateUserOptions type provides options for creating a new user.

type DeploymentService added in v0.2.0

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

DeploymentService encapsulates the Deployment portion of the Splunk API

func (*DeploymentService) SearchPeers added in v0.5.0

func (d *DeploymentService) SearchPeers(filter *PaginationFilter) ([]ServerInfoEntry, *Response, error)

SearchPeers returns information about all search peers

type Entry added in v0.1.3

type Entry struct {
	Value string
}

type EntryMetadata

type EntryMetadata struct {
	ACL                        // XXX doc mismatch
	Messages []APIErrorMessage `json:"messages"`
	Title    string            `json:"title"`
	ID       string            `json:"id"`
	Updated  time.Time         `json:"updated"`
	Links    map[string]string `json:"links"` // XXX doc mismatch
	Author   string            `json:"author"`
}

EntryMetadata https://docs.splunk.com/Documentation/Splunk/latest/RESTUM/RESTusing#Response_elements

type IntrospectionService

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

IntrospectionService encapsulates the Introspection portion of the Splunk API.

func (*IntrospectionService) ServerInfo

func (s *IntrospectionService) ServerInfo() ([]ServerInfoEntry, *Response, error)

ServerInfo returns information about the Splunk instance.

type LoginResponse

type LoginResponse struct {
	APIError
	SessionKey string `json:"sessionKey"`
}

LoginResponse is returned from Login() calls.

type PaginationFilter added in v0.5.0

type PaginationFilter struct {
	Count     int      `url:"count,omitempty"` // NOTE: we omit zero value, since this is already set in outputMode
	Filter    []string `url:"f,omitempty"`
	Offset    int      `url:"offset,omitempty"`
	Search    string   `url:"search,omitempty"`
	SortDir   string   `url:"sort_dir,omitempty"`
	SortKey   string   `url:"sort_key,omitempty"`
	SortMode  string   `url:"sort_mode,omitempty"`
	Summarize bool     `url:"summarize,omitempty"`
}

API https://docs.splunk.com/Documentation/Splunk/8.0.2/RESTREF/RESTprolog#Request_and_response_details

var (
	ServerInfoEntryFilterDefault *PaginationFilter

	ServerInfoEntryFilterMinimal *PaginationFilter = &PaginationFilter{
		Filter: []string{"host", "host_fqdn", "server_roles"},
	}
)

type Paging

type Paging struct {
	Offset  int `json:"offset"`
	PerPage int `json:"perPage"`
	Total   int `json:"total"`
}

The Paging type encapsulates paging information provided by the API.

See also: https://docs.splunk.com/Documentation/Splunk/latest/RESTUM/RESTusing#Atom_Feed_response

type PropertiesService added in v0.1.3

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

func (*PropertiesService) GetKey added in v0.1.3

func (p *PropertiesService) GetKey(file string, stanza string, key string) (*string, *http.Response, error)

GetKey returns value for the given key from the specified stanza in the configuration file

func (*PropertiesService) UpdateKey added in v0.1.3

func (p *PropertiesService) UpdateKey(file string, stanza string, key string, value string) (*string, *http.Response, error)

UpdateKey updates value for specified key from the specified stanza in the configuration file

type Response

type Response struct {
	Title     string            `json:"title"`
	ID        string            `json:"id"`
	Updated   time.Time         `json:"updated"`
	Generator map[string]string `json:"generator"`
	Author    string            `json:"author"`
	Links     map[string]string `json:"links"` // XXX doc mismatch
	Messages  []APIErrorMessage `json:"messages"`
	Paging    Paging            `json:"paging"` // XXX doc mismatch
	Entry     json.RawMessage   `json:"entry"`

	HTTPResponse *http.Response
}

Response https://docs.splunk.com/Documentation/Splunk/latest/RESTUM/RESTusing#Atom_Feed_response

func Receive

func Receive(sling *sling.Sling, v interface{}) (*Response, error)

Receive kicks off an API call to the underlying transport. It attempts to deserialize a value into v, if there is neither a transport error nor an API error. Otherwise, the error is returned. This function also returns the full API response.

type ServerInfoEntry

type ServerInfoEntry struct {
	EntryMetadata
	Content struct {
		ActiveLicenseGroup string `json:"activeLicenseGroup"`
		// XXX ...
		Build    string `json:"build"`
		CPUArch  string `json:"cpu_arch"`
		GUID     string `json:"guid"`
		Host     string `json:"host"`
		HostFQDN string `json:"host_fqdn"`
		IsFree   bool   `json:"isFree"`
		IsTrial  bool   `json:"isTrial"`
		// XXX ...
		Roles       []string  `json:"server_roles"`
		ServerName  string    `json:"serverName"`
		StartupTime Timestamp `json:"startup_time"`
		Version     string    `json:"version"`
	} `json:"content"`
}

ServerInfoEntry is returned from ServerInfo() calls.

BUG(mweber): this type is incomplete.

type TestMainRunner

type TestMainRunner interface {
	Run() (status int)
}

TestMainRunner is an interface for running Tests.

This interface is implemented by testing.M.

type Timestamp

type Timestamp time.Time

The Timestamp type is used for (un)marshalling Unix timestamps from JSON.

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON marshals Timestamp structs to JSON.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals Timestamp structs from JSON.

type UpdateUserOptions

type UpdateUserOptions struct {
	DefaultApp            string   `url:"defaultApp,omitempty"`
	Email                 string   `url:"email,omitempty"`
	ForceChangePass       *bool    `url:"force-change-pass,omitempty"`
	OldPassword           string   `url:"oldpassword,omitempty"`
	Password              string   `url:"password,omitempty"`
	Realname              string   `url:"realname,omitempty"`
	RestartBackgroundJobs *bool    `url:"restart_background_jobs,omitempty"`
	Roles                 []string `url:"roles,omitempty"`
	TZ                    string   `url:"tz,omitempty"`
}

The UpdateUserOptions type provides options for updating a user.

type UserEntry

type UserEntry struct {
	EntryMetadata
	Name    string `json:"name"`
	Content struct {
		Capabilities             []string `json:"capabilities"`
		DefaultApp               string   `json:"defaultApp"`
		DefaultAppIsUserOverride *bool    `json:"DefaultAppIsUserOverride"`
		Email                    string   `json:"email"`
		Password                 string   `json:"password"`
		RealName                 string   `json:"realname"`
		RestartBackgroundJobs    *bool    `json:"restart_background_jobs"`
		Roles                    []string `json:"roles"`
		Type                     string   `json:"type"`
		TZ                       string   `json:"tz"`
	} `json:"content"`
}

UserEntry is returned from Users() calls.

type UserService

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

UserService encapsulates the User portion of the Splunk API.

func (*UserService) Create

func (s *UserService) Create(opts *CreateUserOptions) (*UserEntry, *Response, error)

Create creates a new user, and returns additional meta data.

func (*UserService) Delete

func (s *UserService) Delete(user string) (*UserEntry, *Response, error)

Delete deletes a user, and returns additional meta data.

func (*UserService) Update

func (s *UserService) Update(user string, opts *UpdateUserOptions) (*UserEntry, *Response, error)

Update updates a user, and returns additional meta data.

func (*UserService) Users

func (s *UserService) Users() ([]UserEntry, *Response, error)

Users returns information about all users.

Notes

Bugs

  • this type is incomplete.

Jump to

Keyboard shortcuts

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