Skip to main content

Message

Struct Message 

Source
#[non_exhaustive]
pub struct Message {
Show 17 fields pub message: String, pub title: Option<String>, pub severity: Option<Severity>, pub priority: Option<Priority>, pub category: Option<Category>, pub source: Option<String>, pub environment: Option<String>, pub channel: Option<String>, pub group_key: Option<String>, pub event_type: Option<EventType>, pub occurred_at: Option<SystemTime>, pub url: Option<String>, pub image_url: Option<String>, pub actions: Vec<Action>, pub metadata: BTreeMap<String, MetadataValue>, pub ttl_seconds: Option<u32>, pub source_sequence: Option<u64>,
}
Expand description

One event for POST /v1/messages. Only the message text is required; unset fields are omitted so the server defaults apply (severity info, priority normal, source api, environment default, channel general, event type event, TTL 3600 s). Empty strings count as unset.

use honk_me::{Category, Message, Priority, Severity};

let msg = Message::new("db-1 /var is at 91%")
    .title("Disk 91% full")
    .severity(Severity::LOUD)
    .priority(Priority::High)
    .category(Category::Infrastructure)
    .group_key("disk/db-1/var")
    .metadata("host", "db-1")
    .metadata("used_percent", 91);
assert_eq!(msg.severity, Some(Severity::Warning));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§message: String

The text: plain, 1–8192 bytes of UTF-8. Line breaks and tabs are allowed.

§title: Option<String>

One line, at most 160 characters. Defaults to the first line of the message.

§severity: Option<Severity>

Default info (light).

§priority: Option<Priority>

Default normal.

§category: Option<Category>

The category.

§source: Option<String>

At most 64 characters. Defaults to the client’s default, then api.

§environment: Option<String>

At most 32 characters. Defaults to the client’s default, then default.

§channel: Option<String>

At most 64 characters. Defaults to the client’s default, then general.

§group_key: Option<String>

At most 128 characters. Messages with the same key (per environment, source and channel) form one group: the first one pushes, repeats update it calmly. Use one key per customer request (requests/<id>), a shared key only for repeats of the same problem.

§event_type: Option<EventType>

Default event.

§occurred_at: Option<SystemTime>

When it happened at the source (informational).

§url: Option<String>

An https link shown as “Open link” (no credentials, at most 2048 bytes).

§image_url: Option<String>

An https image the server fetches after ingestion (no credentials or fragment, at most 2048 bytes).

§actions: Vec<Action>

Up to 3 buttons, in display order (the first is the primary). Empty: none.

§metadata: BTreeMap<String, MetadataValue>

At most 16 keys matching [A-Za-z0-9_.-]{1,64}.

§ttl_seconds: Option<u32>

The push lifetime, 60–86400 seconds. Default 3600.

§source_sequence: Option<u64>

A monotonic counter per source stream (0 … 2^53-1), so a delayed recovery can never close a newer problem. Needs a group key.

Implementations§

Source§

impl Message

Source

pub fn new(message: impl Into<String>) -> Self

A message with this text and nothing else set.

Source

pub fn title(self, title: impl Into<String>) -> Self

Sets the title.

Source

pub fn severity(self, severity: Severity) -> Self

Sets the severity (a horn alias like Severity::LOUD or a canonical value).

Source

pub fn priority(self, priority: Priority) -> Self

Sets the priority.

Source

pub fn category(self, category: Category) -> Self

Sets the category.

Source

pub fn source(self, source: impl Into<String>) -> Self

Sets the source.

Source

pub fn environment(self, environment: impl Into<String>) -> Self

Sets the environment.

Source

pub fn channel(self, channel: impl Into<String>) -> Self

Sets the channel.

Source

pub fn group_key(self, group_key: impl Into<String>) -> Self

Sets the group key, e.g. requests/4812.

Source

pub fn event_type(self, event_type: EventType) -> Self

Sets the event type.

Source

pub fn occurred_at(self, occurred_at: SystemTime) -> Self

Sets when the event happened at the source.

Source

pub fn url(self, url: impl Into<String>) -> Self

Sets the https link shown as “Open link”.

Source

pub fn image_url(self, image_url: impl Into<String>) -> Self

Sets an https image the server fetches after ingestion.

Source

pub fn action(self, title: impl Into<String>, url: impl Into<String>) -> Self

Adds a button (at most 3, in display order), e.g. .action("Call", "tel:+15550134").

Source

pub fn metadata( self, key: impl Into<String>, value: impl Into<MetadataValue>, ) -> Self

Adds one metadata entry (a string, number or boolean).

Source

pub fn ttl_seconds(self, ttl_seconds: u32) -> Self

Sets the push lifetime in seconds (60–86400).

Source

pub fn source_sequence(self, source_sequence: u64) -> Self

Sets the monotonic source sequence (needs a group key).

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Message

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&str> for Message

Source§

fn from(message: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Message

Source§

fn from(message: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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