Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows events #3246

Merged
merged 28 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d2c8112
First commit for windows event targets.
cyriltovena Dec 20, 2020
1f9cb05
Add the ability to save where we are.
cyriltovena Jan 25, 2021
042d22b
Finished setup tests and comments.
cyriltovena Jan 27, 2021
70204a3
nits
cyriltovena Jan 27, 2021
e639452
adding documentation
cyriltovena Jan 27, 2021
a2487b7
go tidy
cyriltovena Jan 27, 2021
f4ceb9c
go.mod fun
cyriltovena Jan 27, 2021
bc1245e
lint windows
cyriltovena Jan 27, 2021
4c8f49c
nope
cyriltovena Jan 27, 2021
825ce3e
add manager for non windows
cyriltovena Jan 27, 2021
afc5869
don't lint forked package
cyriltovena Jan 27, 2021
5c229be
mod check
cyriltovena Jan 27, 2021
5062184
Update pkg/promtail/targets/windows/bookmark.go
cyriltovena Jan 28, 2021
0722ed6
Merge remote-tracking branch 'upstream/master' into windows_events
cyriltovena Feb 1, 2021
83f0708
Use passed-in Prometheus registerer.
cyriltovena Feb 1, 2021
8ae11f3
Apply suggestions from code review
cyriltovena Feb 1, 2021
2b39c7b
testing out windows drone.
cyriltovena Feb 1, 2021
7dc2063
Merge branch 'windows_events' of github.com:grafana/loki into windows…
cyriltovena Feb 1, 2021
7b41ba1
type exec.
cyriltovena Feb 1, 2021
23e1980
docker image.
cyriltovena Feb 1, 2021
24d9ef4
go/go.exe
cyriltovena Feb 1, 2021
7043e1c
build windows on container.
cyriltovena Feb 1, 2021
5aaf324
trying another image.
cyriltovena Feb 1, 2021
b2496a6
typo in image
cyriltovena Feb 1, 2021
6a76b8f
Fixed local timezone issue.
cyriltovena Feb 1, 2021
2a8b211
Fix tests with timezone.
cyriltovena Feb 1, 2021
68dc467
Fixes timezone tests.
cyriltovena Feb 2, 2021
c7f782b
Update logstash since the last image is not working anymore :shrug:
cyriltovena Feb 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ local arch_image(arch, tags='') = {
}],
};

local promtail_win() = pipeline('promtail-windows') {
platform: {
os: 'windows',
arch: "amd64",
version: "1809",
},
steps: [{
name: 'test',
image: 'golang:windowsservercore-1809',
commands: [
'go test .\\pkg\\promtail\\targets\\windows\\... -v',
],
}],
};

local fluentbit() = pipeline('fluent-bit-amd64') + arch_image('amd64', 'latest,master') {
steps+: [
// dry run for everything that is not tag or master
Expand Down Expand Up @@ -200,7 +215,7 @@ local manifest(apps) = pipeline('manifest') {
make('check-generated-files', container=false) { depends_on: ['clone'] },
make('check-mod', container=false) { depends_on: ['clone', 'test', 'lint'] },
],
},
}
] + [
multiarch_image(arch) + (
// When we're building Promtail for ARM, we want to use Dockerfile.arm32 to fix
Expand Down Expand Up @@ -273,4 +288,4 @@ local manifest(apps) = pipeline('manifest') {
},
],
},
]
] + [promtail_win()]
15 changes: 15 additions & 0 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -862,4 +862,19 @@ trigger:
depends_on:
- manifest

---
kind: pipeline
name: promtail-windows

platform:
os: windows
arch: amd64
version: 1809

steps:
- name: test
image: golang:windowsservercore-1809
commands:
- go test .\pkg\promtail\targets\windows\... -v

...
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ run:
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- win_eventlog$
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
Expand Down
2 changes: 1 addition & 1 deletion cmd/logstash/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM logstash:7.6.2
FROM logstash:7.9.3

USER logstash
ENV PATH /usr/share/logstash/vendor/jruby/bin:/usr/share/logstash/vendor/bundle/jruby/2.5.0/bin:$PATH
Expand Down
16 changes: 16 additions & 0 deletions cmd/promtail/promtail-windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server:
http_listen_port: 9080
grpc_listen_port: 0

clients:
- url: http://localhost:3100/loki/api/v1/push

scrape_configs:
- job_name: windows
windows_events:
use_incoming_timestamp: false
bookmark_path: "./bookmark.xml"
eventlog_name: "Application"
xpath_query: '*'
labels:
job: windows
62 changes: 62 additions & 0 deletions docs/sources/clients/promtail/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and how to scrape logs from files.
- [syslog](#syslog)
- [Available Labels](#available-labels)
- [loki_push_api](#loki_push_api)
- [windows_events] (#windows_events)
- [relabel_configs](#relabel_configs)
- [static_configs](#static_configs)
- [file_sd_config](#file_sd_config)
Expand Down Expand Up @@ -809,6 +810,67 @@ labels:

See [Example Push Config](#example-push-config)


### windows_events

The `windows_events` block configures Promtail to scrape windows event logs and send them to Loki.

To subcribe to a specific events stream you need to provide either an `eventlog_name` or an `xpath_query`.

Events are scraped periodically every 3 seconds by default but can be changed using `poll_interval`.

A bookmark path `bookmark_path` is mandatory and will be used as a position file where Promtail will
keep record of the last event processed. This file persists across promtail restarts.

You can set `use_incoming_timestamp` if you want to keep incomming event timestamps. By default Promtail will use the timestamp when
the event was read from the event log.

Promtail will serialize JSON windows events, adding `channel` and `computer` labels from the event received.
You can add additional labels with the `labels` property.


```yaml
# LCID (Locale ID) for event rendering
# - 1033 to force English language
# - 0 to use default Windows locale
[locale: <int> | default = 0]

# Name of eventlog, used only if xpath_query is empty
# Example: "Application"
[eventlog_name: <string> | default = ""]

# xpath_query can be in defined short form like "Event/System[EventID=999]"
# or you can form a XML Query. Refer to the Consuming Events article:
# https://docs.microsoft.com/en-us/windows/win32/wes/consuming-events
# XML query is the recommended form, because it is most flexible
# You can create or debug XML Query by creating Custom View in Windows Event Viewer
# and then copying resulting XML here
[xpath_query: <string> | default = "*"]

# Sets the bookmark location on the filesystem.
# The bookmark contains the current position of the target in XML.
# When restarting or rolling out promtail, the target will continue to scrape events where it left off based on the bookmark position.
# The position is updated after each entry processed.
[bookmark_path: <string> | default = ""]

# PollInterval is the interval at which we're looking if new events are available. By default the target will check every 3seconds.
[poll_interval: <duration> | default = 3s]

# Allows to exclude the xml event data.
[exclude_event_data: <bool> | default = false]

# Allows to exclude the user data of each windows event.
[exclude_event_data: <bool> | default = false]

# Label map to add to every log line sent to the push API
labels:
[ <labelname>: <labelvalue> ... ]

# If promtail should pass on the timestamp from the incoming log or not.
# When false promtail will assign the current timestamp to the log when it was processed
[use_incoming_timestamp: <bool> | default = false]
```

### relabel_configs

Relabeling is a powerful tool to dynamically rewrite the label set of a target
Expand Down
32 changes: 31 additions & 1 deletion docs/sources/clients/promtail/scraping.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ Keep in mind that labels prefixed with `__` will be dropped, so relabeling is re
target_label: syslog_identifier
```

## Windows Event Log

On Windows Promtail supports reading from the event log.
Windows event targets can be configured using the `windows_events` stanza:


```yaml
scrape_configs:
- job_name: windows
windows_events:
use_incoming_timestamp: false
bookmark_path: "./bookmark.xml"
eventlog_name: "Application"
xpath_query: '*'
labels:
job: windows
relabel_configs:
- source_labels: ['computer']
target_label: 'host'
```

When Promtail receives an event it will attach the `channel` and `computer` labels
and serialize the event in json.
You can relabel default labels via [Relabeling](#relabeling) if required.

Providing a path to a bookmark is mandatory, it will be used to persist the last event processed and allow
resuming the target without skipping logs.

see the [configuration](./configuration#windows_event) section for more information.

## Gcplog scraping
Promtail supports scraping cloud resource logs(say GCS bucket logs, Load Balancer logs, Kubernetes Cluster logs) from GCP.
Configs are set in `gcplog` section in `scrape_config`
Expand Down Expand Up @@ -296,5 +326,5 @@ clients:
- [ <client_option> ]
```

Refer to [`client_config`](../configuration#client_config) from the Promtail
Refer to [`client_config`](./configuration#client_config) from the Promtail
Configuration reference for all available options.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/hpcloud/tail v1.0.0
github.com/imdario/mergo v0.3.9
github.com/influxdata/go-syslog/v3 v3.0.1-0.20200510134747-836dce2cf6da
github.com/influxdata/telegraf v1.16.3
github.com/jmespath/go-jmespath v0.4.0
github.com/joncrlsn/dque v2.2.1-0.20200515025108-956d14155fa2+incompatible
github.com/json-iterator/go v1.1.10
Expand All @@ -52,6 +53,7 @@ require (
github.com/segmentio/fasthash v1.0.2
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
github.com/spf13/afero v1.2.2
github.com/stretchr/testify v1.6.1
github.com/tonistiigi/fifo v0.0.0-20190226154929-a9fb20d87448
github.com/uber/jaeger-client-go v2.25.0+incompatible
Expand All @@ -61,6 +63,7 @@ require (
go.uber.org/atomic v1.7.0
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
golang.org/x/net v0.0.0-20201224014010-6772e930b67b
golang.org/x/sys v0.0.0-20201223074533-0d417f636930
google.golang.org/api v0.36.0
google.golang.org/grpc v1.33.2
gopkg.in/alecthomas/kingpin.v2 v2.2.6
Expand All @@ -79,6 +82,8 @@ replace k8s.io/client-go => k8s.io/client-go v0.19.4

replace k8s.io/api => k8s.io/api v0.19.4

replace github.com/hashicorp/consul => github.com/hashicorp/consul v1.5.1
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved

// >v1.2.0 has some conflict with prometheus/alertmanager. Hence prevent the upgrade till it's fixed.
replace github.com/satori/go.uuid => github.com/satori/go.uuid v1.2.0

Expand Down
Loading