Skip to main content

asterust_junos/system/syslog/
file.rs

1//! `system { syslog { file <name> { ... } } }`. [`SyslogTarget`] is shared with `user`.
2
3use super::archive::{parse_archive, SyslogArchive};
4use super::{syslog_rules, SyslogRule};
5use crate::{arg_of, child_block, has_leaf, named_children};
6use asterust::config::ConfigLine;
7
8/// A `structured-data` statement on a syslog file.
9#[derive(Clone, Debug, PartialEq, Eq)]
10#[non_exhaustive]
11pub struct SyslogStructuredData {
12    /// Omit the message text.
13    pub brief: bool,
14}
15
16/// A `file <name>` or `user <name>` destination.
17#[derive(Clone, Debug, PartialEq, Eq)]
18#[non_exhaustive]
19pub struct SyslogTarget {
20    /// File name, or user name (`*` for all users).
21    pub name: String,
22    pub rules: Vec<SyslogRule>,
23    /// Only files have an archive.
24    pub archive: Option<SyslogArchive>,
25    pub allow_duplicates: bool,
26    /// The regular expression from `match`.
27    pub match_regex: Option<String>,
28    /// Only files have `explicit-priority`.
29    pub explicit_priority: bool,
30    /// Only files have `structured-data`.
31    pub structured_data: Option<SyslogStructuredData>,
32}
33
34pub(super) fn targets(syslog: &ConfigLine, keyword: &str) -> Vec<SyslogTarget> {
35    named_children(syslog, keyword)
36        .map(|(name, target)| SyslogTarget {
37            name: name.to_string(),
38            rules: syslog_rules(target),
39            archive: parse_archive(target),
40            allow_duplicates: has_leaf(target, "allow-duplicates"),
41            match_regex: arg_of(target, "match").map(str::to_string),
42            explicit_priority: has_leaf(target, "explicit-priority"),
43            structured_data: child_block(target, "structured-data").map(|data| SyslogStructuredData {
44                brief: has_leaf(data, "brief"),
45            }),
46        })
47        .collect()
48}
49
50pub(super) fn files(syslog: &ConfigLine) -> Vec<SyslogTarget> {
51    targets(syslog, "file")
52}