Skip to main content

asterust_junos/system/syslog/
file.rs

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