diff --git a/src/sources/journald.rs b/src/sources/journald.rs index 3470e813d62a3..2d7c7fd5b49d7 100644 --- a/src/sources/journald.rs +++ b/src/sources/journald.rs @@ -156,6 +156,13 @@ pub struct JournaldConfig { #[configurable(metadata(docs::human_name = "Data Directory"))] pub data_dir: Option, + /// A list of extra command line arguments to pass to `journalctl`. + /// + /// If specified, it is merged to the command line arguments as-is. + #[serde(default)] + #[configurable(metadata(docs::examples = "--merge"))] + pub extra_args: Vec, + /// The systemd journal is read in batches, and a checkpoint is set at the end of each batch. /// /// This option limits the size of the batch. @@ -297,6 +304,7 @@ impl Default for JournaldConfig { journalctl_path: None, journal_directory: None, journal_namespace: None, + extra_args: vec![], acknowledgements: Default::default(), remap_priority: false, log_namespace: None, @@ -351,6 +359,7 @@ impl SourceConfig for JournaldConfig { self.journal_namespace.clone(), self.current_boot_only, self.since_now, + self.extra_args.clone(), ); let batch_size = self.batch_size; @@ -621,6 +630,7 @@ struct StartJournalctl { journal_namespace: Option, current_boot_only: bool, since_now: bool, + extra_args: Vec, } impl StartJournalctl { @@ -630,6 +640,7 @@ impl StartJournalctl { journal_namespace: Option, current_boot_only: bool, since_now: bool, + extra_args: Vec, ) -> Self { Self { path, @@ -637,6 +648,7 @@ impl StartJournalctl { journal_namespace, current_boot_only, since_now, + extra_args, } } @@ -669,6 +681,10 @@ impl StartJournalctl { command.arg("--since=2000-01-01"); } + if !self.extra_args.is_empty() { + command.args(&self.extra_args); + } + command } @@ -1414,6 +1430,7 @@ mod tests { let current_boot_only = false; let cursor = None; let since_now = false; + let extra_args = vec![]; let command = create_command( &path, @@ -1422,6 +1439,7 @@ mod tests { current_boot_only, since_now, cursor, + extra_args, ); let cmd_line = format!("{:?}", command); assert!(!cmd_line.contains("--directory=")); @@ -1432,6 +1450,7 @@ mod tests { let journal_dir = None; let journal_namespace = None; let since_now = true; + let extra_args = vec![]; let command = create_command( &path, @@ -1440,6 +1459,7 @@ mod tests { current_boot_only, since_now, cursor, + extra_args, ); let cmd_line = format!("{:?}", command); assert!(cmd_line.contains("--since=now")); @@ -1448,6 +1468,7 @@ mod tests { let journal_namespace = Some(String::from("my_namespace")); let current_boot_only = true; let cursor = Some("2021-01-01"); + let extra_args = vec!["--merge".to_string()]; let command = create_command( &path, @@ -1456,12 +1477,14 @@ mod tests { current_boot_only, since_now, cursor, + extra_args, ); let cmd_line = format!("{:?}", command); assert!(cmd_line.contains("--directory=/tmp/journal-dir")); assert!(cmd_line.contains("--namespace=my_namespace")); assert!(cmd_line.contains("--boot")); assert!(cmd_line.contains("--after-cursor=")); + assert!(cmd_line.contains("--merge")); } fn create_command( @@ -1471,6 +1494,7 @@ mod tests { current_boot_only: bool, since_now: bool, cursor: Option<&str>, + extra_args: Vec, ) -> Command { StartJournalctl::new( path.into(), @@ -1478,6 +1502,7 @@ mod tests { journal_namespace, current_boot_only, since_now, + extra_args, ) .make_command(cursor) } diff --git a/website/cue/reference/components/sources/base/journald.cue b/website/cue/reference/components/sources/base/journald.cue index d259076e1b6a8..321ab7442c522 100644 --- a/website/cue/reference/components/sources/base/journald.cue +++ b/website/cue/reference/components/sources/base/journald.cue @@ -82,6 +82,18 @@ base: components: sources: journald: configuration: { items: type: string: examples: ["badservice", "sysinit.target"] } } + extra_args: { + description: """ + A list of extra command line arguments to pass to `journalctl`. + + If specified, it is merged to the command line arguments as-is. + """ + required: false + type: array: { + default: [] + items: type: string: examples: ["--merge"] + } + } include_matches: { description: """ A list of sets of field/value pairs to monitor.