mackerelclient

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadApibaseFromConfig

func LoadApibaseFromConfig(conffile string) string

LoadApibaseFromConfig gets mackerel api Base URL (usually https://api.mackerelio.com/) from mackerel-agent.conf if it's installed mackerel-agent on localhost

func LoadApibaseFromConfigWithFallback

func LoadApibaseFromConfigWithFallback(conffile string) string

LoadApibaseFromConfigWithFallback get mackerel api Base URL from mackerel-agent.conf, and fallbacks to default (https://api.mackerelio.com/) if not specified.

func LoadApikeyFromConfig

func LoadApikeyFromConfig(conffile string) string

LoadApikeyFromConfig gets mackerel.io apikey from mackerel-agent.conf if it's installed mackerel-agent on localhost

func LoadApikeyFromEnvOrConfig

func LoadApikeyFromEnvOrConfig(conffile string) string

LoadApikeyFromEnvOrConfig is similar to LoadApikeyFromConfig. return MACKEREL_APIKEY environment value if defined MACKEREL_APIKEY

func LoadHostIDFromConfig

func LoadHostIDFromConfig(conffile string) string

LoadHostIDFromConfig gets localhost's hostID from conf.Root (ex. /var/lib/mackerel/id) if it's installed mackerel-agent on localhost

Types

type Client added in v0.36.0

type Client interface {
	FindAWSIntegrationsContext(ctx context.Context) ([]*mackerel.AWSIntegration, error)
	FindHostsContext(ctx context.Context, param *mackerel.FindHostsParam) ([]*mackerel.Host, error)
	FindHostContext(ctx context.Context, id string) (*mackerel.Host, error)
	FindServicesContext(ctx context.Context) ([]*mackerel.Service, error)
	FindChannelsContext(ctx context.Context) ([]*mackerel.Channel, error)
	FindUsersContext(ctx context.Context) ([]*mackerel.User, error)
	GetOrgContext(ctx context.Context) (*mackerel.Org, error)
	CreateHostContext(ctx context.Context, param *mackerel.CreateHostParam) (string, error)
	UpdateHostStatusContext(ctx context.Context, hostID string, status string) error
	ListHostMetricNamesContext(ctx context.Context, id string) ([]string, error)
	// below mock needed implemented.
	FindWithClosedAlertsContext(ctx context.Context) (*mackerel.AlertsResp, error)
	FindWithClosedAlertsByNextIDContext(ctx context.Context, nextID string) (*mackerel.AlertsResp, error)
	FindAlertsContext(ctx context.Context) (*mackerel.AlertsResp, error)
	FindAlertsByNextIDContext(ctx context.Context, nextID string) (*mackerel.AlertsResp, error)
	CloseAlertContext(ctx context.Context, alertID string, reason string) (*mackerel.Alert, error)
	FindAlertLogsContext(ctx context.Context, alertId string, params *mackerel.FindAlertLogsParam) (*mackerel.FindAlertLogsResp, error)
	FindMonitorsContext(ctx context.Context) ([]mackerel.Monitor, error)
	CreateGraphAnnotationContext(ctx context.Context, annotation *mackerel.GraphAnnotation) (*mackerel.GraphAnnotation, error)
	FindGraphAnnotationsContext(ctx context.Context, service string, from int64, to int64) ([]*mackerel.GraphAnnotation, error)
	UpdateGraphAnnotationContext(ctx context.Context, annotationID string, annotation *mackerel.GraphAnnotation) (*mackerel.GraphAnnotation, error)
	DeleteGraphAnnotationContext(ctx context.Context, annotationID string) (*mackerel.GraphAnnotation, error)
	FindDashboardsContext(ctx context.Context) ([]*mackerel.Dashboard, error)
	FindDashboardContext(ctx context.Context, dashboardID string) (*mackerel.Dashboard, error)
	UpdateDashboardContext(ctx context.Context, dashboardID string, param *mackerel.Dashboard) (*mackerel.Dashboard, error)
	CreateDashboardContext(ctx context.Context, param *mackerel.Dashboard) (*mackerel.Dashboard, error)
	RetireHostContext(ctx context.Context, hostID string) error
	UpdateHostRoleFullnamesContext(ctx context.Context, hostID string, roleFullnames []string) error
	UpdateHostContext(ctx context.Context, hostID string, param *mackerel.UpdateHostParam) (string, error)
	ListServiceMetricNamesContext(ctx context.Context, serviceName string) ([]string, error)
	FetchHostMetricValuesContext(ctx context.Context, hostID string, metricName string, from int64, to int64) ([]mackerel.MetricValue, error)
	FetchServiceMetricValuesContext(ctx context.Context, serviceName string, metricName string, from int64, to int64) ([]mackerel.MetricValue, error)
	FetchLatestMetricValuesContext(ctx context.Context, hostIDs []string, metricNames []string) (mackerel.LatestMetricValues, error)
	PostHostMetricValuesByHostIDContext(ctx context.Context, hostID string, metricValues []*mackerel.MetricValue) error
	PostServiceMetricValuesContext(ctx context.Context, serviceName string, metricValues []*mackerel.MetricValue) error
	CreateMonitorContext(ctx context.Context, param mackerel.Monitor) (mackerel.Monitor, error)
	DeleteMonitorContext(ctx context.Context, monitorID string) (mackerel.Monitor, error)
	UpdateMonitorContext(ctx context.Context, monitorID string, param mackerel.Monitor) (mackerel.Monitor, error)
}

Client represents a client of Mackerel API

func New

func New(conffile, apibase string) (Client, error)

New returns new mackerel client

func NewFromCliCommand added in v0.64.0

func NewFromCliCommand(c *cli.Command) Client

NewFromCliCommand returns mackerel client from cli.Command

func NewFromCliCommandVerbose added in v0.64.0

func NewFromCliCommandVerbose(c *cli.Command) Client

NewFromCliCommand returns mackerel client from cli.Command

type MockClient added in v0.36.0

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

MockClient represents a mock client of Mackerel API

func NewMockClient added in v0.36.0

func NewMockClient(opts ...MockClientOption) *MockClient

NewMockClient creates a new mock client of Mackerel API

func (*MockClient) ApplyOption added in v0.36.0

func (c *MockClient) ApplyOption(opt MockClientOption)

ApplyOption applies a mock client option

func (*MockClient) CloseAlertContext added in v0.64.0

func (c *MockClient) CloseAlertContext(context.Context, string, string) (*mackerel.Alert, error)

func (*MockClient) CreateDashboardContext added in v0.64.0

func (c *MockClient) CreateDashboardContext(ctx context.Context, param *mackerel.Dashboard) (*mackerel.Dashboard, error)

func (*MockClient) CreateGraphAnnotationContext added in v0.64.0

func (c *MockClient) CreateGraphAnnotationContext(ctx context.Context, annotation *mackerel.GraphAnnotation) (*mackerel.GraphAnnotation, error)

func (*MockClient) CreateHostContext added in v0.64.0

func (c *MockClient) CreateHostContext(ctx context.Context, param *mackerel.CreateHostParam) (string, error)

CreateHost ...

func (*MockClient) CreateMonitorContext added in v0.64.0

func (c *MockClient) CreateMonitorContext(ctx context.Context, param mackerel.Monitor) (mackerel.Monitor, error)

func (*MockClient) DeleteGraphAnnotationContext added in v0.64.0

func (c *MockClient) DeleteGraphAnnotationContext(ctx context.Context, annotationID string) (*mackerel.GraphAnnotation, error)

func (*MockClient) DeleteMonitorContext added in v0.64.0

func (c *MockClient) DeleteMonitorContext(ctx context.Context, monitorID string) (mackerel.Monitor, error)

func (*MockClient) FetchHostMetricValuesContext added in v0.64.0

func (c *MockClient) FetchHostMetricValuesContext(ctx context.Context, hostID string, metricName string, from int64, to int64) ([]mackerel.MetricValue, error)

func (*MockClient) FetchLatestMetricValuesContext added in v0.64.0

func (c *MockClient) FetchLatestMetricValuesContext(ctx context.Context, hostIDs []string, metricNames []string) (mackerel.LatestMetricValues, error)

func (*MockClient) FetchServiceMetricValuesContext added in v0.64.0

func (c *MockClient) FetchServiceMetricValuesContext(ctx context.Context, serviceName string, metricName string, from int64, to int64) ([]mackerel.MetricValue, error)

func (*MockClient) FindAWSIntegrationsContext added in v0.64.0

func (c *MockClient) FindAWSIntegrationsContext(ctx context.Context) ([]*mackerel.AWSIntegration, error)

FindAWSIntegrations ...

func (*MockClient) FindAlertLogsContext added in v0.64.0

func (*MockClient) FindAlertsByNextIDContext added in v0.64.0

func (c *MockClient) FindAlertsByNextIDContext(context.Context, string) (*mackerel.AlertsResp, error)

func (*MockClient) FindAlertsContext added in v0.64.0

func (c *MockClient) FindAlertsContext(context.Context) (*mackerel.AlertsResp, error)

func (*MockClient) FindChannelsContext added in v0.64.0

func (c *MockClient) FindChannelsContext(ctx context.Context) ([]*mackerel.Channel, error)

FindChannels ...

func (*MockClient) FindDashboardContext added in v0.64.0

func (c *MockClient) FindDashboardContext(ctx context.Context, dashboardID string) (*mackerel.Dashboard, error)

func (*MockClient) FindDashboardsContext added in v0.64.0

func (c *MockClient) FindDashboardsContext(ctx context.Context) ([]*mackerel.Dashboard, error)

func (*MockClient) FindGraphAnnotationsContext added in v0.64.0

func (c *MockClient) FindGraphAnnotationsContext(ctx context.Context, service string, from int64, to int64) ([]*mackerel.GraphAnnotation, error)

func (*MockClient) FindHostContext added in v0.64.0

func (c *MockClient) FindHostContext(ctx context.Context, id string) (*mackerel.Host, error)

FindHost ...

func (*MockClient) FindHostsContext added in v0.64.0

func (c *MockClient) FindHostsContext(ctx context.Context, param *mackerel.FindHostsParam) ([]*mackerel.Host, error)

FindHosts ...

func (*MockClient) FindMonitorsContext added in v0.64.0

func (c *MockClient) FindMonitorsContext(context.Context) ([]mackerel.Monitor, error)

func (*MockClient) FindServicesContext added in v0.64.0

func (c *MockClient) FindServicesContext(ctx context.Context) ([]*mackerel.Service, error)

FindServices ...

func (*MockClient) FindUsersContext added in v0.64.0

func (c *MockClient) FindUsersContext(ctx context.Context) ([]*mackerel.User, error)

FindUsers ...

func (*MockClient) FindWithClosedAlertsByNextIDContext added in v0.64.0

func (c *MockClient) FindWithClosedAlertsByNextIDContext(context.Context, string) (*mackerel.AlertsResp, error)

func (*MockClient) FindWithClosedAlertsContext added in v0.64.0

func (c *MockClient) FindWithClosedAlertsContext(context.Context) (*mackerel.AlertsResp, error)

func (*MockClient) GetOrgContext added in v0.64.0

func (c *MockClient) GetOrgContext(ctx context.Context) (*mackerel.Org, error)

GetOrg ...

func (*MockClient) ListHostMetricNamesContext added in v0.64.0

func (c *MockClient) ListHostMetricNamesContext(ctx context.Context, hostID string) ([]string, error)

ListHostMetricNames ...

func (*MockClient) ListServiceMetricNamesContext added in v0.64.0

func (c *MockClient) ListServiceMetricNamesContext(ctx context.Context, serviceName string) ([]string, error)

func (*MockClient) PostHostMetricValuesByHostIDContext added in v0.64.0

func (c *MockClient) PostHostMetricValuesByHostIDContext(ctx context.Context, hostID string, metricValues []*mackerel.MetricValue) error

func (*MockClient) PostServiceMetricValuesContext added in v0.64.0

func (c *MockClient) PostServiceMetricValuesContext(ctx context.Context, serviceName string, metricValues []*mackerel.MetricValue) error

func (*MockClient) RetireHostContext added in v0.64.0

func (c *MockClient) RetireHostContext(ctx context.Context, hostID string) error

func (*MockClient) UpdateDashboardContext added in v0.64.0

func (c *MockClient) UpdateDashboardContext(ctx context.Context, dashboardID string, param *mackerel.Dashboard) (*mackerel.Dashboard, error)

func (*MockClient) UpdateGraphAnnotationContext added in v0.64.0

func (c *MockClient) UpdateGraphAnnotationContext(ctx context.Context, annotationID string, annotation *mackerel.GraphAnnotation) (*mackerel.GraphAnnotation, error)

func (*MockClient) UpdateHostContext added in v0.64.0

func (c *MockClient) UpdateHostContext(ctx context.Context, hostID string, param *mackerel.UpdateHostParam) (string, error)

func (*MockClient) UpdateHostRoleFullnamesContext added in v0.64.0

func (c *MockClient) UpdateHostRoleFullnamesContext(ctx context.Context, hostID string, roleFullnames []string) error

func (*MockClient) UpdateHostStatusContext added in v0.64.0

func (c *MockClient) UpdateHostStatusContext(ctx context.Context, hostID string, status string) error

UpdateHostStatus ...

func (*MockClient) UpdateMonitorContext added in v0.64.0

func (c *MockClient) UpdateMonitorContext(ctx context.Context, monitorID string, param mackerel.Monitor) (mackerel.Monitor, error)

type MockClientOption added in v0.36.0

type MockClientOption func(*MockClient)

MockClientOption represents an option of mock client of Mackerel API

func MockCreateHost added in v0.38.0

func MockCreateHost(callback func(*mackerel.CreateHostParam) (string, error)) MockClientOption

MockCreateHost returns an option to set the callback of CreateHost

func MockFindAWSIntegrations added in v0.45.3

func MockFindAWSIntegrations(callback func() ([]*mackerel.AWSIntegration, error)) MockClientOption

MockFindAWSIntegrations returns an option to set the callback of FindAWSIntegrations

func MockFindChannels added in v0.40.0

func MockFindChannels(callback func() ([]*mackerel.Channel, error)) MockClientOption

MockFindChannels returns an option to set the callback of FindChannels

func MockFindHost added in v0.47.0

func MockFindHost(callback func(id string) (*mackerel.Host, error)) MockClientOption

MockFindHost returns an option to set the callback of FindHost

func MockFindHosts added in v0.36.0

func MockFindHosts(callback func(param *mackerel.FindHostsParam) ([]*mackerel.Host, error)) MockClientOption

MockFindHosts returns an option to set the callback of FindHosts

func MockFindServices added in v0.36.0

func MockFindServices(callback func() ([]*mackerel.Service, error)) MockClientOption

MockFindServices returns an option to set the callback of FindServices

func MockFindUsers added in v0.63.0

func MockFindUsers(callback func() ([]*mackerel.User, error)) MockClientOption

MockFindUsers returns an option to set the callback of FindUsers

func MockGetOrg added in v0.36.0

func MockGetOrg(callback func() (*mackerel.Org, error)) MockClientOption

MockGetOrg returns an option to set the callback of GetOrg

func MockListHostMetricNames added in v0.48.0

func MockListHostMetricNames(callback func(string) ([]string, error)) MockClientOption

MockListHostMetricNames returns an option to set the callback of ListHostMetricNames

func MockUpdateHostStatus added in v0.38.0

func MockUpdateHostStatus(callback func(string, string) error) MockClientOption

MockUpdateHostStatus returns an option to set the callback of UpdateHostStatus

Jump to

Keyboard shortcuts

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