asterust_junos/system/
tracing.rs1use crate::{statement_words, value_after};
10use asterust::config::ConfigLine;
11
12#[derive(Clone, Debug, PartialEq, Eq)]
14#[non_exhaustive]
15pub struct Tracing {
16 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 #[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}