Skip to main content

asterust_junos/system/syslog/
host.rs

1//! `host`
2//! `system { syslog { host <address> { ... } } }`.
3//!
4//! # See also
5//!
6//! - [host (System)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/host-edit-system.html)
7//! - [transport (System Syslog)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-syslog-host-transport.html)
8//! - [match-strings](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/match-string-edit-system-syslog-file.html)
9
10use super::{syslog_rules, SyslogRule};
11use crate::{arg_of, args_of, has_leaf, list_values};
12use asterust::config::ConfigLine;
13
14/// A `host <address>` destination.
15#[derive(Clone, Debug, PartialEq, Eq)]
16#[non_exhaustive]
17pub struct SyslogHost {
18    /// Address, hostname, or `other-routing-engine`.
19    pub address: String,
20    pub rules: Vec<SyslogRule>,
21    pub port: Option<String>,
22    pub source_address: Option<String>,
23    pub routing_instance: Option<String>,
24    pub facility_override: Option<String>,
25    pub log_prefix: Option<String>,
26    pub allow_duplicates: bool,
27    pub explicit_priority: bool,
28    pub exclude_hostname: bool,
29    /// The regular expression from `match`.
30    pub match_regex: Option<String>,
31    /// The substrings from `match-strings`; a message is logged if it contains any of them.
32    pub match_strings: Vec<String>,
33    /// `tcp`, `tls` or `udp`.
34    pub transport: Option<String>,
35}
36
37pub(super) fn parse_host(address: &str, host: &ConfigLine) -> SyslogHost {
38    SyslogHost {
39        address: address.to_string(),
40        rules: syslog_rules(host),
41        port: arg_of(host, "port").map(str::to_string),
42        source_address: arg_of(host, "source-address").map(str::to_string),
43        routing_instance: arg_of(host, "routing-instance").map(str::to_string),
44        facility_override: arg_of(host, "facility-override").map(str::to_string),
45        log_prefix: arg_of(host, "log-prefix").map(str::to_string),
46        allow_duplicates: has_leaf(host, "allow-duplicates"),
47        explicit_priority: has_leaf(host, "explicit-priority"),
48        exclude_hostname: has_leaf(host, "exclude-hostname"),
49        match_regex: arg_of(host, "match").map(str::to_string),
50        match_strings: args_of(host, "match-strings")
51            .into_iter()
52            .flat_map(list_values)
53            .collect(),
54        transport: arg_of(host, "transport").map(str::to_string),
55    }
56}