Struct Client

Source
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_annotation_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

pub async fn delete_graph_definition(&self, name: impl AsRef<str>) -> 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>,

Source§

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>,

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,