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//! - [tlsdetails](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/tlsdetails.html)
8//! - [transport (System Syslog)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-syslog-host-transport.html)
9//! - [match-strings](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/match-string-edit-system-syslog-file.html)
10
11use super::{syslog_rules, SyslogRule};
12use crate::{arg_of, args_of, child_block, has_leaf, list_values, named_children};
13use asterust::config::ConfigLine;
14
15/// The `tlsdetails` block of a syslog host: how the TLS connection is authenticated.
16#[derive(Clone, Debug, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct SyslogTlsDetails {
19    pub local_certificate: Option<String>,
20    pub trusted_ca_group: Option<String>,
21    /// The `ca-profiles` of the trusted CA group.
22    pub ca_profiles: Vec<String>,
23}
24
25/// A `host <address>` destination.
26#[derive(Clone, Debug, PartialEq, Eq)]
27#[non_exhaustive]
28pub struct SyslogHost {
29    /// Address, hostname, or `other-routing-engine`.
30    pub address: String,
31    pub rules: Vec<SyslogRule>,
32    pub port: Option<String>,
33    pub source_address: Option<String>,
34    pub routing_instance: Option<String>,
35    pub facility_override: Option<String>,
36    pub log_prefix: Option<String>,
37    pub allow_duplicates: bool,
38    pub explicit_priority: bool,
39    pub exclude_hostname: bool,
40    /// The regular expression from `match`.
41    pub match_regex: Option<String>,
42    /// The substrings from `match-strings`; a message is logged if it contains any of them.
43    pub match_strings: Vec<String>,
44    /// `tcp`, `tls` or `udp`.
45    pub transport: Option<String>,
46    pub tls_details: Option<SyslogTlsDetails>,
47}
48
49pub(super) fn parse_host(address: &str, host: &ConfigLine) -> SyslogHost {
50    SyslogHost {
51        address: address.to_string(),
52        rules: syslog_rules(host),
53        port: arg_of(host, "port").map(str::to_string),
54        source_address: arg_of(host, "source-address").map(str::to_string),
55        routing_instance: arg_of(host, "routing-instance").map(str::to_string),
56        facility_override: arg_of(host, "facility-override").map(str::to_string),
57        log_prefix: arg_of(host, "log-prefix").map(str::to_string),
58        allow_duplicates: has_leaf(host, "allow-duplicates"),
59        explicit_priority: has_leaf(host, "explicit-priority"),
60        exclude_hostname: has_leaf(host, "exclude-hostname"),
61        match_regex: arg_of(host, "match").map(str::to_string),
62        match_strings: args_of(host, "match-strings")
63            .into_iter()
64            .flat_map(list_values)
65            .collect(),
66        transport: arg_of(host, "transport").map(str::to_string),
67        tls_details: child_block(host, "tlsdetails").map(|tls| {
68            let group = named_children(tls, "trusted-ca-group").next();
69            SyslogTlsDetails {
70                local_certificate: arg_of(tls, "local-certificate").map(str::to_string),
71                trusted_ca_group: group.map(|(name, _)| name.to_string()),
72                ca_profiles: group
73                    .map(|(_, block)| {
74                        args_of(block, "ca-profiles")
75                            .into_iter()
76                            .flat_map(list_values)
77                            .collect()
78                    })
79                    .unwrap_or_default(),
80            }
81        }),
82    }
83}