client

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MIT Imports: 10 Imported by: 0

README

go-graylog client

GoDoc Build Status codecov Go Report Card GitHub last commit GitHub tag License

Graylog API client for Golang.

See https://github.com/suzuki-shunsuke/go-graylog

Documentation

Overview

Package client provides Graylog API client.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a Graylog API client.

Example
package main

import (
	"fmt"
	"log"

	"github.com/suzuki-shunsuke/go-graylog/client"
	"github.com/suzuki-shunsuke/go-graylog/mockserver"
)

func main() {
	// Create a mock server
	server, err := mockserver.NewServer("", nil)
	if err != nil {
		log.Fatal(err)
	}
	// Start a server
	server.Start()
	defer server.Close()

	// Create a client
	cl, err := client.NewClient(server.Endpoint(), "admin", "admin")
	if err != nil {
		log.Fatal(err)
	}

	// get a role "Admin"
	// ei.Response.Body is closed
	role, ei, err := cl.GetRole("Admin")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(ei.Response.StatusCode)
	fmt.Println(role.Name)
}
Output:

200
Admin

func NewClient

func NewClient(ep string, name, password string) (*Client, error)

NewClient returns a new Graylog API Client. ep is API endpoint url (ex. http://localhost:9000/api). name and password are authentication name and password. If you use an access token instead of password, name is access token and password is literal password "token". If you use a session token instead of password, name is session token and password is literal password "session".

func (*Client) AddUserToRole

func (client *Client) AddUserToRole(userName, roleName string) (
	*ErrorInfo, error,
)

AddUserToRole adds a user to a role.

func (*Client) AddUserToRoleContext

func (client *Client) AddUserToRoleContext(
	ctx context.Context, userName, roleName string,
) (*ErrorInfo, error)

AddUserToRoleContext adds a user to a role with a context.

func (*Client) CreateDashboard added in v0.4.0

func (client *Client) CreateDashboard(dashboard *graylog.Dashboard) (*ErrorInfo, error)

CreateDashboard creates a new dashboard account.

func (*Client) CreateDashboardContext added in v0.4.0

func (client *Client) CreateDashboardContext(
	ctx context.Context, dashboard *graylog.Dashboard,
) (*ErrorInfo, error)

CreateDashboardContext creates a new dashboard account with a context.

func (*Client) CreateIndexSet

func (client *Client) CreateIndexSet(indexSet *graylog.IndexSet) (*ErrorInfo, error)

CreateIndexSet creates a Index Set.

func (*Client) CreateIndexSetContext

func (client *Client) CreateIndexSetContext(
	ctx context.Context, is *graylog.IndexSet,
) (*ErrorInfo, error)

CreateIndexSetContext creates a Index Set with a context.

func (*Client) CreateInput

func (client *Client) CreateInput(input *graylog.Input) (
	ei *ErrorInfo, err error,
)

CreateInput creates an input.

func (*Client) CreateInputContext

func (client *Client) CreateInputContext(
	ctx context.Context, input *graylog.Input,
) (ei *ErrorInfo, err error)

CreateInputContext creates an input with a context.

func (*Client) CreateRole

func (client *Client) CreateRole(role *graylog.Role) (*ErrorInfo, error)

CreateRole creates a new role.

func (*Client) CreateRoleContext

func (client *Client) CreateRoleContext(
	ctx context.Context, role *graylog.Role,
) (*ErrorInfo, error)

CreateRoleContext creates a new role with a context.

func (*Client) CreateStream

func (client *Client) CreateStream(stream *graylog.Stream) (*ErrorInfo, error)

CreateStream creates a stream.

func (*Client) CreateStreamContext

func (client *Client) CreateStreamContext(
	ctx context.Context, stream *graylog.Stream,
) (*ErrorInfo, error)

CreateStreamContext creates a stream with a context.

func (*Client) CreateStreamRule

func (client *Client) CreateStreamRule(rule *graylog.StreamRule) (*ErrorInfo, error)

CreateStreamRule creates a stream

func (*Client) CreateStreamRuleContext

func (client *Client) CreateStreamRuleContext(
	ctx context.Context, rule *graylog.StreamRule,
) (*ErrorInfo, error)

CreateStreamRuleContext creates a stream with a context

func (*Client) CreateUser

func (client *Client) CreateUser(user *graylog.User) (*ErrorInfo, error)

CreateUser creates a new user account.

func (*Client) CreateUserContext

func (client *Client) CreateUserContext(
	ctx context.Context, user *graylog.User,
) (*ErrorInfo, error)

CreateUserContext creates a new user account with a context.

func (*Client) DeleteDashboard added in v0.4.0

func (client *Client) DeleteDashboard(id string) (*ErrorInfo, error)

DeleteDashboard deletes a given dashboard.

func (*Client) DeleteDashboardContext added in v0.4.0

func (client *Client) DeleteDashboardContext(
	ctx context.Context, id string,
) (*ErrorInfo, error)

DeleteDashboardContext deletes a given dashboard with a context.

func (*Client) DeleteIndexSet

func (client *Client) DeleteIndexSet(id string) (*ErrorInfo, error)

DeleteIndexSet deletes a given Index Set.

func (*Client) DeleteIndexSetContext

func (client *Client) DeleteIndexSetContext(
	ctx context.Context, id string,
) (*ErrorInfo, error)

DeleteIndexSetContext deletes a given Index Set with a context.

func (*Client) DeleteInput

func (client *Client) DeleteInput(id string) (*ErrorInfo, error)

DeleteInput deletes an given input.

func (*Client) DeleteInputContext

func (client *Client) DeleteInputContext(
	ctx context.Context, id string,
) (*ErrorInfo, error)

DeleteInputContext deletes an given input with a context.

func (*Client) DeleteRole

func (client *Client) DeleteRole(name string) (*ErrorInfo, error)

DeleteRole deletes a given role.

func (*Client) DeleteRoleContext

func (client *Client) DeleteRoleContext(
	ctx context.Context, name string,
) (*ErrorInfo, error)

DeleteRoleContext deletes a given role with a context.

func (*Client) DeleteStream

func (client *Client) DeleteStream(id string) (*ErrorInfo, error)

DeleteStream deletes a stream.

func (*Client) DeleteStreamContext

func (client *Client) DeleteStreamContext(
	ctx context.Context, id string,
) (*ErrorInfo, error)

DeleteStreamContext deletes a stream with a context.

func (*Client) DeleteStreamRule

func (client *Client) DeleteStreamRule(streamID, ruleID string) (*ErrorInfo, error)

DeleteStreamRule deletes a stream rule

func (*Client) DeleteStreamRuleContext

func (client *Client) DeleteStreamRuleContext(
	ctx context.Context, streamID, ruleID string,
) (*ErrorInfo, error)

DeleteStreamRuleContext deletes a stream rule with a context

func (*Client) DeleteUser

func (client *Client) DeleteUser(name string) (*ErrorInfo, error)

DeleteUser deletes a given user.

func (*Client) DeleteUserContext

func (client *Client) DeleteUserContext(
	ctx context.Context, name string,
) (*ErrorInfo, error)

DeleteUserContext deletes a given user with a context.

func (*Client) Endpoints

func (client *Client) Endpoints() *endpoint.Endpoints

Endpoints returns endpoints.

func (*Client) GetAlarmCallbacks added in v0.5.0

func (client *Client) GetAlarmCallbacks() (
	[]graylog.AlarmCallback, int, *ErrorInfo, error,
)

GetAlarmCallbacks returns all alarm callbacks.

func (*Client) GetAlarmCallbacksContext added in v0.5.0

func (client *Client) GetAlarmCallbacksContext(ctx context.Context) (
	[]graylog.AlarmCallback, int, *ErrorInfo, error,
)

GetAlarmCallbacksContext returns all alarm callbacks with a context.

func (*Client) GetAlert added in v0.3.0

func (client *Client) GetAlert(id string) (*graylog.Alert, *ErrorInfo, error)

GetAlert returns an alert.

func (*Client) GetAlertConditions added in v0.2.0

func (client *Client) GetAlertConditions() ([]graylog.AlertCondition, int, *ErrorInfo, error)

GetAlertConditions returns all alert conditions.

func (*Client) GetAlertConditionsContext added in v0.2.0

func (client *Client) GetAlertConditionsContext(ctx context.Context) (
	[]graylog.AlertCondition, int, *ErrorInfo, error,
)

GetAlertConditionsContext returns all alert conditions with a context.

func (*Client) GetAlertContext added in v0.3.0

func (client *Client) GetAlertContext(ctx context.Context, id string) (
	*graylog.Alert, *ErrorInfo, error,
)

GetAlertContext returns an alert with a context.

func (*Client) GetAlerts added in v0.3.0

func (client *Client) GetAlerts(
	skip, limit int,
) ([]graylog.Alert, int, *ErrorInfo, error)

GetAlerts returns all alerts.

func (*Client) GetAlertsContext added in v0.3.0

func (client *Client) GetAlertsContext(ctx context.Context, skip, limit int) (
	[]graylog.Alert, int, *ErrorInfo, error,
)

GetAlertsContext returns all alerts with a context.

func (*Client) GetDashboard added in v0.4.0

func (client *Client) GetDashboard(id string) (*graylog.Dashboard, *ErrorInfo, error)

GetDashboard returns a given dashboard.

func (*Client) GetDashboardContext added in v0.4.0

func (client *Client) GetDashboardContext(
	ctx context.Context, id string,
) (*graylog.Dashboard, *ErrorInfo, error)

GetDashboardContext returns a given dashboard with a context.

func (*Client) GetDashboards added in v0.4.0

func (client *Client) GetDashboards() ([]graylog.Dashboard, int, *ErrorInfo, error)

GetDashboards returns all dashboards.

func (*Client) GetDashboardsContext added in v0.4.0

func (client *Client) GetDashboardsContext(ctx context.Context) ([]graylog.Dashboard, int, *ErrorInfo, error)

GetDashboardsContext returns all dashboards with a context.

func (*Client) GetEnabledStreams

func (client *Client) GetEnabledStreams() (
	streams []graylog.Stream, total int, ei *ErrorInfo, err error,
)

GetEnabledStreams returns all enabled streams.

func (*Client) GetEnabledStreamsContext

func (client *Client) GetEnabledStreamsContext(
	ctx context.Context,
) (streams []graylog.Stream, total int, ei *ErrorInfo, err error)

GetEnabledStreamsContext returns all enabled streams with a context.

func (*Client) GetIndexSet

func (client *Client) GetIndexSet(id string) (*graylog.IndexSet, *ErrorInfo, error)

GetIndexSet returns a given index set.

func (*Client) GetIndexSetContext

func (client *Client) GetIndexSetContext(
	ctx context.Context, id string,
) (*graylog.IndexSet, *ErrorInfo, error)

GetIndexSetContext returns a given index set with a context.

func (*Client) GetIndexSetStats

func (client *Client) GetIndexSetStats(id string) (
	*graylog.IndexSetStats, *ErrorInfo, error,
)

GetIndexSetStats returns a given Index Set statistics.

func (*Client) GetIndexSetStatsContext

func (client *Client) GetIndexSetStatsContext(
	ctx context.Context, id string,
) (*graylog.IndexSetStats, *ErrorInfo, error)

GetIndexSetStatsContext returns a given Index Set statistics with a context.

func (*Client) GetIndexSets

func (client *Client) GetIndexSets(
	skip, limit int, stats bool,
) ([]graylog.IndexSet, map[string]graylog.IndexSetStats, int, *ErrorInfo, error)

GetIndexSets returns a list of all index sets.

func (*Client) GetIndexSetsContext

func (client *Client) GetIndexSetsContext(
	ctx context.Context, skip, limit int, stats bool,
) ([]graylog.IndexSet, map[string]graylog.IndexSetStats, int, *ErrorInfo, error)

GetIndexSetsContext returns a list of all index sets with a context.

func (*Client) GetInput

func (client *Client) GetInput(id string) (*graylog.Input, *ErrorInfo, error)

GetInput returns a given input.

func (*Client) GetInputContext

func (client *Client) GetInputContext(
	ctx context.Context, id string,
) (*graylog.Input, *ErrorInfo, error)

GetInputContext returns a given input with a context.

func (*Client) GetInputs

func (client *Client) GetInputs() ([]graylog.Input, int, *ErrorInfo, error)

GetInputs returns all inputs.

func (*Client) GetInputsContext

func (client *Client) GetInputsContext(ctx context.Context) (
	[]graylog.Input, int, *ErrorInfo, error,
)

GetInputsContext returns all inputs with a context.

func (*Client) GetRole

func (client *Client) GetRole(name string) (*graylog.Role, *ErrorInfo, error)

GetRole returns a given role.

func (*Client) GetRoleContext

func (client *Client) GetRoleContext(
	ctx context.Context, name string,
) (*graylog.Role, *ErrorInfo, error)

GetRoleContext returns a given role with a context.

func (*Client) GetRoleMembers

func (client *Client) GetRoleMembers(name string) ([]graylog.User, *ErrorInfo, error)

GetRoleMembers returns a given role's members.

func (*Client) GetRoleMembersContext

func (client *Client) GetRoleMembersContext(
	ctx context.Context, name string,
) ([]graylog.User, *ErrorInfo, error)

GetRoleMembersContext returns a given role's members with a context.

func (*Client) GetRoles

func (client *Client) GetRoles() ([]graylog.Role, int, *ErrorInfo, error)

GetRoles returns all roles.

func (*Client) GetRolesContext

func (client *Client) GetRolesContext(ctx context.Context) (
	[]graylog.Role, int, *ErrorInfo, error,
)

GetRolesContext returns all roles with a context.

func (*Client) GetStream

func (client *Client) GetStream(id string) (*graylog.Stream, *ErrorInfo, error)

GetStream returns a given stream.

func (*Client) GetStreamContext

func (client *Client) GetStreamContext(
	ctx context.Context, id string,
) (*graylog.Stream, *ErrorInfo, error)

GetStreamContext returns a given stream with a context.

func (*Client) GetStreamRule

func (client *Client) GetStreamRule(streamID, ruleID string) (*graylog.StreamRule, *ErrorInfo, error)

GetStreamRule returns a stream rule

func (*Client) GetStreamRuleContext

func (client *Client) GetStreamRuleContext(
	ctx context.Context, streamID, ruleID string,
) (*graylog.StreamRule, *ErrorInfo, error)

GetStreamRuleContext returns a stream rule with a context

func (*Client) GetStreamRules

func (client *Client) GetStreamRules(streamID string) (
	streamRules []graylog.StreamRule, total int, ei *ErrorInfo, err error,
)

GetStreamRules returns a list of all stream rules

func (*Client) GetStreamRulesContext

func (client *Client) GetStreamRulesContext(
	ctx context.Context, streamID string,
) (streamRules []graylog.StreamRule, total int, ei *ErrorInfo, err error)

GetStreamRulesContext returns a list of all stream rules with a context.

func (*Client) GetStreams

func (client *Client) GetStreams() (
	streams []graylog.Stream, total int, ei *ErrorInfo, err error,
)

GetStreams returns all streams.

func (*Client) GetStreamsContext

func (client *Client) GetStreamsContext(
	ctx context.Context,
) (streams []graylog.Stream, total int, ei *ErrorInfo, err error)

GetStreamsContext returns all streams with a context.

func (*Client) GetTotalIndexSetsStats

func (client *Client) GetTotalIndexSetsStats() (
	*graylog.IndexSetStats, *ErrorInfo, error,
)

GetTotalIndexSetsStats returns stats of all Index Sets.

func (*Client) GetTotalIndexSetsStatsContext

func (client *Client) GetTotalIndexSetsStatsContext(
	ctx context.Context,
) (*graylog.IndexSetStats, *ErrorInfo, error)

GetTotalIndexSetsStatsContext returns stats of all Index Sets with a context.

func (*Client) GetUser

func (client *Client) GetUser(name string) (*graylog.User, *ErrorInfo, error)

GetUser returns a given user.

func (*Client) GetUserContext

func (client *Client) GetUserContext(
	ctx context.Context, name string,
) (*graylog.User, *ErrorInfo, error)

GetUserContext returns a given user with a context.

func (*Client) GetUsers

func (client *Client) GetUsers() ([]graylog.User, *ErrorInfo, error)

GetUsers returns all users.

func (*Client) GetUsersContext

func (client *Client) GetUsersContext(ctx context.Context) ([]graylog.User, *ErrorInfo, error)

GetUsersContext returns all users with a context.

func (*Client) Name

func (client *Client) Name() string

Name returns authentication name.

func (*Client) Password

func (client *Client) Password() string

Password returns authentication password.

func (*Client) PauseStream

func (client *Client) PauseStream(id string) (*ErrorInfo, error)

PauseStream pauses a stream.

func (*Client) PauseStreamContext

func (client *Client) PauseStreamContext(
	ctx context.Context, id string,
) (*ErrorInfo, error)

PauseStreamContext pauses a stream with a context.

func (*Client) RemoveUserFromRole

func (client *Client) RemoveUserFromRole(
	userName, roleName string,
) (*ErrorInfo, error)

RemoveUserFromRole removes a user from a role.

func (*Client) RemoveUserFromRoleContext

func (client *Client) RemoveUserFromRoleContext(
	ctx context.Context, userName, roleName string,
) (*ErrorInfo, error)

RemoveUserFromRoleContext removes a user from a role with a context.

func (*Client) ResumeStream

func (client *Client) ResumeStream(id string) (*ErrorInfo, error)

ResumeStream resumes a stream.

func (*Client) ResumeStreamContext

func (client *Client) ResumeStreamContext(
	ctx context.Context, id string,
) (*ErrorInfo, error)

ResumeStreamContext resumes a stream with a context.

func (*Client) SetDefaultIndexSet

func (client *Client) SetDefaultIndexSet(id string) (
	*graylog.IndexSet, *ErrorInfo, error,
)

SetDefaultIndexSet sets default Index Set.

func (*Client) SetDefaultIndexSetContext

func (client *Client) SetDefaultIndexSetContext(
	ctx context.Context, id string,
) (*graylog.IndexSet, *ErrorInfo, error)

SetDefaultIndexSetContext sets default Index Set with a context.

func (*Client) UpdateDashboard added in v0.4.0

func (client *Client) UpdateDashboard(prms *graylog.Dashboard) (*ErrorInfo, error)

UpdateDashboard updates a given dashboard.

func (*Client) UpdateDashboardContext added in v0.4.0

func (client *Client) UpdateDashboardContext(
	ctx context.Context, dashboard *graylog.Dashboard,
) (*ErrorInfo, error)

UpdateDashboardContext updates a given dashboard with a context.

func (*Client) UpdateIndexSet

func (client *Client) UpdateIndexSet(is *graylog.IndexSetUpdateParams) (*graylog.IndexSet, *ErrorInfo, error)

UpdateIndexSet updates a given Index Set.

func (*Client) UpdateIndexSetContext

func (client *Client) UpdateIndexSetContext(
	ctx context.Context, prms *graylog.IndexSetUpdateParams,
) (*graylog.IndexSet, *ErrorInfo, error)

UpdateIndexSetContext updates a given Index Set with a context.

func (*Client) UpdateInput

func (client *Client) UpdateInput(input *graylog.InputUpdateParams) (*graylog.Input, *ErrorInfo, error)

UpdateInput updates an given input.

func (*Client) UpdateInputContext

func (client *Client) UpdateInputContext(
	ctx context.Context, prms *graylog.InputUpdateParams,
) (*graylog.Input, *ErrorInfo, error)

UpdateInputContext updates an given input with a context.

func (*Client) UpdateRole

func (client *Client) UpdateRole(name string, role *graylog.RoleUpdateParams) (
	*graylog.Role, *ErrorInfo, error,
)

UpdateRole updates a given role.

func (*Client) UpdateRoleContext

func (client *Client) UpdateRoleContext(
	ctx context.Context, name string, prms *graylog.RoleUpdateParams,
) (*graylog.Role, *ErrorInfo, error)

UpdateRoleContext updates a given role with a context.

func (*Client) UpdateStream

func (client *Client) UpdateStream(stream *graylog.Stream) (*ErrorInfo, error)

UpdateStream updates a stream.

func (*Client) UpdateStreamContext

func (client *Client) UpdateStreamContext(
	ctx context.Context, stream *graylog.Stream,
) (*ErrorInfo, error)

UpdateStreamContext updates a stream with a context.

func (*Client) UpdateStreamRule

func (client *Client) UpdateStreamRule(rule *graylog.StreamRule) (*ErrorInfo, error)

UpdateStreamRule updates a stream rule

func (*Client) UpdateStreamRuleContext

func (client *Client) UpdateStreamRuleContext(
	ctx context.Context, rule *graylog.StreamRule,
) (*ErrorInfo, error)

UpdateStreamRuleContext updates a stream rule

func (*Client) UpdateUser

func (client *Client) UpdateUser(prms *graylog.UserUpdateParams) (*ErrorInfo, error)

UpdateUser updates a given user.

func (*Client) UpdateUserContext

func (client *Client) UpdateUserContext(
	ctx context.Context, prms *graylog.UserUpdateParams,
) (*ErrorInfo, error)

UpdateUserContext updates a given user with a context.

type ErrorInfo

type ErrorInfo struct {
	Type     string         `json:"type"`
	Message  string         `json:"message"`
	Request  *http.Request  `json:"request"`
	Response *http.Response `json:"response"`
}

ErrorInfo represents Graylog API's error information. Basically Client methods (ex. CreateRole) returns this, but note that Response is closed.

Directories

Path Synopsis
Package endpoint provides Graylog API endpoints.
Package endpoint provides Graylog API endpoints.

Jump to

Keyboard shortcuts

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