Skip to content

Commit a3102d5

Browse files
authored
Merge pull request #1578 from OctopusDeploy/pagerduty-create-incident
Created new PagerDuty template
2 parents 6b70cb9 + 8c9d5f6 commit a3102d5

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"Id": "38a1ab46-b8dd-48b4-ab21-73068c737a43",
3+
"Name": "PagerDuty - Create Incident",
4+
"Description": "Creates an Incident against a PagerDuty Service.",
5+
"ActionType": "Octopus.Script",
6+
"Version": 1,
7+
"CommunityActionTemplateId": null,
8+
"Packages": [],
9+
"GitDependencies": [],
10+
"Properties": {
11+
"Octopus.Action.Script.ScriptSource": "Inline",
12+
"Octopus.Action.Script.Syntax": "PowerShell",
13+
"Octopus.Action.Script.ScriptBody": "# Gather Octopus variables\n$pagerDutyToken = $OctopusParameters['PagerDuty.API.AuthorizationToken']\n$incidentTitle = $OctopusParameters['PagerDuty.Incident.Title']\n$serviceId = $OctopusParameters['PagerDuty.Service.Id']\n$incidentPriority = $OctopusParameters['PagerDuty.Priority.Code']\n$incidentUrgency = $OctopusParameters['PagerDuty.Urgency.Code']\n$escalationPolicyId = $OctopusParameters['PagerDuty.EscalationPolicy.Id']\n$incidentDetails = $OctopusParameters['PagerDuty.Body.Details']\n$pagerDutyFrom = \"Octopus Deploy Project: $($OctopusParameters['Octopus.Project.Name']) Environment $($OctopusParameters['Octopus.Environment.Name'])\"\n\n# Configure request headers\n$headers = @{\n \"Authorization\" = \"Token token=$pagerDutyToken\"\n \"Content-Type\" = \"application/json\"\n \"Accept\" = \"application/json\"\n \"From\" = \"$pagerDutyFrom\"\n}\n\n# Build Incident Object\n$incidentPayload = @{\n incident = @{\n type = \"incident\"\n title = $incidentTitle\n service = @{\n id = $serviceId\n type = \"service_reference\"\n }\n \n urgency = $incidentUrgency\n body = @{\n type = \"incident_body\"\n details = $incidentDetails\n }\n }\n}\n\n# Check to see if an escalation id was specified\nif (![string]::IsNullOrWhitespace($escalationPolicyId))\n{\n $policyDetails = @{\n type = \"escalation_policy_reference\"\n id = $escalationPolicyId\n }\n\n $incidentPayload.incident.Add(\"escalation_policy\", $policyDetails)\n}\n\n\n# Get Priority\n$priorities = (Invoke-RestMethod -Method Get -Uri \"https://api.pagerduty.com/priorities\" -Headers $headers)\n$priority = ($priorities.priorities | Where-Object {$_.Name -eq $incidentPriority})\n\n# Add priority to body\n$priorityBody = @{\n id = \"$($priority.id)\"\n type = \"priority_reference\"\n}\n$incidentPayload.incident.Add(\"priority\", $priorityBody)\n\n# Submit incident\ntry\n{\n $responseResult = Invoke-RestMethod -Method Post -Uri \"https://api.pagerduty.com/incidents\" -Body ($incidentPayload | ConvertTo-Json -Depth 10) -Headers $headers\n Write-Host \"Successfully created incident.\"\n $responseResult.incident\n}\ncatch [System.Exception] {\n Write-Host $_.Exception.Message\n \n $ResponseStream = $_.Exception.Response.GetResponseStream()\n $Reader = New-Object System.IO.StreamReader($ResponseStream)\n $Reader.ReadToEnd() | Write-Error\n}"
14+
},
15+
"Parameters": [
16+
{
17+
"Id": "39ed5ced-1b7e-4d69-af4a-dbac5a4bf7df",
18+
"Name": "PagerDuty.API.AuthorizationToken",
19+
"Label": "Token",
20+
"HelpText": "\n\nPlease supply the API token of your PagerDuty instance.\n\nFound here: https://mydomain.pagerduty.com/api_keys",
21+
"DefaultValue": "",
22+
"DisplaySettings": {
23+
"Octopus.ControlType": "Sensitive"
24+
}
25+
},
26+
{
27+
"Id": "c092e897-15df-4561-8505-f76650cdec01",
28+
"Name": "PagerDuty.Incident.Title",
29+
"Label": "Title",
30+
"HelpText": "Please enter a title for this incident.",
31+
"DefaultValue": "",
32+
"DisplaySettings": {
33+
"Octopus.ControlType": "SingleLineText"
34+
}
35+
},
36+
{
37+
"Id": "9d048098-25cb-4736-8523-97eed8e15f3a",
38+
"Name": "PagerDuty.Body.Details",
39+
"Label": "Details",
40+
"HelpText": "Please enter the details of the Incident.",
41+
"DefaultValue": "",
42+
"DisplaySettings": {
43+
"Octopus.ControlType": "MultiLineText"
44+
}
45+
},
46+
{
47+
"Id": "cdc36097-7255-4f58-bf3b-afb4ae1b80c6",
48+
"Name": "PagerDuty.Service.Id",
49+
"Label": "Service Id",
50+
"HelpText": "Please enter the Service Id for the Incident.",
51+
"DefaultValue": "",
52+
"DisplaySettings": {
53+
"Octopus.ControlType": "SingleLineText"
54+
}
55+
},
56+
{
57+
"Id": "888bd996-ef6a-4d06-b8a0-7afd7dc888b7",
58+
"Name": "PagerDuty.Priority.Code",
59+
"Label": "Priority",
60+
"HelpText": "Please select a Priority level for the Incident.",
61+
"DefaultValue": "",
62+
"DisplaySettings": {
63+
"Octopus.ControlType": "Select",
64+
"Octopus.SelectOptions": "None|None\nP1|P1\nP2|P2\nP3|P3\nP4|P4\nP5|P5"
65+
}
66+
},
67+
{
68+
"Id": "dcf56174-8588-448d-8ab0-1d7285f6b5e2",
69+
"Name": "PagerDuty.Urgency.Code",
70+
"Label": "Urgency",
71+
"HelpText": "Please enter an Urgency for the Incident.",
72+
"DefaultValue": "",
73+
"DisplaySettings": {
74+
"Octopus.ControlType": "Select",
75+
"Octopus.SelectOptions": "high|High\nlow|Low"
76+
}
77+
},
78+
{
79+
"Id": "45206809-1211-454b-a724-fe0e924ed11c",
80+
"Name": "PagerDuty.EscalationPolicy.Id",
81+
"Label": "Escalation Policy Id",
82+
"HelpText": "Please enter an Escalation Policy Id, leave blank if you don't have one.",
83+
"DefaultValue": "",
84+
"DisplaySettings": {
85+
"Octopus.ControlType": "SingleLineText"
86+
}
87+
}
88+
],
89+
"StepPackageId": "Octopus.Script",
90+
"$Meta": {
91+
"ExportedAt": "2024-12-20T22:23:43.782Z",
92+
"OctopusVersion": "2024.4.7005",
93+
"Type": "ActionTemplate"
94+
},
95+
"LastModifiedBy": "twerthi",
96+
"Category": "pagerduty"
97+
}

0 commit comments

Comments
 (0)