Skip to content

Added the Send Event command to the PagerDuty Integration#969

Open
tyler-horschig wants to merge 4 commits into
chronicle:mainfrom
tyler-horschig:main
Open

Added the Send Event command to the PagerDuty Integration#969
tyler-horschig wants to merge 4 commits into
chronicle:mainfrom
tyler-horschig:main

Conversation

@tyler-horschig

Copy link
Copy Markdown

Description

Please provide a detailed description of your changes. This helps reviewers understand your work and its context.

What problem does this PR solve?
Added a new command to the current integration needed to send a page to a team in PagerDuty without creating an incident.

How does this PR solve the problem?
Added the command functionality.

Any other relevant information (e.g., design choices, tradeoffs, known issues):
N/A


Checklist:

Please ensure you have completed the following items before submitting your PR.
This helps us review your contribution faster and more efficiently.

General Checks:

  • I have read and followed the project's contributing.md guide.
  • My code follows the project's coding style guidelines.
  • I have performed a self-review of my own code.
  • My changes do not introduce any new warnings.
  • My changes pass all existing tests.
  • I have added new tests where appropriate to cover my changes. (If applicable)
  • I have updated the documentation where necessary (e.g., README, API docs). (If applicable)

Open-Source Specific Checks:

  • My changes do not introduce any Personally Identifiable Information (PII) or sensitive customer data.
  • My changes do not expose any internal-only code examples, configurations, or URLs.
  • All code examples, comments, and messages are generic and suitable for a public repository.
  • I understand that any internal context or sensitive details related to this work are handled separately in internal systems (Buganizer for Google team members).

Screenshots (If Applicable)

If your changes involve UI or visual elements, please include screenshots or GIFs here.
Ensure any sensitive data is redacted or generalized.


Further Comments / Questions

Any additional comments, questions, or areas where you'd like specific feedback.

Signed-off-by: Tyler Horschig <48213613+tyler-horschig@users.noreply.github.com>
Signed-off-by: Tyler Horschig <48213613+tyler-horschig@users.noreply.github.com>
Signed-off-by: Tyler Horschig <48213613+tyler-horschig@users.noreply.github.com>
Signed-off-by: Tyler Horschig <48213613+tyler-horschig@users.noreply.github.com>
@tyler-horschig tyler-horschig requested a review from a team as a code owner June 23, 2026 17:18
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new 'Send Event' command to the PagerDuty integration. This addition enables users to send events directly to PagerDuty for processing, providing more flexibility for automation workflows that do not require the overhead of creating formal incidents.

Highlights

  • New Send Event Command: Added a new 'Send Event' action to the PagerDuty integration, allowing users to trigger events without creating full incidents.
  • API Integration: Implemented the send_event method in PagerDutyManager to interface with the PagerDuty Events API v2.
  • Configuration: Added the necessary YAML configuration file to define the new action, including parameters for the Routing Key and JSON payload.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions

Copy link
Copy Markdown

Integration Tests Failed

Click to view the full report

🧩 pager_duty

✅ Passed ❌ Failed ⏭️ Skipped
9 1 0

❌ Failed Tests

tests/test_defaults/test_imports.py::test_imports
def test_imports() -> None:
>       import_all_integration_modules(common.INTEGRATION_PATH)

tests/test_defaults/test_imports.py:9: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.11/site-packages/integration_testing/default_tests/import_test.py:39: in import_all_integration_modules
    importlib.import_module(import_)
/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:940: in exec_module
    ???
<frozen importlib._bootstrap>:241: in _call_with_frames_removed
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    from __future__ import annotations
    
    from ScriptResult import EXECUTION_STATE_COMPLETED, EXECUTION_STATE_FAILED
    from SiemplifyAction import SiemplifyAction
    
>   from constants import INTEGRATION_NAME, SCRIPT_NAME_LISTUSERS
E   ModuleNotFoundError: No module named 'constants'

actions/SendEvent.py:6: ModuleNotFoundError

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a new 'Send Event' action for the PagerDuty integration, including the action script, YAML configuration, and a manager method. The review feedback highlights several critical issues and style guide violations: the send_event manager method silently swallows exceptions and lacks type annotations/docstrings; the SendEvent.py action script needs defensive parameter parsing, corrected error message formatting, proper boolean return values, and updated imports (using the soar_sdk namespace and relative imports); additionally, a JSON result example file and corresponding unit tests must be provided.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +34 to +44
def send_event(self, payload):
try:
response = self.requests_session.post(
"https://events.pagerduty.com/v2/enqueue",
timeout=10,
json=payload
)
response.raise_for_status()
return response.json()
except Exception as e:
return None

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.

high

The send_event method currently catches all exceptions and returns None. This causes the calling action (SendEvent.py) to proceed as if the event was successfully sent, even if the API call failed (e.g., due to network issues or HTTP errors).\n\nAdditionally, the method lacks type annotations and a Google-style docstring as required by the style guide.\n\nPlease remove the try...except block to let exceptions propagate to the action's error handler, and add the required type annotations and docstring.

    def send_event(self, payload: dict) -> dict:\n        \"\"\"Sends an event to PagerDuty.\n\n        Args:\n            payload: The payload containing event details.\n\n        Returns:\n            The JSON response from PagerDuty.\n        \"\"\"\n        response = self.requests_session.post(\n            \"https://events.pagerduty.com/v2/enqueue\",\n            timeout=10,\n            json=payload\n        )\n        response.raise_for_status()\n        return response.json()
References
  1. All function parameters and return types must be annotated, and Google Style Docstrings must be used for all functions. (link)

Comment on lines +11 to +42
def main():
siemplify = SiemplifyAction()
json_result = {}
siemplify.script_name = INTEGRATION_NAME + "Send Event"
configurations = siemplify.get_configuration(INTEGRATION_NAME)

siemplify.LOGGER.info("----------------- Main - Param Init -----------------")
routing_key = siemplify.parameters["Routing Key"]
payload = json.loads(siemplify.parameters["Payload"])

payload['routing_key'] = routing_key

siemplify.LOGGER.info("----------------- Main - Start -----------------")
pager_duty = PagerDutyManager(None)

try:
siemplify.LOGGER.info("Started sending an event to PagerDuty")
event_response = pager_duty.send_event(payload)

json_result = event_response
output_message = "Successfully Created Event\n"
result_value = "true"
status = EXECUTION_STATE_COMPLETED

except Exception as e:
output_message = f"There was an error creating a new incident.{e!s}"
result_value = False
status = EXECUTION_STATE_FAILED

siemplify.LOGGER.info("----------------- Main - Finished -----------------")
siemplify.result.add_result_json(json_result)
siemplify.end(output_message, result_value, status)

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.

high

Please refactor the main function to address the following issues:\n1. Defensive Programming / Robustness: Move parameter extraction (siemplify.parameters[...]) and JSON parsing (json.loads(...)) inside the try...except block. If the Payload parameter contains invalid JSON, the script will currently crash with an unhandled exception instead of failing gracefully.\n2. Error Message Template: The error message currently mentions "creating a new incident" (a copy-paste error) and does not follow the required format. It must use the prefix: Error executing action \"{action name}\". Reason: {error}.\n3. Result Value Consistency: Use boolean True instead of the string \"true\" for result_value to be consistent with False in the exception block.\n4. Type Annotations & Docstring: Add type annotations and a Google-style docstring to the main function.\n5. Missing JSON Result Example: Since this action returns a JSON result (add_result_json), the repository style guide requires a corresponding JSON example file to exist at content/response_integrations/third_party/community/pager_duty/resources/SendEvent_JsonResult_example.json. Please create this file.

def main() -> None:\n    \"\"\"Main execution function for Send Event action.\"\"\"\n    siemplify = SiemplifyAction()\n    siemplify.script_name = f\"{INTEGRATION_NAME} Send Event\"\n    siemplify.LOGGER.info(\"----------------- Main - Start -----------------\")\n\n    json_result = {}\n    result_value = False\n    status = EXECUTION_STATE_FAILED\n\n    try:\n        siemplify.LOGGER.info(\"----------------- Main - Param Init -----------------\")\n        routing_key = siemplify.parameters[\"Routing Key\"]\n        payload = json.loads(siemplify.parameters[\"Payload\"])\n        payload['routing_key'] = routing_key\n\n        pager_duty = PagerDutyManager(None)\n\n        siemplify.LOGGER.info(\"Started sending an event to PagerDuty\")\n        event_response = pager_duty.send_event(payload)\n\n        json_result = event_response\n        output_message = \"Successfully Created Event\\n\"\n        result_value = True\n        status = EXECUTION_STATE_COMPLETED\n\n    except Exception as e:\n        output_message = f\"Error executing action \\\"Send Event\\\". Reason: {e}\"\n        status = EXECUTION_STATE_FAILED\n\n    siemplify.LOGGER.info(\"----------------- Main - Finished -----------------\")\n    siemplify.result.add_result_json(json_result)\n    siemplify.end(output_message, result_value, status)
References
  1. Error messages must follow the standard format, JSON result example files must be provided in the resources directory, and functions must have type annotations and docstrings. (link)

Comment on lines +3 to +8
from ScriptResult import EXECUTION_STATE_COMPLETED, EXECUTION_STATE_FAILED
from SiemplifyAction import SiemplifyAction

from constants import INTEGRATION_NAME, SCRIPT_NAME_LISTUSERS
from PagerDutyManager import PagerDutyManager
import json

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.

medium

Please update the imports to adhere to the repository style guide:\n1. Use the soar_sdk namespace for SDK imports (e.g., SiemplifyAction and ScriptResult).\n2. Use relative imports for internal modules (e.g., PagerDutyManager and constants).\n3. Remove the unused import SCRIPT_NAME_LISTUSERS.

from soar_sdk.ScriptResult import EXECUTION_STATE_COMPLETED, EXECUTION_STATE_FAILED\nfrom soar_sdk.SiemplifyAction import SiemplifyAction\n\nfrom ..constants import INTEGRATION_NAME\nfrom ..core.PagerDutyManager import PagerDutyManager\nimport json
References
  1. SDK imports must use soar_sdk.* namespace, and internal imports must be relative. (link)

@@ -0,0 +1,46 @@
from __future__ import annotations

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.

medium

Please add corresponding unit tests for the new SendEvent action to ensure production stability. The tests should be modeled after the reference examples in the repository (e.g., content/response_integrations/third_party/telegram/tests/ or content/response_integrations/third_party/sample_integration/tests/) using pytest and mocking network calls.

References
  1. All new features or integrations must include corresponding unit tests modeled after the reference examples. (link)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant