Skip to content

Commit

Permalink
Add start_at parameter to journald input
Browse files Browse the repository at this point in the history
  • Loading branch information
camdencheek committed Jul 23, 2020
1 parent b1e749e commit 402f72c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/operators/journald_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions operator/builtin/input/journald.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func init() {
func NewJournaldInputConfig(operatorID string) *JournaldInputConfig {
return &JournaldInputConfig{
InputConfig: helper.NewInputConfig(operatorID, "journald_input"),
StartAt: "end",
}
}

Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 402f72c

Please sign in to comment.