asterust_junos/system/syslog/
file.rs1use super::archive::{parse_archive, SyslogArchive};
12use super::{syslog_rules, SyslogRule};
13use crate::{arg_of, args_of, child_block, has_leaf, list_values, named_children};
14use asterust::config::ConfigLine;
15
16#[derive(Clone, Debug, PartialEq, Eq)]
18#[non_exhaustive]
19pub struct SyslogStructuredData {
20 pub brief: bool,
22}
23
24#[derive(Clone, Debug, PartialEq, Eq)]
26#[non_exhaustive]
27pub struct SyslogTarget {
28 pub name: String,
30 pub rules: Vec<SyslogRule>,
31 pub archive: Option<SyslogArchive>,
33 pub allow_duplicates: bool,
34 pub match_regex: Option<String>,
36 pub match_strings: Vec<String>,
38 pub explicit_priority: bool,
40 pub structured_data: Option<SyslogStructuredData>,
42}
43
44pub(super) fn targets(syslog: &ConfigLine, keyword: &str) -> Vec<SyslogTarget> {
45 named_children(syslog, keyword)
46 .map(|(name, target)| SyslogTarget {
47 name: name.to_string(),
48 rules: syslog_rules(target),
49 archive: parse_archive(target),
50 allow_duplicates: has_leaf(target, "allow-duplicates"),
51 match_regex: arg_of(target, "match").map(str::to_string),
52 match_strings: args_of(target, "match-strings")
53 .into_iter()
54 .flat_map(list_values)
55 .collect(),
56 explicit_priority: has_leaf(target, "explicit-priority"),
57 structured_data: child_block(target, "structured-data").map(|data| SyslogStructuredData {
58 brief: has_leaf(data, "brief"),
59 }),
60 })
61 .collect()
62}
63
64pub(super) fn files(syslog: &ConfigLine) -> Vec<SyslogTarget> {
65 targets(syslog, "file")
66}