-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathwindows_event_log_windows.go
More file actions
69 lines (55 loc) · 1.72 KB
/
Copy pathwindows_event_log_windows.go
File metadata and controls
69 lines (55 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
//go:build windows
package windows_event_log
import (
"context"
_ "embed"
"fmt"
"os"
"sync"
logstatecommon "github.com/aws/amazon-cloudwatch-agent-test/test/log_state/common"
"github.com/aws/amazon-cloudwatch-agent-test/util/common"
"github.com/aws/amazon-cloudwatch-agent-test/util/common/logs"
)
const tmpConfigPath = "C:\\Users\\Administrator\\AppData\\Local\\Temp\\config.json"
//go:embed resources/config.json
var testConfigJSON string
func Validate() error {
if err := os.WriteFile(tmpConfigPath, []byte(testConfigJSON), 0644); err != nil {
return fmt.Errorf("could not create config file: %w", err)
}
return logstatecommon.Validate(new(generatorStarter), tmpConfigPath)
}
type generatorStarter struct {
generator *logs.Generator
}
var _ logstatecommon.GeneratorStarter = (*generatorStarter)(nil)
func (g *generatorStarter) Init(_ string) error {
writer := &windowsEventWriter{
eventLogName: "Application",
eventLogLevel: "INFORMATION",
}
generator, err := logs.NewGenerator(&logs.GeneratorConfig{
LinesPerSecond: 1,
LineLength: 50,
TimestampFormat: "2006-01-02T15:04:05.000",
}, writer)
if err != nil {
return fmt.Errorf("could not create logs generator: %v", err)
}
g.generator = generator
return nil
}
func (g *generatorStarter) Start(ctx context.Context, wg *sync.WaitGroup) {
wg.Add(1)
go g.generator.Generate(ctx, wg)
}
type windowsEventWriter struct {
eventLogName string
eventLogLevel string
}
var _ logs.EntryWriter = (*windowsEventWriter)(nil)
func (w windowsEventWriter) Write(entry string) error {
return common.CreateWindowsEvent(w.eventLogName, w.eventLogLevel, "1", entry)
}