robotrt-obs-core 0.1.0-beta.2

RobotRT modular robotics runtime and middleware components.
Documentation
use core_types::Timestamp;

/// Severity level of an alert.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum AlertSeverity {
    /// Informational notice, no action required.
    Info,
    /// Threshold crossed; operator should be aware.
    Warn,
    /// Component degraded; timely investigation needed.
    Error,
    /// Critical failure; immediate action required.
    Critical,
}

impl AlertSeverity {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Info => "info",
            Self::Warn => "warn",
            Self::Error => "error",
            Self::Critical => "critical",
        }
    }
}

/// An alert fired by a component or rule.
#[derive(Clone, Debug)]
pub struct Alert {
    /// The component or subsystem that raised the alert.
    pub source: String,
    /// Free-form alert code (e.g. `"CPU_OVER_THRESHOLD"`).
    pub code: String,
    /// Human-readable description of what happened.
    pub message: String,
    /// Alert severity.
    pub severity: AlertSeverity,
    /// When the alert was created (nanos since Unix epoch).
    pub timestamp: Timestamp,
}

impl Alert {
    pub fn new(
        source: impl Into<String>,
        code: impl Into<String>,
        message: impl Into<String>,
        severity: AlertSeverity,
        timestamp: Timestamp,
    ) -> Self {
        Self {
            source: source.into(),
            code: code.into(),
            message: message.into(),
            severity,
            timestamp,
        }
    }
}