mib-rs 0.8.0

SNMP MIB parser and resolver
Documentation
//! NOTIFICATION-TYPE and TRAP-TYPE definitions.
//!
//! [`NotificationData`] covers both SMIv2 NOTIFICATION-TYPE and SMIv1
//! TRAP-TYPE definitions. SMIv1 traps additionally carry [`TrapInfo`]
//! with the enterprise OID and trap number.
//!
//! For handle-oriented access, see [`Notification`](super::handle::Notification).

use crate::types::Span;

use super::object::EntityData;
use super::types::*;

/// A NOTIFICATION-TYPE or TRAP-TYPE definition.
///
/// Covers both SMIv2 NOTIFICATION-TYPE and SMIv1 TRAP-TYPE macro instances.
/// SMIv1 traps carry additional [`TrapInfo`] with the enterprise OID and
/// trap number, accessible via [`trap_info`](Self::trap_info).
#[derive(Debug, Clone)]
pub struct NotificationData {
    pub(crate) entity: EntityData,
    pub(crate) objects: Vec<ObjectId>,
    pub(crate) trap_info: Option<TrapInfo>,
}

impl NotificationData {
    pub(crate) fn new(name: String) -> Self {
        Self {
            entity: EntityData::new(name),
            objects: Vec::new(),
            trap_info: None,
        }
    }

    /// Return the notification name.
    pub fn name(&self) -> &str {
        &self.entity.name
    }

    /// Return the source span.
    pub fn span(&self) -> Span {
        self.entity.span
    }

    /// Return the OID tree [`NodeId`], if resolved.
    pub fn node(&self) -> Option<NodeId> {
        self.entity.node
    }

    /// Return the defining [`ModuleId`].
    pub fn module(&self) -> Option<ModuleId> {
        self.entity.module
    }

    /// Return the [`Status`](crate::types::Status).
    pub fn status(&self) -> crate::types::Status {
        self.entity.status
    }

    /// Return the DESCRIPTION clause text, or an empty string if absent.
    pub fn description(&self) -> &str {
        &self.entity.description
    }

    /// Return the REFERENCE clause text, or an empty string if absent.
    pub fn reference(&self) -> &str {
        &self.entity.reference
    }

    /// Return the symbolic OID references from the value assignment.
    pub fn oid_refs(&self) -> &[OidRef] {
        &self.entity.oid_refs
    }

    /// Return the OBJECTS clause entries as [`ObjectId`]s.
    pub fn objects(&self) -> &[ObjectId] {
        &self.objects
    }

    /// Return the SMIv1 [`TrapInfo`], or `None` for SMIv2 notifications.
    pub fn trap_info(&self) -> Option<&TrapInfo> {
        self.trap_info.as_ref()
    }
}