Skip to main content

InMemoryAlertHook

Struct InMemoryAlertHook 

Source
pub struct InMemoryAlertHook { /* private fields */ }
Expand description

内存告警钩子(非真实 Webhook):将告警存入内存,不进行任何网络发送。

类型名刻意改为 InMemoryAlertHook(原 WebhookAlertHook 名字暗示 HTTP 调用, 但实际只 push 到 Vec,会误导用户)。identifier 字段仅用于测试断言与调试, 不会被用于任何 HTTP 请求

如需真实 Webhook 推送,请实现自定义 AlertHook 并在 notify 中使用 reqwesthyper 发起 HTTP 请求。

用于测试和本地开发环境,可通过 sent_alerts 检查被分发过的告警。

Implementations§

Source§

impl InMemoryAlertHook

Source

pub fn new(identifier: String) -> Self

创建内存告警钩子。identifier 仅作调试标识,不参与网络调用。

Source

pub fn sent_alerts(&self) -> Vec<Alert>

返回到目前为止已“发送“的告警快照(拷贝)。

Source

pub fn identifier(&self) -> &str

暴露配置的标识符,便于调用方调试或断言。

Source

pub fn url(&self) -> &str

👎Deprecated since 1.2.0:

use identifier() instead; this hook does not perform HTTP

向后兼容:返回 identifier(原 url 字段的别名)。

§已废弃

此方法仅为减少破坏性变更而保留,新代码应使用 identifier

Trait Implementations§

Source§

impl AlertHook for InMemoryAlertHook

Source§

fn notify(&self, alert: &Alert) -> Result<(), String>

处理告警事件。成功返回 Ok(()),失败返回错误描述字符串。

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.