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

Http post2 alternate jinja root #1104

Merged
merged 10 commits into from
Feb 11, 2023

Conversation

akusei
Copy link
Contributor

@akusei akusei commented Feb 10, 2023

Description

  • Added support for multiline JSON strings in YAML fields (similar to alert_text)
    http_post2_payload: |
      {
        "description": "An event came from IP {{ _data["client.ip"] }}",
        "username": "{{ _data['username'] }}"
        {%- for k, v in some_field.items() -%}
        ,"{{ k }}": "changed_{{ v }}"
        {%- endfor -%}
      }
    http_post2_headers: |
      {
        "authorization": "Basic 123dr3234",
        "X-custom-{{key}}": "{{type}}"
      }
  • Added jinja_root_name support to the HTTP POST2 alerter
  • Changed the --data argument for rule testing to accept both a file with a single JSON document or a file with a proper JSON list of objects
    Example file with single JSON object
{"fieldname": "value"}

Example file with list of JSON objects:

[{"fieldname":"value1"},{"fieldname":"value2"}]
  • Additional error checking has been added around JSON decoding and jinja templates for HTTP POST2 headers and payloads

Checklist

  • I have reviewed the contributing guidelines.
  • I have included unit tests for my changes or additions.
  • I have successfully run make test-docker with my changes.
  • I have manually tested all relevant modes of the change in this PR.
  • I have updated the documentation.
  • I have updated the changelog.

Questions or Comments

The change to --data for rule testing was added just for convenience. I was doing some testing and didn't realize the document needed to be a list of JSON objects. I didn't see anything stating it needed to be a list so I changed the code to allow for a single JSON object in the file or a list of JSON objects. The intent of this PR was not to make this change so if it's not wanted I'm okay with removing it

Copy link
Owner

@jertel jertel left a comment

Choose a reason for hiding this comment

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

Nice job on this PR and the extensive unit test coverage. Thank you!

@jertel jertel merged commit 443ac8f into jertel:master Feb 11, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants