AgentSkillsCN

pagerduty-helper

通过 REST API 完成 PagerDuty 操作——管理事件、排班表、值班安排、服务与自动化编排流程 当用户提及 PagerDuty、事件、值班安排、排班表、升级机制、页面通知与告警时

SKILL.md
--- frontmatter
name: pagerduty-helper
description: |
  Complete PagerDuty operations via REST API - incidents, schedules, oncall, services, orchestrations
  When user mentions PagerDuty, incidents, oncall, schedules, escalation, pages, alerts

PagerDuty Helper Agent

Overview

Complete PagerDuty operations via REST API. This skill replaces PagerDuty MCP server functionality, providing API equivalents for all operations.

MCP Tool Equivalents Reference

MCP ToolAPI Equivalent
list_incidentscurl "$API/incidents"
get_incidentcurl "$API/incidents/{id}"
get_outlier_incidentcurl "$API/incidents/{id}/outlier_incident"
get_past_incidentscurl "$API/incidents/{id}/past_incidents"
get_related_incidentscurl "$API/incidents/{id}/related_incidents"
list_incident_notescurl "$API/incidents/{id}/notes"
list_incident_workflowscurl "$API/incident_workflows"
get_incident_workflowcurl "$API/incident_workflows/{id}"
list_servicescurl "$API/services"
get_servicecurl "$API/services/{id}"
list_teamscurl "$API/teams"
get_teamcurl "$API/teams/{id}"
list_team_memberscurl "$API/teams/{id}/members"
list_userscurl "$API/users"
get_user_datacurl "$API/users/me"
list_schedulescurl "$API/schedules"
get_schedulecurl "$API/schedules/{id}"
list_schedule_userscurl "$API/schedules/{id}/users"
list_oncallscurl "$API/oncalls"
list_escalation_policiescurl "$API/escalation_policies"
get_escalation_policycurl "$API/escalation_policies/{id}"
list_event_orchestrationscurl "$API/event_orchestrations"
get_event_orchestrationcurl "$API/event_orchestrations/{id}"
get_event_orchestration_routercurl "$API/event_orchestrations/{id}/router"
get_event_orchestration_servicecurl "$API/event_orchestrations/services/{service_id}"
get_event_orchestration_globalcurl "$API/event_orchestrations/{id}/global"
list_alert_grouping_settingscurl "$API/alert_grouping_settings"
get_alert_grouping_settingcurl "$API/alert_grouping_settings/{id}"
list_change_eventscurl "$API/change_events"
get_change_eventcurl "$API/change_events/{id}"
list_service_change_eventscurl "$API/services/{id}/change_events"
list_incident_change_eventscurl "$API/incidents/{id}/related_change_events"
list_status_pagescurl "$API/status_pages"
list_status_page_severitiescurl "$API/status_pages/{id}/severities"
list_status_page_impactscurl "$API/status_pages/{id}/impacts"
list_status_page_statusescurl "$API/status_pages/{id}/statuses"
get_status_page_postcurl "$API/status_pages/{id}/posts/{post_id}"
list_status_page_post_updatescurl "$API/status_pages/{id}/posts/{post_id}/post_updates"

Configuration

bash
# Set environment variables
export PAGERDUTY_TOKEN="your-api-token"
export API="https://api.pagerduty.com"

# Standard headers
AUTH="Authorization: Token token=$PAGERDUTY_TOKEN"
ACCEPT="Accept: application/vnd.pagerduty+json;version=2"
CONTENT="Content-Type: application/json"

# Test connection
curl -H "$AUTH" -H "$ACCEPT" "$API/users/me"

Incident Operations

List Incidents

bash
# All incidents
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents"

# Filter by status
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents?statuses[]=triggered&statuses[]=acknowledged"

# Filter by service
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents?service_ids[]=$SERVICE_ID"

# Filter by team
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents?team_ids[]=$TEAM_ID"

# Filter by date range
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents?since=2024-01-01T00:00:00Z&until=2024-01-31T23:59:59Z"

# Filter by urgency
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents?urgencies[]=high"

# Sort and limit
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents?sort_by=created_at:desc&limit=10"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents" | \
  jq '.incidents[] | {id, title, status, urgency, created_at}'

Get Incident Details

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents/$INCIDENT_ID"

# With additional info
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents/$INCIDENT_ID?include[]=acknowledgers&include[]=assignees"

Get Outlier Incident

bash
# Get outlier analysis for an incident
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents/$INCIDENT_ID/outlier_incident"

# With time range
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents/$INCIDENT_ID/outlier_incident?since=2024-01-01T00:00:00Z"

Get Past Incidents

bash
# Get similar past incidents
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents/$INCIDENT_ID/past_incidents"

# With limit
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents/$INCIDENT_ID/past_incidents?limit=5"

Get Related Incidents

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents/$INCIDENT_ID/related_incidents"

# With additional details
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents/$INCIDENT_ID/related_incidents?additional_details[]=incident"

List Incident Notes

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/incidents/$INCIDENT_ID/notes"

# Add a note
curl -X POST -H "$AUTH" -H "$ACCEPT" -H "$CONTENT" \
  -H "From: user@example.com" \
  "$API/incidents/$INCIDENT_ID/notes" \
  -d '{
    "note": {
      "content": "Investigation update: found the root cause"
    }
  }'

Acknowledge/Resolve Incident

bash
# Acknowledge
curl -X PUT -H "$AUTH" -H "$ACCEPT" -H "$CONTENT" \
  -H "From: user@example.com" \
  "$API/incidents/$INCIDENT_ID" \
  -d '{
    "incident": {
      "type": "incident_reference",
      "status": "acknowledged"
    }
  }'

# Resolve
curl -X PUT -H "$AUTH" -H "$ACCEPT" -H "$CONTENT" \
  -H "From: user@example.com" \
  "$API/incidents/$INCIDENT_ID" \
  -d '{
    "incident": {
      "type": "incident_reference",
      "status": "resolved"
    }
  }'

Service Operations

List Services

bash
# All services
curl -H "$AUTH" -H "$ACCEPT" "$API/services"

# Search by name
curl -H "$AUTH" -H "$ACCEPT" "$API/services?query=production"

# Filter by team
curl -H "$AUTH" -H "$ACCEPT" "$API/services?team_ids[]=$TEAM_ID"

# Include integrations
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/services?include[]=integrations&include[]=escalation_policies"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/services" | \
  jq '.services[] | {id, name, status, description}'

Get Service Details

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/services/$SERVICE_ID"

# With integrations
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/services/$SERVICE_ID?include[]=integrations"

List Service Change Events

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/services/$SERVICE_ID/change_events"

# With time range
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/services/$SERVICE_ID/change_events?since=2024-01-01T00:00:00Z"

Team Operations

List Teams

bash
# All teams
curl -H "$AUTH" -H "$ACCEPT" "$API/teams"

# Search by name
curl -H "$AUTH" -H "$ACCEPT" "$API/teams?query=platform"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/teams" | \
  jq '.teams[] | {id, name, description}'

Get Team Details

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/teams/$TEAM_ID"

List Team Members

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/teams/$TEAM_ID/members"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/teams/$TEAM_ID/members" | \
  jq '.members[] | {user: .user.summary, role: .role}'

User Operations

List Users

bash
# All users
curl -H "$AUTH" -H "$ACCEPT" "$API/users"

# Search by name/email
curl -H "$AUTH" -H "$ACCEPT" "$API/users?query=john"

# Filter by team
curl -H "$AUTH" -H "$ACCEPT" "$API/users?team_ids[]=$TEAM_ID"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/users" | \
  jq '.users[] | {id, name, email, role}'

Get Current User

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/users/me"

# With contact methods
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/users/me?include[]=contact_methods&include[]=notification_rules"

Schedule Operations

List Schedules

bash
# All schedules
curl -H "$AUTH" -H "$ACCEPT" "$API/schedules"

# Search by name
curl -H "$AUTH" -H "$ACCEPT" "$API/schedules?query=primary"

# Include schedule layers
curl -H "$AUTH" -H "$ACCEPT" "$API/schedules?include[]=schedule_layers"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/schedules" | \
  jq '.schedules[] | {id, name, time_zone}'

Get Schedule Details

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/schedules/$SCHEDULE_ID"

# For specific time range
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/schedules/$SCHEDULE_ID?since=2024-01-01&until=2024-01-07"

List Schedule Users

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/schedules/$SCHEDULE_ID/users"

# For specific time range
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/schedules/$SCHEDULE_ID/users?since=2024-01-01&until=2024-01-07"

On-Call Operations

List On-Calls

bash
# Current on-call
curl -H "$AUTH" -H "$ACCEPT" "$API/oncalls"

# Filter by schedule
curl -H "$AUTH" -H "$ACCEPT" "$API/oncalls?schedule_ids[]=$SCHEDULE_ID"

# Filter by escalation policy
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/oncalls?escalation_policy_ids[]=$POLICY_ID"

# Filter by user
curl -H "$AUTH" -H "$ACCEPT" "$API/oncalls?user_ids[]=$USER_ID"

# Only earliest on-call per combination
curl -H "$AUTH" -H "$ACCEPT" "$API/oncalls?earliest=true"

# With time range
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/oncalls?since=2024-01-01T00:00:00Z&until=2024-01-07T00:00:00Z"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/oncalls" | \
  jq '.oncalls[] | {
    user: .user.summary,
    schedule: .schedule.summary,
    escalation_policy: .escalation_policy.summary,
    level: .escalation_level,
    start: .start,
    end: .end
  }'

Escalation Policy Operations

List Escalation Policies

bash
# All policies
curl -H "$AUTH" -H "$ACCEPT" "$API/escalation_policies"

# Search by name
curl -H "$AUTH" -H "$ACCEPT" "$API/escalation_policies?query=engineering"

# Filter by team
curl -H "$AUTH" -H "$ACCEPT" "$API/escalation_policies?team_ids[]=$TEAM_ID"

# Include services and teams
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/escalation_policies?include[]=services&include[]=teams"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/escalation_policies" | \
  jq '.escalation_policies[] | {id, name, num_loops}'

Get Escalation Policy Details

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/escalation_policies/$POLICY_ID"

# Get escalation rules
curl -H "$AUTH" -H "$ACCEPT" "$API/escalation_policies/$POLICY_ID" | \
  jq '.escalation_policy.escalation_rules[] | {
    level: .escalation_delay_in_minutes,
    targets: [.targets[].summary]
  }'

Event Orchestration Operations

List Event Orchestrations

bash
# All orchestrations
curl -H "$AUTH" -H "$ACCEPT" "$API/event_orchestrations"

# Sort by name
curl -H "$AUTH" -H "$ACCEPT" "$API/event_orchestrations?sort_by=name:asc"

# JSON output
curl -H "$AUTH" -H "$ACCEPT" "$API/event_orchestrations" | \
  jq '.orchestrations[] | {id, name, routes: .routes}'

Get Event Orchestration

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/event_orchestrations/$ORCHESTRATION_ID"

Get Event Orchestration Router

bash
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/event_orchestrations/$ORCHESTRATION_ID/router"

Get Event Orchestration Service

bash
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/event_orchestrations/services/$SERVICE_ID"

Get Event Orchestration Global

bash
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/event_orchestrations/$ORCHESTRATION_ID/global"

Alert Grouping Settings

List Alert Grouping Settings

bash
# All settings
curl -H "$AUTH" -H "$ACCEPT" "$API/alert_grouping_settings"

# Filter by service
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/alert_grouping_settings?service_ids[]=$SERVICE_ID"

Get Alert Grouping Setting

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/alert_grouping_settings/$SETTING_ID"

Change Events Operations

List Change Events

bash
# All change events
curl -H "$AUTH" -H "$ACCEPT" "$API/change_events"

# Filter by time range
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/change_events?since=2024-01-01T00:00:00Z&until=2024-01-31T23:59:59Z"

# Filter by team
curl -H "$AUTH" -H "$ACCEPT" "$API/change_events?team_ids[]=$TEAM_ID"

# Filter by integration
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/change_events?integration_ids[]=$INTEGRATION_ID"

Get Change Event

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/change_events/$CHANGE_EVENT_ID"

List Incident Change Events

bash
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incidents/$INCIDENT_ID/related_change_events"

Incident Workflow Operations

List Incident Workflows

bash
# All workflows
curl -H "$AUTH" -H "$ACCEPT" "$API/incident_workflows"

# Search by name
curl -H "$AUTH" -H "$ACCEPT" "$API/incident_workflows?query=triage"

# Include steps and team
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/incident_workflows?include[]=steps&include[]=team"

Get Incident Workflow

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/incident_workflows/$WORKFLOW_ID"

Status Page Operations

List Status Pages

bash
# All status pages
curl -H "$AUTH" -H "$ACCEPT" "$API/status_pages"

# Filter by type
curl -H "$AUTH" -H "$ACCEPT" "$API/status_pages?status_page_type=public"

List Status Page Severities

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/status_pages/$STATUS_PAGE_ID/severities"

# Filter by post type
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/status_pages/$STATUS_PAGE_ID/severities?post_type=incident"

List Status Page Impacts

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/status_pages/$STATUS_PAGE_ID/impacts"

# Filter by post type
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/status_pages/$STATUS_PAGE_ID/impacts?post_type=maintenance"

List Status Page Statuses

bash
curl -H "$AUTH" -H "$ACCEPT" "$API/status_pages/$STATUS_PAGE_ID/statuses"

Get Status Page Post

bash
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/status_pages/$STATUS_PAGE_ID/posts/$POST_ID"

# Include updates
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/status_pages/$STATUS_PAGE_ID/posts/$POST_ID?include[]=status_page_post_update"

List Status Page Post Updates

bash
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/status_pages/$STATUS_PAGE_ID/posts/$POST_ID/post_updates"

# Filter by review status
curl -H "$AUTH" -H "$ACCEPT" \
  "$API/status_pages/$STATUS_PAGE_ID/posts/$POST_ID/post_updates?reviewed_status=approved"

Creating Incidents

Trigger via Events API v2

bash
curl -X POST -H "Content-Type: application/json" \
  "https://events.pagerduty.com/v2/enqueue" \
  -d '{
    "routing_key": "your-integration-key",
    "event_action": "trigger",
    "dedup_key": "unique-incident-key",
    "payload": {
      "summary": "Critical: Database connection pool exhausted",
      "severity": "critical",
      "source": "production-db-01",
      "custom_details": {
        "pool_size": "100",
        "active_connections": "98"
      }
    },
    "links": [{
      "href": "https://monitoring.example.com/dashboard",
      "text": "View Dashboard"
    }]
  }'

Create via REST API

bash
curl -X POST -H "$AUTH" -H "$ACCEPT" -H "$CONTENT" \
  -H "From: user@example.com" \
  "$API/incidents" \
  -d '{
    "incident": {
      "type": "incident",
      "title": "Critical database issue",
      "service": {
        "id": "SERVICE_ID",
        "type": "service_reference"
      },
      "urgency": "high",
      "body": {
        "type": "incident_body",
        "details": "Database is experiencing high load"
      }
    }
  }'

Common Workflows

Dashboard Script

bash
#!/bin/bash
echo "=== Open Incidents ==="
curl -sH "$AUTH" -H "$ACCEPT" \
  "$API/incidents?statuses[]=triggered&statuses[]=acknowledged" | \
  jq -r '.incidents[] | "\(.id)\t\(.title)\t\(.status)\t\(.urgency)"' | \
  column -t -s$'\t'

echo ""
echo "=== Currently On-Call ==="
curl -sH "$AUTH" -H "$ACCEPT" "$API/oncalls?earliest=true" | \
  jq -r '.oncalls[] | "\(.user.summary)\t\(.escalation_policy.summary)"' | \
  column -t -s$'\t'

Who's On-Call Script

bash
#!/bin/bash
# Show who's on-call for each escalation policy

curl -sH "$AUTH" -H "$ACCEPT" "$API/oncalls?earliest=true" | \
  jq -r '.oncalls[] | [
    .escalation_policy.summary,
    .user.summary,
    .schedule.summary // "Direct",
    .escalation_level
  ] | @tsv' | \
  sort | \
  column -t -s$'\t'

Incident Response Script

bash
#!/bin/bash
INCIDENT_ID=$1
ACTION=$2

case $ACTION in
  ack)     STATUS="acknowledged" ;;
  resolve) STATUS="resolved" ;;
  *)       echo "Usage: $0 <incident-id> <ack|resolve>"; exit 1 ;;
esac

curl -X PUT -H "$AUTH" -H "$ACCEPT" -H "$CONTENT" \
  -H "From: $USER_EMAIL" \
  "$API/incidents/$INCIDENT_ID" \
  -d "{\"incident\":{\"type\":\"incident_reference\",\"status\":\"$STATUS\"}}"

CLI Tools

pd CLI (Third-party)

bash
# Install
go install github.com/martindstone/pagerduty-cli/pd@latest

# Configure
pd auth:set --token $PAGERDUTY_TOKEN

# List incidents
pd incident:list

# Acknowledge incident
pd incident:ack --ids INCIDENT_ID

# Resolve incident
pd incident:resolve --ids INCIDENT_ID

# Show on-call
pd schedule:oncall --schedule-id SCHEDULE_ID

When to Ask for Help

Ask the user for clarification when:

  • PagerDuty account or service ID is not specified
  • User email is needed for incident updates but not provided
  • Incident severity or urgency classification is ambiguous
  • Integration key vs API key usage is unclear
  • Multiple services, schedules, or teams match the description