pub struct Client { /* private fields */ }
Expand description

An API client for Mackerel.

Implementations§

source§

impl Client

source

pub fn builder() -> ClientBuilder<((), (), (), ())>

Create a builder for building Client. On the builder, call .api_base(...)(optional), .api_key(...), .user_agent(...)(optional), .timeout(...)(optional) to set the values of the fields. Finally, call .build() to create the instance of Client.

source§

impl Client

source

pub fn new(api_key: impl AsRef<str>) -> Client

Creates a new API client from API key.

use mackerel_client::Client;

let client = Client::new("<Mackerel-API-KEY>");

If you want to configure the API base, use Client::builder().

use mackerel_client::Client;

let client = Client::builder()
    .api_key("<Mackerel-API-KEY>")
    .api_base("https://api.mackerelio.com")
    .build();

You can configure user agent and timeout (default: 30s).

use mackerel_client::Client;
use std::time::Duration;

let client = Client::builder()
    .api_key("<Mackerel-API-KEY>")
    .user_agent("custom-user-agent/0.0")
    .timeout(Duration::from_secs(60))
    .build();
source§

impl Client

source

pub async fn list_open_alerts( &self, cursor_opt: Option<impl Into<AlertId>>, limit: u8 ) -> Result<(Vec<Alert>, Option<AlertId>)>

source

pub async fn list_all_alerts( &self, cursor_opt: Option<impl Into<AlertId>>, limit: u8 ) -> Result<(Vec<Alert>, Option<AlertId>)>

Fetches all (open or closed) alerts.

See https://mackerel.io/api-docs/entry/alerts#list.

source

pub async fn get_alert(&self, alert_id: impl Into<AlertId>) -> Result<Alert>

source

pub async fn update_alert( &self, alert_id: impl Into<AlertId>, memo: impl AsRef<str> ) -> Result<()>

source

pub async fn close_alert( &self, alert_id: impl Into<AlertId>, reason: impl AsRef<str> ) -> Result<Alert>

Closes the specified alert.

See https://mackerel.io/api-docs/entry/alerts#close.

source§

impl Client

source

pub async fn list_alert_group_settings(&self) -> Result<Vec<AlertGroupSetting>>

Fetches all the alert group settings.

See https://mackerel.io/api-docs/entry/alert-group-settings#list.

source

pub async fn create_alert_group_setting( &self, alert_group_setting_value: impl Borrow<AlertGroupSettingValue> ) -> Result<AlertGroupSetting>

source

pub async fn get_alert_group_setting( &self, alert_group_setting_id: impl Into<AlertGroupSettingId> ) -> Result<AlertGroupSetting>

source

pub async fn update_alert_group_setting( &self, alert_group_setting_id: impl Into<AlertGroupSettingId>, alert_group_setting_value: impl Borrow<AlertGroupSettingValue> ) -> Result<AlertGroupSetting>

source

pub async fn delete_alert_group_setting( &self, alert_group_setting_id: impl Into<AlertGroupSettingId> ) -> Result<AlertGroupSetting>

source§

impl Client

source

pub async fn list_aws_integrations(&self) -> Result<Vec<AWSIntegration>>

Fetches all the AWS integration settings.

See https://mackerel.io/api-docs/entry/aws-integration#list.

source

pub async fn create_aws_integration( &self, aws_integration_value: impl Borrow<AWSIntegrationValue> ) -> Result<AWSIntegration>

source

pub async fn get_aws_integration( &self, aws_integration_id: impl Into<AWSIntegrationId> ) -> Result<AWSIntegration>

source

pub async fn update_aws_integration( &self, aws_integration_id: impl Into<AWSIntegrationId>, aws_integration_value: impl Borrow<AWSIntegrationValue> ) -> Result<AWSIntegration>

source

pub async fn delete_aws_integration( &self, aws_integration_id: impl Into<AWSIntegrationId> ) -> Result<AWSIntegration>

source

pub async fn create_aws_integration_external_id(&self) -> Result<String>

source

pub async fn list_aws_integration_metrics( &self ) -> Result<HashMap<AWSServiceName, Vec<String>>>

Lists includable/excludable metrics for AWS integration.

See https://mackerel.io/api-docs/entry/aws-integration#excludable-metrics.

source§

impl Client

source

pub async fn list_channels(&self) -> Result<Vec<Channel>>

Fetches all the channels.

See https://mackerel.io/api-docs/entry/channels#get.

source

pub async fn create_channel( &self, channel_value: impl Borrow<ChannelValue> ) -> Result<Channel>

source

pub async fn delete_channel( &self, channel_id: impl Into<ChannelId> ) -> Result<Channel>

source§

impl Client

source

pub async fn create_check_report( &self, check_reports: impl IntoIterator<Item = CheckReport> ) -> Result<()>

source§

impl Client

source

pub async fn list_dashboards(&self) -> Result<Vec<Dashboard>>

Fetches all the dashboards.

See https://mackerel.io/api-docs/entry/dashboards#list.

source

pub async fn create_dashboard( &self, dashboard_value: impl Borrow<DashboardValue> ) -> Result<Dashboard>

source

pub async fn get_dashboard( &self, dashboard_id: impl Into<DashboardId> ) -> Result<Dashboard>

source

pub async fn update_dashboard( &self, dashboard_id: impl Into<DashboardId>, dashboard_value: impl Borrow<DashboardValue> ) -> Result<Dashboard>

source

pub async fn delete_dashboard( &self, dashboard_id: impl Into<DashboardId> ) -> Result<Dashboard>

source§

impl Client

source

pub async fn list_downtimes(&self) -> Result<Vec<Downtime>>

Fetches all the downtimes.

See https://mackerel.io/api-docs/entry/downtimes#list.

source

pub async fn create_downtime( &self, downtime_value: impl Borrow<DowntimeValue> ) -> Result<Downtime>

source

pub async fn update_downtime( &self, downtime_id: impl Into<DowntimeId>, downtime_value: impl Borrow<DowntimeValue> ) -> Result<Downtime>

source

pub async fn delete_downtime( &self, downtime_id: impl Into<DowntimeId> ) -> Result<Downtime>

source§

impl Client

source

pub async fn list_graph_annotations( &self, service: impl Into<ServiceName>, from: impl Into<DateTime<Utc>>, to: impl Into<DateTime<Utc>> ) -> Result<Vec<GraphAnnotation>>

source

pub async fn create_graph_annotation( &self, graph_annotation_value: impl Borrow<GraphAnnotationValue> ) -> Result<GraphAnnotation>

source

pub async fn update_graph_annotation( &self, graph_annontation_id: impl Into<GraphAnnotationId>, graph_annotation_value: impl Borrow<GraphAnnotationValue> ) -> Result<GraphAnnotation>

source

pub async fn delete_graph_annotation( &self, graph_annotation_id: impl Into<GraphAnnotationId> ) -> Result<GraphAnnotation>

source§

impl Client

source

pub async fn create_graph_definitions( &self, graph_definitions: impl IntoIterator<Item = GraphDefinition> ) -> Result<()>

source§

impl Client

source

pub async fn create_host( &self, host_value: impl Borrow<HostValue> ) -> Result<HostId>

source

pub async fn get_host(&self, host_id: impl Into<HostId>) -> Result<Host>

source

pub async fn get_host_by_custom_identifier( &self, custom_identifier: impl AsRef<str> ) -> Result<Option<Host>>

Gets a host by the custom identifier.

See https://mackerel.io/api-docs/entry/hosts#get-by-custom-identifier.

source

pub async fn update_host( &self, host_id: impl Into<HostId>, host_value: impl Borrow<HostValue> ) -> Result<()>

source

pub async fn update_host_status( &self, host_id: impl Into<HostId>, host_status: HostStatus ) -> Result<()>

source

pub async fn update_host_statuses( &self, host_ids: impl IntoIterator<Item = impl Into<HostId>>, host_status: HostStatus ) -> Result<()>

source

pub async fn update_host_roles( &self, host_id: impl Into<HostId>, role_fullnames: impl IntoIterator<Item = impl Into<RoleFullname>> ) -> Result<()>

source

pub async fn retire_host(&self, host_id: impl Into<HostId>) -> Result<()>

source

pub async fn retire_hosts( &self, host_ids: impl IntoIterator<Item = impl Into<HostId>> ) -> Result<()>

source

pub async fn list_hosts( &self, list_hosts_params: impl Into<ListHostsParams> ) -> Result<Vec<Host>>

Fetches hosts.

See https://mackerel.io/api-docs/entry/hosts#list.

// Fetches all the hosts (with working or standby status).
let hosts = client.list_hosts(()).await?;
// Fetches the hosts in the specified service and role.
let hosts = client.list_hosts(ServiceName::from("service0")).await?;
let hosts = client.list_hosts(RoleFullname::from("service0:role0")).await?;
let hosts = client.list_hosts((ServiceName::from("service0"), RoleName::from("role0"))).await?;
// Fetches the hosts with the specified name.
let hosts = client.list_hosts(ListHostsParams::host_name("example-host")).await?;

// Fetches the hosts with the specified statuses.
let hosts = client.list_hosts(
    ListHostsParams::default().status(HostStatus::Working),
).await?;
let hosts = client.list_hosts(
    ListHostsParams::service_name("service0").status(HostStatus::Working),
).await?;
let hosts = client.list_hosts(
    ListHostsParams::service_name("service0")
        .statuses([HostStatus::Working, HostStatus::Standby, HostStatus::Maintenance]),
).await?;
let hosts = client.list_hosts(
    ListHostsParams::role_fullname("service0:role0").status(HostStatus::Working),
).await?;
let hosts = client.list_hosts(
    ListHostsParams::service_role_name("service0", "role0").status(HostStatus::Working),
).await?;
let hosts = client.list_hosts(
    ListHostsParams::service_role_names("service0", ["role0", "role1", "role2"])
        .statuses([HostStatus::Working, HostStatus::Standby, HostStatus::Maintenance]),
).await?;
source

pub async fn list_host_metric_names( &self, host_id: impl Into<HostId> ) -> Result<Vec<String>>

source

pub async fn list_host_monitored_statuses( &self, host_id: impl Into<HostId> ) -> Result<Vec<MonitoredStatus>>

Fetches host monitoring statuses.

See https://mackerel.io/api-docs/entry/hosts#monitored-statuses.

source§

impl Client

source

pub async fn list_invitations(&self) -> Result<Vec<Invitation>>

Fetches all the invitations.

See https://mackerel.io/api-docs/entry/invitations#list.

source

pub async fn create_invitation( &self, invitation_value: impl Borrow<InvitationValue> ) -> Result<Invitation>

source

pub async fn revoke_invitation(&self, email: impl AsRef<str>) -> Result<()>

source§

impl Client

source

pub async fn get_host_metadata( &self, host_id: impl Into<HostId>, namespace: impl AsRef<str> ) -> Result<Value>

source

pub async fn put_host_metadata( &self, host_id: impl Into<HostId>, namespace: impl AsRef<str>, metadata: impl Borrow<Value> ) -> Result<()>

Creates/Updates a host metadata.

See https://mackerel.io/api-docs/entry/metadata#hostput.

source

pub async fn delete_host_metadata( &self, host_id: impl Into<HostId>, namespace: impl AsRef<str> ) -> Result<()>

source

pub async fn list_host_metadata( &self, host_id: impl Into<HostId> ) -> Result<Vec<Metadata>>

source

pub async fn get_service_metadata( &self, service_name: impl Into<ServiceName>, namespace: impl AsRef<str> ) -> Result<Value>

Retrieves a service metadata.

See https://mackerel.io/api-docs/entry/metadata#serviceget.

source

pub async fn put_service_metadata( &self, service_name: impl Into<ServiceName>, namespace: impl AsRef<str>, metadata: impl Borrow<Value> ) -> Result<()>

Creates/Updates a service metadata.

See https://mackerel.io/api-docs/entry/metadata#serviceput.

source

pub async fn delete_service_metadata( &self, service_name: impl Into<ServiceName>, namespace: impl AsRef<str> ) -> Result<()>

source

pub async fn list_service_metadata( &self, service_name: impl Into<ServiceName> ) -> Result<Vec<Metadata>>

source

pub async fn get_role_metadata( &self, service_name: impl Into<ServiceName>, role_name: impl Into<RoleName>, namespace: impl AsRef<str> ) -> Result<Value>

source

pub async fn put_role_metadata( &self, service_name: impl Into<ServiceName>, role_name: impl Into<RoleName>, namespace: impl AsRef<str>, metadata: impl Borrow<Value> ) -> Result<()>

Creates/Updates a role metadata.

See https://mackerel.io/api-docs/entry/metadata#roleput.

source

pub async fn delete_role_metadata( &self, service_name: impl Into<ServiceName>, role_name: impl Into<RoleName>, namespace: impl AsRef<str> ) -> Result<()>

source

pub async fn list_role_metadata( &self, service_name: impl Into<ServiceName>, role_name: impl Into<RoleName> ) -> Result<Vec<Metadata>>

source§

impl Client

source

pub async fn post_host_metric_values( &self, host_metric_values: impl IntoIterator<Item = HostMetricValue> ) -> Result<()>

source

pub async fn list_host_metric_values( &self, host_id: impl Into<HostId>, metric_name: impl AsRef<str>, from: impl Into<DateTime<Utc>>, to: impl Into<DateTime<Utc>> ) -> Result<Vec<MetricValue>>

source

pub async fn list_latest_host_metric_values( &self, host_ids: impl IntoIterator<Item = impl Into<HostId>>, metric_names: impl IntoIterator<Item = impl AsRef<str>> ) -> Result<HashMap<HostId, HashMap<String, Option<MetricValue>>>>

Fetches latest host metric values of hosts.

See https://mackerel.io/api-docs/entry/host-metrics#get-latest.

source

pub async fn post_service_metric_values( &self, service_name: impl Into<ServiceName>, service_metric_values: impl IntoIterator<Item = ServiceMetricValue> ) -> Result<()>

source

pub async fn list_service_metric_values( &self, service_name: impl Into<ServiceName>, metric_name: impl AsRef<str>, from: impl Into<DateTime<Utc>>, to: impl Into<DateTime<Utc>> ) -> Result<Vec<MetricValue>>

Fetches service metric values.

See https://mackerel.io/api-docs/entry/service-metrics#get.

source§

impl Client

source

pub async fn list_monitors(&self) -> Result<Vec<Monitor>>

Fetches all the monitors.

See https://mackerel.io/api-docs/entry/monitors#get.

source

pub async fn create_monitor( &self, monitor_value: impl Borrow<MonitorValue> ) -> Result<Monitor>

source

pub async fn get_monitor( &self, monitor_id: impl Into<MonitorId> ) -> Result<Monitor>

source

pub async fn update_monitor( &self, monitor_id: impl Into<MonitorId>, monitor_value: impl Borrow<MonitorValue> ) -> Result<Monitor>

source

pub async fn delete_monitor( &self, monitor_id: impl Into<MonitorId> ) -> Result<Monitor>

source§

impl Client

source

pub async fn list_notification_groups(&self) -> Result<Vec<NotificationGroup>>

Fetches all the notification groups.

See https://mackerel.io/api-docs/entry/notification-groups#get.

source

pub async fn create_notification_group( &self, notification_group_value: impl Borrow<NotificationGroupValue> ) -> Result<NotificationGroup>

source

pub async fn update_notification_group( &self, notification_group_id: impl Into<NotificationGroupId>, notification_group_value: impl Borrow<NotificationGroupValue> ) -> Result<NotificationGroup>

source

pub async fn delete_notification_group( &self, notification_group_id: impl Into<NotificationGroupId> ) -> Result<NotificationGroup>

source§

impl Client

source

pub async fn get_organization(&self) -> Result<Organization>

Retrieve the information on the organization.

See https://mackerel.io/api-docs/entry/organizations#get.

source§

impl Client

source

pub async fn list_roles( &self, service_name: impl Into<ServiceName> ) -> Result<Vec<Role>>

Fetches the roles in the specified service.

See https://mackerel.io/api-docs/entry/services#rolelist.

source

pub async fn create_role( &self, service_name: impl Into<ServiceName>, role: impl Borrow<Role> ) -> Result<Role>

source

pub async fn delete_role( &self, service_name: impl Into<ServiceName>, role_name: impl Into<RoleName> ) -> Result<Role>

source§

impl Client

source

pub async fn list_services(&self) -> Result<Vec<Service>>

Fetches all the services.

See https://mackerel.io/api-docs/entry/services#list.

source

pub async fn create_service( &self, service: impl Borrow<Service> ) -> Result<Service>

source

pub async fn delete_service( &self, service_name: impl Into<ServiceName> ) -> Result<Service>

source

pub async fn list_service_metric_names( &self, service_name: impl Into<ServiceName> ) -> Result<Vec<String>>

source§

impl Client

source

pub async fn list_users(&self) -> Result<Vec<User>>

source

pub async fn delete_user(&self, user_id: impl Into<UserId>) -> Result<User>

Delete the user from the organization.

See https://mackerel.io/api-docs/entry/users#delete.

Trait Implementations§

source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more