Skip to content

[pkg/stanza/operator/input/windows] [receiver/windowseventlogreceiver] add raw XML query support #39055

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

Merged
merged 3 commits into from
Apr 28, 2025

Conversation

OverOrion
Copy link
Contributor

@OverOrion OverOrion commented Mar 31, 2025

Example usage

receivers:
  windowseventlog/query:
    raw: true
    query: |
      <QueryList>
        <Query Id="0">
          <Select Path="Application">*[System[Provider[@Name='foo']]]</Select>
          <Select Path="Application">*[System[Provider[@Name='bar']]]</Select>
        </Query>
      </QueryList>

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    logs/query:
      receivers: [windowseventlog/query]
      exporters: [debug]

I tested it using eventcreate:

eventcreate /t ERROR /id 100 /l application /d "Create event in application log"  /so foo

@github-actions github-actions bot requested a review from djaglowski March 31, 2025 10:55
@OverOrion OverOrion force-pushed the feat/eventlog-query-main branch 2 times, most recently from e5bd2d7 to 5133f5d Compare March 31, 2025 11:07
@OverOrion OverOrion force-pushed the feat/eventlog-query-main branch from 5133f5d to 8c5d9a7 Compare March 31, 2025 11:24
@github-actions github-actions bot requested review from armstrmi and pjanotti March 31, 2025 11:24
@songy23 songy23 added the Run Windows Enable running windows test on a PR label Mar 31, 2025
Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OverOrion sorry for the delay - this is looking good! We will need a test before this can be approved and merged. It will be good to add some examples and links on the README.md - something like https://learn.microsoft.com/en-us/previous-versions/aa385231(v=vs.85)#xml-event-queries for instance.

@OverOrion OverOrion force-pushed the feat/eventlog-query-main branch from 8c5d9a7 to 3c3c107 Compare April 15, 2025 14:04
@OverOrion
Copy link
Contributor Author

Hey @pjanotti

I have extended the README with a sample configuration, let me know if that's what you had in your mind.

@OverOrion OverOrion marked this pull request as ready for review April 15, 2025 14:05
@OverOrion OverOrion requested a review from a team as a code owner April 15, 2025 14:05
@OverOrion OverOrion requested a review from pjanotti April 15, 2025 14:05
@pjanotti
Copy link
Contributor

Hi @OverOrion - I was in a short break last week, will take a look soon.

Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OverOrion - changes are looking good, the test that I was thinking about would be like the ones in receiver/windowseventlogreceiver/receiver_windows_test.go, but, using the Query on the config. Perhaps TestReadWindowsEventLogger

@OverOrion
Copy link
Contributor Author

Added a similar test:

> go test -count=1 . -v
=== RUN   TestNewFactory
=== RUN   TestNewFactory/NewFactoryCorrectType
--- PASS: TestNewFactory (0.00s)
    --- PASS: TestNewFactory/NewFactoryCorrectType (0.00s)
=== RUN   TestCreateDefaultConfig
--- PASS: TestCreateDefaultConfig (0.00s)
=== RUN   TestCreateAndShutdown
--- PASS: TestCreateAndShutdown (0.00s)
=== RUN   TestComponentFactoryType
--- PASS: TestComponentFactoryType (0.00s)
=== RUN   TestComponentConfigStruct
--- PASS: TestComponentConfigStruct (0.00s)
=== RUN   TestComponentLifecycle
=== RUN   TestComponentLifecycle/logs-shutdown
=== RUN   TestComponentLifecycle/logs-lifecycle
--- PASS: TestComponentLifecycle (0.00s)
    --- PASS: TestComponentLifecycle/logs-shutdown (0.00s)
    --- PASS: TestComponentLifecycle/logs-lifecycle (0.00s)
=== RUN   TestDefaultConfig
--- PASS: TestDefaultConfig (0.00s)
=== RUN   TestLoadConfig
--- PASS: TestLoadConfig (0.00s)
=== RUN   TestCreateWithInvalidInputConfig
--- PASS: TestCreateWithInvalidInputConfig (0.00s)
=== RUN   TestReadWindowsEventLogger
--- PASS: TestReadWindowsEventLogger (4.51s)
=== RUN   TestReadWindowsEventLoggerWithQuery
--- PASS: TestReadWindowsEventLoggerWithQuery (4.51s)
=== RUN   TestReadWindowsEventLoggerRaw
--- PASS: TestReadWindowsEventLoggerRaw (4.55s)
=== RUN   TestExcludeProvider
=== RUN   TestExcludeProvider/with_EventXML
=== RUN   TestExcludeProvider/with_Raw
--- PASS: TestExcludeProvider (9.09s)
    --- PASS: TestExcludeProvider/with_EventXML (4.28s)
    --- PASS: TestExcludeProvider/with_Raw (4.26s)
PASS
ok      github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowseventlogreceiver      22.719s

@OverOrion OverOrion requested a review from pjanotti April 28, 2025 07:18
Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @OverOrion!

CI failure is unrelated, tracking via #39691

@djaglowski djaglowski merged commit 054557a into open-telemetry:main Apr 28, 2025
324 of 326 checks passed
@github-actions github-actions bot added this to the next release milestone Apr 28, 2025
vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 6, 2025
…] add raw XML query support (open-telemetry#39055)

Example usage 

```yaml
receivers:
  windowseventlog/query:
    raw: true
    query: |
      <QueryList>
        <Query Id="0">
          <Select Path="Application">*[System[Provider[@name='foo']]]</Select>
          <Select Path="Application">*[System[Provider[@name='bar']]]</Select>
        </Query>
      </QueryList>

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    logs/query:
      receivers: [windowseventlog/query]
      exporters: [debug]
```

I tested it using `eventcreate`:
```powershell
eventcreate /t ERROR /id 100 /l application /d "Create event in application log"  /so foo
```

---------

Signed-off-by: Szilard Parrag <[email protected]>
vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 20, 2025
…] add raw XML query support (open-telemetry#39055)

Example usage 

```yaml
receivers:
  windowseventlog/query:
    raw: true
    query: |
      <QueryList>
        <Query Id="0">
          <Select Path="Application">*[System[Provider[@name='foo']]]</Select>
          <Select Path="Application">*[System[Provider[@name='bar']]]</Select>
        </Query>
      </QueryList>

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    logs/query:
      receivers: [windowseventlog/query]
      exporters: [debug]
```

I tested it using `eventcreate`:
```powershell
eventcreate /t ERROR /id 100 /l application /d "Create event in application log"  /so foo
```

---------

Signed-off-by: Szilard Parrag <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants