Skip to content

Commit

Permalink
window_event_input config add mapstructure support (#62)
Browse files Browse the repository at this point in the history
* eventLog add mapstructure support
  • Loading branch information
wph95 authored Mar 16, 2021
1 parent 81f80e6 commit eb3a760
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
14 changes: 7 additions & 7 deletions operator/builtin/input/windows/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import (
)

func init() {
operator.Register("windows_eventlog_input", NewDefaultConfig)
operator.Register("windows_eventlog_input", func() operator.Builder { return NewDefaultConfig() })
}

// EventLogConfig is the configuration of a windows event log operator.
type EventLogConfig struct {
helper.InputConfig `yaml:",inline"`
Channel string `json:"channel" yaml:"channel"`
MaxReads int `json:"max_reads,omitempty" yaml:"max_reads,omitempty"`
StartAt string `json:"start_at,omitempty" yaml:"start_at,omitempty"`
PollInterval helper.Duration `json:"poll_interval,omitempty" yaml:"poll_interval,omitempty"`
helper.InputConfig `mapstructure:",squash" yaml:",inline"`
Channel string `mapstructure:"channel" json:"channel" yaml:"channel"`
MaxReads int `mapstructure:"max_reads,omitempty" json:"max_reads,omitempty" yaml:"max_reads,omitempty"`
StartAt string `mapstructure:"start_at,omitempty" json:"start_at,omitempty" yaml:"start_at,omitempty"`
PollInterval helper.Duration `mapstructure:"poll_interval,omitempty" json:"poll_interval,omitempty" yaml:"poll_interval,omitempty"`
}

// Build will build a windows event log operator.
Expand Down Expand Up @@ -73,7 +73,7 @@ func (c *EventLogConfig) Build(context operator.BuildContext) ([]operator.Operat
}

// NewDefaultConfig will return an event log config with default values.
func NewDefaultConfig() operator.Builder {
func NewDefaultConfig() *EventLogConfig {
return &EventLogConfig{
InputConfig: helper.NewInputConfig("", "windows_eventlog_input"),
MaxReads: 100,
Expand Down
47 changes: 47 additions & 0 deletions operator/builtin/input/windows/operator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build windows

package windows

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/open-telemetry/opentelemetry-log-collection/entry"
"github.com/open-telemetry/opentelemetry-log-collection/operator/helper"
)

func TestEventLogConfig(t *testing.T) {
expect := NewDefaultConfig()
expect.WriteTo = entry.NewRecordField("to")

input := map[string]interface{}{
"id": "",
"type": "windows_eventlog_input",
"max_reads": 100,
"start_at": "end",
"poll_interval": "1s",
"attributes": map[string]interface{}{},
"resource": map[string]interface{}{},
"write_to": "$record.to",
}

var actual EventLogConfig
err := helper.UnmarshalMapstructure(input, &actual)
require.NoError(t, err)
require.Equal(t, expect, &actual)
}

0 comments on commit eb3a760

Please sign in to comment.