Added the Send Event command to the PagerDuty Integration#969
Added the Send Event command to the PagerDuty Integration#969tyler-horschig wants to merge 4 commits into
Conversation
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>
Summary of ChangesHello, 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 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 AssistThe 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
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 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
|
|
❌ Integration Tests Failed Click to view the full report🧩 pager_duty
❌ Failed Teststests/test_defaults/test_imports.py::test_imports |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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
- All function parameters and return types must be annotated, and Google Style Docstrings must be used for all functions. (link)
| 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) |
There was a problem hiding this comment.
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
- 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)
| 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 |
There was a problem hiding this comment.
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 jsonReferences
- SDK imports must use soar_sdk.* namespace, and internal imports must be relative. (link)
| @@ -0,0 +1,46 @@ | |||
| from __future__ import annotations | |||
There was a problem hiding this comment.
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
- All new features or integrations must include corresponding unit tests modeled after the reference examples. (link)
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:
Open-Source Specific Checks:
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.