Skip to content

Sekoia.io: handle null value#2917

Open
squioc wants to merge 2 commits into
developfrom
fix/SekoiaIOTriggerNullValue
Open

Sekoia.io: handle null value#2917
squioc wants to merge 2 commits into
developfrom
fix/SekoiaIOTriggerNullValue

Conversation

@squioc

@squioc squioc commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Fix the way the trigger handles null values in some parameters of an alert.

Summary by Sourcery

Handle null or absent alert attributes safely in Sekoia.io triggers and document the fix.

Bug Fixes:

  • Ensure alert triggers correctly process events when message.attributes is null or missing.
  • Prevent failures when alert status, rule, verdict, custom_status, urgency, entity, alert_type, or rule fields are null in alert payloads.

Enhancements:

  • Improve alert trigger robustness by consistently defaulting nullable nested fields to empty dictionaries before access.

Build:

  • Bump Sekoia.io module version to 2.74.5.

Documentation:

  • Add changelog entry describing the fix for handling absent or null values in triggers.

Tests:

  • Extend alert trigger tests to cover alerts and comments with null attributes and nested fields.

@squioc
squioc requested review from a team, Copilot and mchupeau-sk July 22, 2026 15:55
@squioc squioc added the bug Something isn't working label Jul 22, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The PR hardens Sekoia.io alert triggers against null or missing values in alert payloads and extends tests to validate behavior when alert attributes or nested fields are None, plus bumps the integration version and changelog.

Flow diagram for null-safe alert attribute handling in handle_event

flowchart TD
    M[message]
    HE[handle_event]
    AA["alert_attrs = message.get(attributes) or {}"]
    ST["status_dict = alert.get(status) or {}"]
    CS["custom_status_dict = alert.get(custom_status) or {}"]
    VG["verdict_dict = alert.get(verdict) or {}"]
    UR["urgency_dict = alert.get(urgency) or {}"]
    EN["entity_dict = alert.get(entity) or {}"]
    AT["alert_type_dict = alert.get(alert_type) or {}"]
    RL["rule_dict = alert.get(rule) or {}"]
    OUT[build alert_payload]

    M --> HE
    HE --> AA
    HE --> ST
    HE --> CS
    HE --> VG
    HE --> UR
    HE --> EN
    HE --> AT
    HE --> RL
    ST --> OUT
    CS --> OUT
    VG --> OUT
    UR --> OUT
    EN --> OUT
    AT --> OUT
    RL --> OUT
    AA --> OUT
Loading

File-Level Changes

Change Details Files
Alert triggers now safely handle null or missing attributes and nested alert fields when building events and managing alert state/thresholds.
  • Replace dict.get(..., {}) patterns on message attributes with message.get("attributes") or {} to avoid None values breaking subsequent access.
  • Wrap alert.get(...) calls for nested objects like status, custom_status, verdict, urgency, entity, alert_type, and rule with (alert.get(field) or {}) before accessing subkeys, ensuring None does not cause attribute errors.
  • Update rule UUID/name extraction in threshold/state management helpers to use (alert.get("rule") or {}) to guard against null rule objects.
Sekoia.io/sekoiaio/triggers/alerts.py
Tests now cover alert update and comment triggers with null parameters and attributes, ensuring events are still produced and other notifications are ignored.
  • Extend invalid alert message tests to include a case where attributes is explicitly None.
  • Add parametrized tests for AlertUpdatedTrigger with samples where status, rule, verdict, or custom_status are None, verifying only appropriate notifications produce events.
  • Add parametrized tests for AlertCommentCreatedTrigger with samples where status or rule are None, including mocked alert and comment API responses, and asserting correct event dispatch behavior.
Sekoia.io/tests/ic_oc_triggers/test_alerts.py
Versioning and changelog updated to reflect the null-handling fix release.
  • Add a new changelog entry for version 2.74.5 describing the fix for absent or null values in triggers.
  • Bump the integration version from 2.74.4 to 2.74.5 in the manifest.
Sekoia.io/CHANGELOG.md
Sekoia.io/manifest.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The alert payload assembly logic now repeats (alert.get("field") or {}) patterns in multiple places; consider extracting a small helper function to centralize this null-safe nested access and keep the trigger code more readable.
  • The parametrized sample alert dictionaries are duplicated between test_trigger_updated_alert_with_null_parameters and test_trigger_comment_created_with_null_parameters; you could move them to a shared fixture or factory to reduce repetition and make future updates easier.
  • The fake API base URL (http://fake.url/api/v1/sic/alerts/...) is hard-coded in several tests; using a shared constant or fixture for the base URL would simplify maintenance if those endpoints ever change.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The alert payload assembly logic now repeats `(alert.get("field") or {})` patterns in multiple places; consider extracting a small helper function to centralize this null-safe nested access and keep the trigger code more readable.
- The parametrized `sample` alert dictionaries are duplicated between `test_trigger_updated_alert_with_null_parameters` and `test_trigger_comment_created_with_null_parameters`; you could move them to a shared fixture or factory to reduce repetition and make future updates easier.
- The fake API base URL (`http://fake.url/api/v1/sic/alerts/...`) is hard-coded in several tests; using a shared constant or fixture for the base URL would simplify maintenance if those endpoints ever change.

## Individual Comments

### Comment 1
<location path="Sekoia.io/CHANGELOG.md" line_range="14" />
<code_context>
+
+### Fixed
+
+- Fix the way to handle absent or null values in the triggers
+
 ## 2026-07-22 - 2.74.4
</code_context>
<issue_to_address>
**suggestion (typo):** Consider rephrasing this entry for clearer grammar.

The current wording is slightly awkward. Consider "Fix handling of absent or null values in triggers" or "Fix how absent or null values are handled in triggers" for smoother readability.

```suggestion
- Fix handling of absent or null values in triggers
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread Sekoia.io/CHANGELOG.md

### Fixed

- Fix the way to handle absent or null values in the triggers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (typo): Consider rephrasing this entry for clearer grammar.

The current wording is slightly awkward. Consider "Fix handling of absent or null values in triggers" or "Fix how absent or null values are handled in triggers" for smoother readability.

Suggested change
- Fix the way to handle absent or null values in the triggers
- Fix handling of absent or null values in triggers

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the Sekoia.io alert-related triggers against null/missing fields in incoming notifications and Alert API payloads, adds regression tests for these cases, and releases the fix as module version 2.74.5.

Changes:

  • Make trigger handlers tolerate message["attributes"] being null by defaulting to {}.
  • Guard access to nullable nested alert fields (status, rule, verdict, custom_status, etc.) when building outgoing event payloads.
  • Extend trigger tests to include Alert API responses with null values for nested fields; bump manifest version and add a changelog entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Sekoia.io/sekoiaio/triggers/alerts.py Adds null-safe defaults for notification attributes and nested alert fields when constructing trigger events.
Sekoia.io/tests/ic_oc_triggers/test_alerts.py Adds coverage for notifications / alert payloads containing null attributes and nested fields.
Sekoia.io/manifest.json Bumps module version to 2.74.5.
Sekoia.io/CHANGELOG.md Adds a 2.74.5 changelog entry describing the fix.

Comment on lines +99 to 103
"urgency": (alert.get("urgency") or {}).get("current_value"),
"entity": (alert.get("entity") or {}),
"alert_type": (alert.get("alert_type") or {}),
"rule": {"name": (alert.get("rule") or {}).get("name"), "uuid": (alert.get("rule") or {}).get("uuid")},
"last_seen_at": alert.get("last_seen_at"),
Comment thread Sekoia.io/CHANGELOG.md

### Fixed

- Fix the way to handle absent or null values in the triggers

@PierrickV PierrickV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be a pydantic model ? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants