Skip to main content

asterust_junos/system/
tracing.rs

1//! `tracing`
2//! `system { tracing { destination-override { syslog host <address>; } } }`.
3//!
4//! # See also
5//!
6//! - [tracing](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/tracing-edit-system.html)
7//! - [destination-override](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/destination-override-edit-system.html)
8
9use crate::{statement_words, value_after};
10use asterust::config::ConfigLine;
11
12/// The `system tracing` options.
13#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct Tracing {
16    /// The host that remote tracing output is sent to, from `destination-override syslog host`.
17    pub destination_override_syslog_host: Option<String>,
18}
19
20pub(super) fn parse_tracing(tracing: &ConfigLine) -> Tracing {
21    Tracing {
22        destination_override_syslog_host: statement_words(tracing, "destination-override")
23            .and_then(|words| value_after(&words, "host")),
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use crate::system::system;
30    use asterust::config::juniper;
31
32    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
33    #[test]
34    fn extracts_the_destination_override_in_block_form() {
35        let tracing = system(&juniper::parse_braces(
36            "system {\n    tracing {\n        destination-override {\n            syslog host 192.0.2.9;\n        }\n    }\n}\n",
37        ))
38        .unwrap()
39        .tracing
40        .unwrap();
41        assert_eq!(tracing.destination_override_syslog_host.as_deref(), Some("192.0.2.9"));
42    }
43
44    #[test]
45    fn extracts_the_destination_override_in_line_form() {
46        let tracing = system(&juniper::parse_braces(
47            "system {\n    tracing {\n        destination-override syslog host 192.0.2.9;\n    }\n}\n",
48        ))
49        .unwrap()
50        .tracing
51        .unwrap();
52        assert_eq!(tracing.destination_override_syslog_host.as_deref(), Some("192.0.2.9"));
53    }
54
55    #[test]
56    fn no_tracing_is_none() {
57        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
58        assert!(system.tracing.is_none());
59    }
60}