Skip to content

Add automatic PagerDuty environment variables to ocm-container#137

Merged
clcollins merged 2 commits intomainfrom
add-pagerduty-env-vars
Mar 13, 2026
Merged

Add automatic PagerDuty environment variables to ocm-container#137
clcollins merged 2 commits intomainfrom
add-pagerduty-env-vars

Conversation

@clcollins
Copy link
Owner

@clcollins clcollins commented Mar 12, 2026

Summary

This PR automatically passes PagerDuty incident and alert information as environment variables when launching ocm-container via the login feature (pressing l on an incident).

Changes

  • New environment variables automatically set in ocm-container:

    • PAGERDUTY_INCIDENT - Contains the PagerDuty incident ID
    • ALERT_DETAILS - Base64 URL-encoded JSON containing the full incident object, all associated alerts, and incident notes
  • Implementation:

    • Modified login() function in pkg/tui/commands.go to:
      • Accept incident, alerts, and notes as parameters
      • Serialize incident/alert/notes data to JSON
      • Base64 URL encode the JSON (without padding to avoid parsing issues)
      • Add -e flags to pass environment variables to ocm-container
      • Correctly position env flags after terminal separator and ocm-container command
    • Updated call site in pkg/tui/tui.go to pass incident, alert, and notes data
    • Added alertData struct to encapsulate the data being passed
  • Bug Fix:

    • Fixed ocm-container env var parsing error by using base64.RawURLEncoding instead of base64.StdEncoding
    • Standard base64 padding uses = characters which broke ocm-container's parser (splits on = and expects max 2 parts)
    • RawURLEncoding (RFC 4648) eliminates padding while maintaining full data integrity
  • Testing:

    • Added comprehensive unit tests in pkg/tui/commands_test.go to verify:
      • JSON serialization of alertData with incident, alerts, and notes
      • Base64 URL encoding without padding characters
      • Data integrity after round-trip encoding/decoding
      • All combinations of incident/alerts/notes (nil, empty, populated)
  • Documentation:

    • Updated README.md with new section on automatic PagerDuty environment variables
    • Documented base64 URL encoding usage and rationale
    • Included usage examples for accessing incident, alerts, and notes from within ocm-container

Benefits

  • Users can access full incident, alert, and notes details from within ocm-container without manual configuration
  • Enables better context awareness during on-call operations
  • Allows scripting and automation based on incident data (e.g., extracting cluster details, SOP links, alert severity, previous notes)

Example Usage

Inside ocm-container after login:

# View the incident ID
echo $PAGERDUTY_INCIDENT

# Decode and view the full alert details
echo $ALERT_DETAILS | base64 -d | jq .

# Extract specific alert information
echo $ALERT_DETAILS | base64 -d | jq '.alerts[0].body.details.cluster_id'

# View incident notes
echo $ALERT_DETAILS | base64 -d | jq '.notes'

Technical Details

The ALERT_DETAILS JSON structure:

{
  "incident": { /* full PagerDuty incident object */ },
  "alerts": [ /* array of incident alerts */ ],
  "notes": [ /* array of incident notes */ ]
}

Command structure generated:

gnome-terminal -- ocm-container -e PAGERDUTY_INCIDENT=<id> -e ALERT_DETAILS=<base64> --cluster-id <cluster>

The -e flags are correctly positioned after the terminal separator (--) and the ocm-container command, but before ocm-container's arguments.

Test Plan

  • Unit tests pass for alertData serialization (4/4 test cases)
  • Binary builds successfully
  • All new tests pass
  • No = padding characters in base64 output (verified in tests)
  • Verified command structure in debug logs
  • Tested with live incident - environment variables successfully set in ocm-container

🤖 Generated with Claude Code

clcollins and others added 2 commits March 12, 2026 11:21
This change automatically passes PagerDuty incident and alert information
as environment variables when launching ocm-container via the login feature.

Changes:
- Add PAGERDUTY_INCIDENT environment variable containing the incident ID
- Add ALERT_DETAILS environment variable with base64-encoded JSON of
  incident and alert data
- Update login() function to serialize incident/alert data and pass via
  -e flags to ocm-container
- Add unit tests for alertData serialization and base64 encoding
- Update README with documentation on the new automatic environment variables

This allows users to access full incident and alert details from within
ocm-container without manual configuration, enabling better context
awareness during on-call operations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit fixes a critical bug where ocm-container's environment
variable parser was rejecting the ALERT_DETAILS variable due to
base64 padding characters (=).

Changes:
- Use base64.RawURLEncoding instead of StdEncoding to eliminate padding
- Add incident notes to the alertData structure passed to ocm-container
- Update login() function to accept and include notes parameter
- Add comprehensive tests for all combinations of incident/alerts/notes
- Update README to document notes inclusion and URL encoding

The ocm-container env var parser splits on '=' and fails when there
are more than 2 parts. Standard base64 padding uses '=' characters:
"Length of env string split > 2 for env: ALERT_DETAILS=..."

Using RawURLEncoding (RFC 4648) eliminates padding while maintaining
full data integrity. The encoded data can still be decoded with
standard base64 -d inside ocm-container.

ALERT_DETAILS now contains:
- Full incident object
- All associated alerts
- All incident notes

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@clcollins clcollins merged commit 9f8db70 into main Mar 13, 2026
1 of 2 checks passed
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