Automated weekly PagerDuty analytics reports sent to Slack workflows, with AI-powered summaries.
Prerequisites:
Get the pager duty API token by following instruction here. Copy the generated token and add it to your .env file:
PD_API_TOKEN=your_token_hereNote: The API token only needs read permissions. The script does not modify any PagerDuty data.s and on-call user tracking.
- π Weekly Analytics: Incidents, interruptions, sleep-hour interruptions, and SEVs
- π Trend Analysis: Compare current week vs previous week with percentage changes
- π₯ On-Call Tracking: Shows who was on-call during the reporting period
- π€ AI Summaries: Uses Ollama for intelligent report summarization
- π Flexible Scheduling: Built-in cron support or ad-hoc historical reports
- π³ Docker Ready: Containerized for easy deployment
- π Debug Mode: Comprehensive logging for troubleshooting
-
Checkout the repository locally
-
Run the setup script
./scripts/setup.sh
This will:
- Check Node.js version
- Install npm dependencies
- Install and configure Ollama (if needed)
- Set up environment configuration
- Test the installation
-
Edit your configuration
# Edit .env with your actual credentials nano .env -
Run reports
# Test with debug mode npm run dev # Current week npm start # Previous week npm run last-week
If you prefer to set up manually:
-
Install dependencies
npm install
-
Install Ollama
# macOS brew install ollama # or curl -fsSL https://ollama.ai/install.sh | sh # Start Ollama server ollama serve # Pull a model ollama pull llama3.2:3b
-
Configure environment
cp .env.example .env # Edit .env with your credentials
Copy .env.example to .env and fill in your values:
cp .env.example .env| Variable | Description | Example |
|---|---|---|
PD_API_TOKEN |
PagerDuty API token | u+YrzuXhx2s2kxzzeuGg |
PD_TEAM_IDS |
Comma-separated team IDs | TEAM_ID_1,TEAM_ID_2 |
PD_TEAM_NAME |
Team name for AI summaries | Observability |
PD_SCHEDULES |
Comma-separated schedule IDs | SCHEDULE_ID_1,SCHEDULE_ID_2 |
SLACK_WORKFLOW_WEBHOOK_URL |
Slack workflow webhook URL | https://hooks.slack.com/triggers/... |
OLLAMA_MODEL |
Ollama model to use | llama3.2:3b |
| Variable | Description | Default |
|---|---|---|
PD_TIMEZONE |
Timezone for reports | America/Chicago |
OLLAMA_BASE_URL |
Ollama server URL | http://localhost:11434 |
ENABLE_CRON |
Enable automatic scheduling | false |
CRON_EXPR |
Cron expression | 0 9 * * 1 (9am Mondays) |
CRON_TZ |
Cron timezone | Same as PD_TIMEZONE |
DEBUG |
Enable debug logging | false |
- Log in to PagerDuty for your organization
- Click on "My Profile" (usually in the top-right menu)
- Click on the "User Settings" tab
- Click "Create API User Token" button
- Give it a description (e.g., "Weekly Reports Script")
- Copy the generated token and add it to your
.envfile:PD_API_TOKEN=your_token_here
Team IDs:
- Go to People β Teams in PagerDuty
- Click on your team name
- The team ID is in the URL:
https://yourorg.pagerduty.com/teams/PXXXXXX - Use
PXXXXXXas your team ID
Schedule IDs:
- Go to People β On-Call Schedules
- Click on your schedule name
- The schedule ID is in the URL:
https://yourorg.pagerduty.com/schedules/PXXXXXX - Use
PXXXXXXas your schedule ID
-
Import the pre-configured workflow:
- Open Slack Workflow Builder in your browser (only browser/desktop, not mobile supported)
- Click "Create" β "Import"
- Select
slack-workflow-template.jsonfrom this repository - Configure the message recipients (channels/users)
- Publish the workflow and copy the webhook URL
-
Detailed setup guide: See SLACK_SETUP.md for complete instructions
-
Open Slack Workflow Builder
- Go to your Slack workspace β "Tools" β "Workflow Builder"
-
Create New Workflow
- Click "Create Workflow" β "Webhook" trigger
- Configure webhook parameters:
ai_summary,period_label
-
Add Message Steps
- Add "Send a message to a channel" steps
- Use webhook data to format messages
- Copy the webhook URL to your
.envfile - You can use variables like
{{text}}for the message text - Use
{{blocks}}to include the rich formatting
-
Publish Workflow
- Test the workflow
- Publish it when ready
npm install# Current week report (default behavior)
node index.js
# Generate report for last week (last Monday to previous Monday)
node index.js --last-week
# or
node index.js -l
# Generate report for N weeks ago
node index.js --weeks-ago 2 # 2 weeks ago
node index.js -w 3 # 3 weeks ago
# Show help
node index.js --helpThe webhook receives structured data that can be used in your workflow:
The webhook receives structured data that can be used in your Slack workflow. Below are the inputs and their descriptions:
period_label: A string representing the reporting period (e.g., "Last Week", "Current Week").current_incidents: The total number of incidents that occurred during the reporting period.incident_trend: A comparison of incidents between the current and previous reporting periods (e.g., "up 10%", "down 5%").current_interruptions: The total number of interruptions during the reporting period.interruptions_trend: A comparison of interruptions between the current and previous reporting periods.current_sleep_interruptions: The total number of sleep-hour interruptions during the reporting period.sleep_interruptions_trend: A comparison of sleep-hour interruptions between the current and previous reporting periods.previous_interruptions: The total number of interruptions in the previous reporting period.previous_sleep_interruptions: The total number of sleep-hour interruptions in the previous reporting period.ai_summary: An AI-generated summary of the report, providing key insights and highlights.message_text: A plain-text version of the report, suitable for simple Slack messages.message_blocks: A rich-text formatted version of the report, designed for Slack's block kit.
These inputs can be used to dynamically populate your Slack messages with relevant data and formatting.
- Webhook URL: Make sure your
SLACK_WORKFLOW_WEBHOOK_URLis correct and the workflow is published - Permissions: Ensure the workflow has permission to post to your target channel
- Testing: Use Slack's workflow test feature to verify the webhook integration works
The tool supports several command-line options for ad-hoc report generation:
# Last week's report (most common ad-hoc use case)
node index.js --last-week
# Report from 2 weeks ago
node index.js --weeks-ago 2
# Report from any number of weeks ago
node index.js -w 5- Current week (default): Previous Monday 00:00 to this Monday 00:00
- Last week (
--last-week): Two Mondays ago to last Monday - N weeks ago (
--weeks-ago N): Reports for the Monday-to-Monday period N weeks in the past
This is particularly useful for:
- Generating missed reports
- Historical analysis
- Backfilling data
- Testing with known data ranges
The included slack-workflow-template.json file is a pre-configured Slack workflow that you can import directly into your Slack workspace. This template:
- β Ready to use: No need to build workflow from scratch
- π§ Customizable: Easy to modify recipients and formatting
- π Formatted: Proper rich text formatting for reports
- π Quick setup: Import, configure recipients, get webhook URL
To use: See the detailed guide in SLACK_SETUP.md