Skip to content

Commit

Permalink
Merge pull request #1586 from Sam-Kudo/master
Browse files Browse the repository at this point in the history
Bugfixing Template - Statuspage Create Incident
  • Loading branch information
hnrkndrssn authored Feb 18, 2025
2 parents b69242c + 6edecbc commit 3a09940
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"Name": "StatusPage.io - Create Scheduled Maintenance Incident",
"Description": "Creates or updates a scheduled maintenance incident on StatusPage.io",
"ActionType": "Octopus.Script",
"Version": 5,
"Version": 6,
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
"Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\r\n## Input\r\n## --------------------------------------------------------------------------------------\r\n$pageId = $OctopusParameters['PageId']\r\n$apiKey = $OctopusParameters['ApiKey']\r\n$incidentName = $OctopusParameters['IncidentName']\r\n$incidentStatus = $OctopusParameters['IncidentStatus']\r\n$incidentMessage = $OctopusParameters['IncidentMessage']\r\n$componentId = $OctopusParameters['ComponentId']\r\n\r\nfunction Validate-Parameter($parameterValue, $parameterName) {\r\n if(!$parameterName -contains \"Key\") {\r\n Write-Host \"${parameterName}: ${parameterValue}\"\r\n }\r\n\r\n if (! $parameterValue) {\r\n throw \"$parameterName cannot be empty, please specify a value\"\r\n }\r\n}\r\n\r\nfunction New-ScheduledIncident\r\n{\r\n [CmdletBinding()]\r\n Param(\r\n [Parameter(Mandatory=$true)]\r\n [string]$PageId,\r\n\r\n [Parameter(Mandatory=$true)]\r\n [string]$ApiKey,\r\n\r\n [Parameter(Mandatory=$true)]\r\n [string]$Name,\r\n\r\n [Parameter(Mandatory=$true)]\r\n [ValidateSet(\"scheduled\", \"in_progress\", \"verifying\", \"completed\")]\r\n [string]$Status,\r\n \r\n [Parameter(Mandatory=$false)]\r\n [string]$Message,\r\n\r\n [Parameter(Mandatory=$false)]\r\n [string]$Componentid\r\n )\r\n\r\n $date = [System.DateTime]::Now.ToString(\"o\")\r\n $url = \"https://api.statuspage.io/v1/pages/$PageId/incidents.json\"\r\n $headers = @{\"Authorization\"=\"OAuth $ApiKey\"}\r\n $body = \"incident[name]=$Name&incident[status]=$Status&incident[scheduled_for]=$date&incident[scheduled_until]=$date\"\r\n\r\n if($Message)\r\n {\r\n $body += \"&incident[message]=$Message\"\r\n }\r\n\r\n if($Componentid)\r\n {\r\n $body += \"&incident[component_ids][]=$Componentid\"\r\n }\r\n\r\n $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method POST -Body $body\r\n $content = ConvertFrom-Json $response\r\n $content.id\r\n}\r\n\r\nValidate-Parameter $pageId -parameterName 'PageId'\r\nValidate-Parameter $apiKey = -parameterName 'ApiKey'\r\nValidate-Parameter $incidentName = -parameterName 'IncidentName'\r\nValidate-Parameter $incidentStatus -parameterName 'IncidentStatus'\r\n\r\nWrite-Output \"Creating new scheduled maintenance incident `\"$incidentName`\" ...\"\r\nNew-ScheduledIncident -PageId $pageId -ApiKey $apiKey -Name $incidentName -Status $incidentStatus -Message $incidentMessage -ComponentId $componentId\r\n",
"Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\r\n## Input\r\n## --------------------------------------------------------------------------------------\r\n$pageId = $OctopusParameters['PageId']\r\n$apiKey = $OctopusParameters['ApiKey']\r\n$incidentName = $OctopusParameters['IncidentName']\r\n$incidentStatus = $OctopusParameters['IncidentStatus']\r\n$incidentMessage = $OctopusParameters['IncidentMessage']\r\n$componentId = $OctopusParameters['ComponentId']\r\n\r\nfunction Validate-Parameter($parameterValue, $parameterName) {\r\n if(!$parameterName -contains \"Key\") {\r\n Write-Host \"${parameterName}: ${parameterValue}\"\r\n }\r\n\r\n if (! $parameterValue) {\r\n throw \"$parameterName cannot be empty, please specify a value\"\r\n }\r\n}\r\n\r\nfunction New-ScheduledIncident\r\n{\r\n [CmdletBinding()]\r\n Param(\r\n [Parameter(Mandatory=$true)]\r\n [string]$PageId,\r\n\r\n [Parameter(Mandatory=$true)]\r\n [string]$ApiKey,\r\n\r\n [Parameter(Mandatory=$true)]\r\n [string]$Name,\r\n\r\n [Parameter(Mandatory=$true)]\r\n [ValidateSet(\"scheduled\", \"in_progress\", \"verifying\", \"completed\")]\r\n [string]$Status,\r\n \r\n [Parameter(Mandatory=$false)]\r\n [string]$Message,\r\n\r\n [Parameter(Mandatory=$false)]\r\n [string]$Componentid\r\n )\r\n\r\n $date = [System.DateTime]::Now.ToString(\"o\")\r\n $dateTomorrow = [System.DateTime]::Now.AddDays(1).ToString(\"o\")\r\n $url = \"https://api.statuspage.io/v1/pages/$PageId/incidents.json\"\r\n $headers = @{\"Authorization\"=\"OAuth $ApiKey\"}\r\n $body = \"incident[name]=$Name&incident[status]=$Status&incident[scheduled_for]=$date&incident[scheduled_until]=$dateTomorrow\"\r\n\r\n if($Message)\r\n {\r\n $body += \"&incident[message]=$Message\"\r\n }\r\n\r\n if($Componentid)\r\n {\r\n $body += \"&incident[component_ids][]=$Componentid\"\r\n }\r\n\r\n $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method POST -Body $body\r\n $content = ConvertFrom-Json $response\r\n $content.id\r\n}\r\n\r\nValidate-Parameter $pageId -parameterName 'PageId'\r\nValidate-Parameter $apiKey = -parameterName 'ApiKey'\r\nValidate-Parameter $incidentName = -parameterName 'IncidentName'\r\nValidate-Parameter $incidentStatus -parameterName 'IncidentStatus'\r\n\r\nWrite-Output \"Creating new scheduled maintenance incident `\"$incidentName`\" ...\"\r\nNew-ScheduledIncident -PageId $pageId -ApiKey $apiKey -Name $incidentName -Status $incidentStatus -Message $incidentMessage -ComponentId $componentId\r\n",
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.FeedId": null,
"Octopus.Action.Package.PackageId": null
Expand Down Expand Up @@ -76,11 +76,11 @@
}
}
],
"LastModifiedBy": "nshenoy",
"LastModifiedBy": "Sam-Kudo",
"$Meta": {
"ExportedAt": "2016-10-26T18:49:13.955+00:00",
"OctopusVersion": "3.4.10",
"ExportedAt": "2025-02-17T14:35:00.000+00:00",
"OctopusVersion": "2025.1.8967",
"Type": "ActionTemplate"
},
"Category": "statusPage"
}
}

0 comments on commit 3a09940

Please sign in to comment.