Octopus.Script exported 2020-07-23 by tfbryan belongs to ‘PagerDuty’ category.
Closes a maintenance window by Id.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Token
Token =
The API token of the PagerDuty instance.
Found here: https://mydomain.pagerduty.com/api_keys
OpeningStepName
OpeningStepName =
The previous step in which the window to close was opened.
Script body
Steps based on this template will execute the following PowerShell script.
param(
[string]$OpeningStepName = "",
[string]$Token = ""
)
function Get-Param($Name, [switch]$Required, $Default) {
$Result = $null
if ($OctopusParameters -ne $null) {
$Result = $OctopusParameters[$Name]
}
if ($Result -eq $null) {
$variable = Get-Variable $Name -EA SilentlyContinue
if ($variable -ne $null) {
$Result = $variable.Value
}
}
if ($Result -eq $null -or $Result -eq "") {
if ($Required) {
throw "Missing parameter value $Name"
} else {
$Result = $Default
}
}
return $Result
}
& {
param([string]$OpeningStepName, [string]$Token)
$WindowId = $OctopusParameters["Octopus.Action[$OpeningStepName].Output.WindowId"]
$Uri = "https://api.pagerduty.com/maintenance_windows/$WindowId"
$Headers = @{
"Authorization" = "Token token=$Token"
"Accept" = "application/vnd.pagerduty+json;version=2"
}
try {
Invoke-RestMethod -Uri $Uri -Method Delete -ContentType "application/json" -Headers $Headers
Write-Host "PagerDuty window closed for window_id: $WindowId"
} catch [System.Exception] {
Write-Host $_.Exception.Message
$ResponseStream = $_.Exception.Response.GetResponseStream()
$Reader = New-Object System.IO.StreamReader($ResponseStream)
$Reader.ReadToEnd() | Write-Host
Exit 0
}
} (Get-Param 'OpeningStepName' -Required) (Get-Param 'Token' -Required)
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "4841c8e6-3f23-4b52-90d0-c363eb0bc526",
"Name": "PagerDuty - Close Maintenance Window",
"Description": "Closes a maintenance window by Id.",
"Version": 8,
"ExportedAt": "2020-07-23T07:38:49.056Z",
"ActionType": "Octopus.Script",
"Author": "tfbryan",
"Parameters": [
{
"Name": "Token",
"Label": "Token",
"HelpText": "The API token of the PagerDuty instance.\n\nFound here: https://mydomain.pagerduty.com/api_keys",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "OpeningStepName",
"Label": "OpeningStepName",
"HelpText": "The **previous** step in which the window to close was opened.",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "StepName"
}
}
],
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
"Octopus.Action.Script.ScriptBody": "param(\n [string]$OpeningStepName = \"\",\n [string]$Token = \"\"\n) \n\nfunction Get-Param($Name, [switch]$Required, $Default) {\n $Result = $null\n\n if ($OctopusParameters -ne $null) {\n $Result = $OctopusParameters[$Name]\n }\n\n if ($Result -eq $null) {\n $variable = Get-Variable $Name -EA SilentlyContinue \n if ($variable -ne $null) {\n $Result = $variable.Value\n }\n }\n\n if ($Result -eq $null -or $Result -eq \"\") {\n if ($Required) {\n throw \"Missing parameter value $Name\"\n } else {\n $Result = $Default\n }\n }\n\n return $Result\n}\n\n& {\n param([string]$OpeningStepName, [string]$Token)\n\n\t$WindowId = $OctopusParameters[\"Octopus.Action[$OpeningStepName].Output.WindowId\"]\n $Uri = \"https://api.pagerduty.com/maintenance_windows/$WindowId\"\n $Headers = @{\n \"Authorization\" = \"Token token=$Token\"\n \"Accept\" = \"application/vnd.pagerduty+json;version=2\"\n\t\t}\n\n\ttry {\n\t\tInvoke-RestMethod -Uri $Uri -Method Delete -ContentType \"application/json\" -Headers $Headers\n\t\tWrite-Host \"PagerDuty window closed for window_id: $WindowId\"\n\t} catch [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-Host\n\n\t\tExit 0\n }\n} (Get-Param 'OpeningStepName' -Required) (Get-Param 'Token' -Required)"
},
"Category": "PagerDuty",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/pagerduty-close-maintenance-window.json",
"Website": "/step-templates/4841c8e6-3f23-4b52-90d0-c363eb0bc526",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABhQTFRF////QbwAveatVcMrmtp9N7oA1+/NcMxCz2uBkgAAAsJJREFUeNrsm9ua6iAMRktIwvu/8WzHK20NR1vds9bXa+jqD4ht2DYAAAAAAAAAAAAAAAAA+Au4PZK/VUQePVL53kTSA4gggggiiCCCCCKIIIIIIogggggiiCDyN0VcSoyK97aopUpOK0Vcy+115Q17caXfN5qlVca9ZLu3aeGVFopoSa38u7MsDRq7B93MuIgU6+2rlkpJ4wyLaOr1SBaH4jMeoyKebaQ3C7oTs/NFfP1Q1jRHOdfjZYeSLhCZG8x62GS6QmTK43gZzleIzD69vH6CjIkUm+vSfNEaOCmi6/tcEEi/yNxMv+PLZ8iAiMyPAtPlTQ6I6OGWMOCo1/oqaFVmRcp+B1UkQnOuTPe9SKXJ32ZnRfJunHj/RkDCNatlwz/9D/H5pkxHtjQl2p1Y03+wWRF5uqfsI+PxoVe1cAa9SWRsaD6vSzlosinj9SJjveYgkY8W2XpE5AoRe0MiQiIkQiIkQiIkQiIkQiIkQiIkQiIkQiIkQiIkQiIkQiIkQiKLEylflIj3fLH6pkSib4iNTcoliWhUEahWrR5aN1nnEtl9SS/RLTV9nn6utWockJMPooS9ykBR9e7LvfmsiNcQrZRw7AsjbhUcYYtqlfKWfpGUaxzVB8eBVZs9aHJJcdAnlDnJJSIS/+6P1En6FSL7UkBb3uQZIvuVcrrqt3vNWpNIfX1eUhT9bpGjn67ZSPwKkcOnJ+cuWStEXqwvZd1qfo7Iy1M95dQ8pkWC00mja/BQHpMiOTpl5TpSkJ3H8pgSsVqn/cfPkvp2soil0lAgLKXn3ELW0ThGRcxy6/FQ0ZIaTo3Zrf7bt22diDUUsfcdcnXX+2wJjoX2H5td9PLhA/lfRRKJkAiJkAiJkAiJkAiJkAiJkAiJkAiJkAiJkMhXiDy9D/1aEXeRh2sDAAAAAAAAAAAAAAAAgIAfAQYAXo0zRlgxYJcAAAAASUVORK5CYII=",
"$Meta": {
"Type": "ActionTemplate"
}
}
Page updated on Thursday, July 23, 2020