From 402f72c757dfc2ab5521ecd70906a915397841b1 Mon Sep 17 00:00:00 2001 From: Camden Cheek Date: Wed, 22 Jul 2020 14:23:39 -0400 Subject: [PATCH] Add start_at parameter to journald input --- CHANGELOG.md | 4 ++++ docs/operators/journald_input.md | 2 +- operator/builtin/input/journald.go | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de0991161..11fbf28d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased +### Added +- New parameter `start_at` for journald input + ## [0.9.4] - 2020-07-21 - Allow omitting `id`, defaulting to plugin type if unique within namespace - Allow omitting `output`, defaulting to the next operator in the pipeline if valid diff --git a/docs/operators/journald_input.md b/docs/operators/journald_input.md index ae59b783c..8ed1cb834 100644 --- a/docs/operators/journald_input.md +++ b/docs/operators/journald_input.md @@ -15,7 +15,7 @@ The `journald_input` operator will use the `__REALTIME_TIMESTAMP` field of the j | `directory` | | A directory containing journal files to read entries from | | `files` | | A list of journal files to read entries from | | `write_to` | $ | A [field](/docs/types/field.md) that will be set to the path of the file the entry was read from | - +| `start_at` | `end` | At startup, where to start reading logs from the file. Options are `beginning` or `end` | ### Example Configurations diff --git a/operator/builtin/input/journald.go b/operator/builtin/input/journald.go index 41f4d80c1..e18c23b6f 100644 --- a/operator/builtin/input/journald.go +++ b/operator/builtin/input/journald.go @@ -27,6 +27,7 @@ func init() { func NewJournaldInputConfig(operatorID string) *JournaldInputConfig { return &JournaldInputConfig{ InputConfig: helper.NewInputConfig(operatorID, "journald_input"), + StartAt: "end", } } @@ -36,6 +37,7 @@ type JournaldInputConfig struct { Directory *string `json:"directory,omitempty" yaml:"directory,omitempty"` Files []string `json:"files,omitempty" yaml:"files,omitempty"` + StartAt string `json:"start_at,omitempty" yaml:"start_at,omitempty"` } // Build will build a journald input operator from the supplied configuration @@ -56,6 +58,14 @@ func (c JournaldInputConfig) Build(buildContext operator.BuildContext) (operator // Continue watching logs until cancelled args = append(args, "--follow") + switch c.StartAt { + case "end": + case "beginning": + args = append(args, "--no-tail") + default: + return nil, fmt.Errorf("invalid value '%s' for parameter 'start_at'", c.StartAt) + } + switch { case c.Directory != nil: args = append(args, "--directory", *c.Directory)