Skip to content

Commit

Permalink
Updated variable retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
twerthi committed Jan 6, 2025
1 parent 30d12d2 commit 8c9d5f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion step-templates/pagerduty-create-incident.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Properties": {
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "# Gather Octopus variables\n$pagerDutyToken = $OctopusParameters['PagerDuty.API.Token']\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}"
"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}"
},
"Parameters": [
{
Expand Down

0 comments on commit 8c9d5f6

Please sign in to comment.