StatusPage.io - Update Scheduled Maintenance Incident

Octopus.Script exported 2016-10-26 by nshenoy belongs to ‘StatusPage’ category.

Updates an existing scheduled maintenance incident on StatusPage.io

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Scheduled Maintenance Name

IncidentName

The name of the scheduled maintenance incident.

Status

IncidentStatus

The status of the incident, one of scheduled|in_progress|verifying|completed

Message

IncidentMessage

Optional message to add to scheduled maintenance incident.

StatusPage.io Page Id

PageId

StatusPage.io Organization or “Page ID”. Visit the API authentication docs for details.

StatusPage.io API Key

ApiKey

StatusPage.io API key for the organization. Visit the API Authentication docs for details.

Script body

Steps based on this template will execute the following PowerShell script.

## --------------------------------------------------------------------------------------
## Input
## --------------------------------------------------------------------------------------
$pageId = $OctopusParameters['PageId']
$apiKey = $OctopusParameters['ApiKey']
$incidentName = $OctopusParameters['IncidentName']
$incidentStatus = $OctopusParameters['IncidentStatus']
$incidentMessage = $OctopusParameters['IncidentMessage']

function Validate-Parameter($parameterValue, $parameterName) {
    if(!$parameterName -contains "Key") {
        Write-Host "${parameterName}: ${parameterValue}"
    }

    if (! $parameterValue) {
        throw "$parameterName cannot be empty, please specify a value"
    }
}

function Get-InProgressScheduledIncidentByName
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [string]$PageId,

        [Parameter(Mandatory=$true)]
        [string]$ApiKey,

        [Parameter(Mandatory=$true)]
        [string]$Name
    )

    $url = "https://api.statuspage.io/v1/pages/$PageId/incidents/unresolved.json"
    $headers = @{"Authorization"="OAuth $ApiKey"}

    $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method GET
    $content = ConvertFrom-Json $response
    $incident = $content | where {$_.name -eq $Name}
    $incident.id
}

function Update-ScheduledIncident
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [string]$PageId,

        [Parameter(Mandatory=$true)]
        [string]$ApiKey,

        [Parameter(Mandatory=$true)]
        [string]$IncidentId,

        [Parameter(Mandatory=$true)]
        [ValidateSet("scheduled", "in_progress", "verifying", "completed")]
        [string]$Status,
        
        [Parameter(Mandatory=$false)]
        [string]$Message
    )

    $url = "https://api.statuspage.io/v1/pages/$PageId/incidents/$IncidentId.json"
    $headers = @{"Authorization"="OAuth $ApiKey"}
    $body = "incident[status]=$Status"

    if($Message)
    {
        $body += "&incident[message]=$Message"
    }

    $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method PATCH -Body $body -ContentType application/x-www-form-urlencoded
}

Validate-Parameter $pageId -parameterName 'PageId'
Validate-Parameter $apiKey = -parameterName 'ApiKey'
Validate-Parameter $incidentName = -parameterName 'IncidentName'
Validate-Parameter $incidentStatus -parameterName 'IncidentStatus'

$incidentId = Get-InProgressScheduledIncidentByName -PageId $pageId -ApiKey $apiKey -Name $incidentName
Write-Verbose "Found incident id: $incidentId"
Write-Output "Updating scheduled maintenance incident `"$incidentName`" [IncidentId: $incidentId]"
Update-ScheduledIncident -PageId $pageId -ApiKey $apiKey -IncidentId $incidentId -Status $incidentStatus -Message $incidentMessage 

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "7bc83a07-8927-467e-a2eb-922609212e3a",
  "Name": "StatusPage.io - Update Scheduled Maintenance Incident",
  "Description": "Updates an existing scheduled maintenance incident on StatusPage.io",
  "Version": 0,
  "ExportedAt": "2016-10-26T18:51:37.967+00:00",
  "ActionType": "Octopus.Script",
  "Author": "nshenoy",
  "Parameters": [
    {
      "Id": "b1044b12-8cdc-4b55-b429-a08711a66339",
      "Name": "IncidentName",
      "Label": "Scheduled Maintenance Name",
      "HelpText": "The name of the scheduled maintenance incident.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "6d9277b0-3cab-43ea-9946-d772c9d3aebf",
      "Name": "IncidentStatus",
      "Label": "Status",
      "HelpText": "The status of the incident, one of scheduled|in_progress|verifying|completed",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "scheduled|Scheduled\nin_progress|In Progress\nverifying|Verifying\ncompleted|Completed"
      }
    },
    {
      "Id": "a2121f55-09ea-4200-ae4f-0131f7db06b1",
      "Name": "IncidentMessage",
      "Label": "Message",
      "HelpText": "Optional message to add to scheduled maintenance incident.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "d0504e1f-150d-46b2-8127-449a708e55c6",
      "Name": "PageId",
      "Label": "StatusPage.io Page Id",
      "HelpText": "StatusPage.io Organization or \"Page ID\". Visit the [API authentication docs](http://doers.statuspage.io/api/authentication/) for details.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "48c90b4b-d9ca-419a-8c8f-98d301db2015",
      "Name": "ApiKey",
      "Label": "StatusPage.io API Key",
      "HelpText": "StatusPage.io API key for the organization. Visit the [API Authentication docs](http://doers.statuspage.io/api/authentication/) for details.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false",
    "Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\n## Input\n## --------------------------------------------------------------------------------------\n$pageId = $OctopusParameters['PageId']\n$apiKey = $OctopusParameters['ApiKey']\n$incidentName = $OctopusParameters['IncidentName']\n$incidentStatus = $OctopusParameters['IncidentStatus']\n$incidentMessage = $OctopusParameters['IncidentMessage']\n\nfunction Validate-Parameter($parameterValue, $parameterName) {\n    if(!$parameterName -contains \"Key\") {\n        Write-Host \"${parameterName}: ${parameterValue}\"\n    }\n\n    if (! $parameterValue) {\n        throw \"$parameterName cannot be empty, please specify a value\"\n    }\n}\n\nfunction Get-InProgressScheduledIncidentByName\n{\n    [CmdletBinding()]\n    Param(\n        [Parameter(Mandatory=$true)]\n        [string]$PageId,\n\n        [Parameter(Mandatory=$true)]\n        [string]$ApiKey,\n\n        [Parameter(Mandatory=$true)]\n        [string]$Name\n    )\n\n    $url = \"https://api.statuspage.io/v1/pages/$PageId/incidents/unresolved.json\"\n    $headers = @{\"Authorization\"=\"OAuth $ApiKey\"}\n\n    $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method GET\n    $content = ConvertFrom-Json $response\n    $incident = $content | where {$_.name -eq $Name}\n    $incident.id\n}\n\nfunction Update-ScheduledIncident\n{\n    [CmdletBinding()]\n    Param(\n        [Parameter(Mandatory=$true)]\n        [string]$PageId,\n\n        [Parameter(Mandatory=$true)]\n        [string]$ApiKey,\n\n        [Parameter(Mandatory=$true)]\n        [string]$IncidentId,\n\n        [Parameter(Mandatory=$true)]\n        [ValidateSet(\"scheduled\", \"in_progress\", \"verifying\", \"completed\")]\n        [string]$Status,\n        \n        [Parameter(Mandatory=$false)]\n        [string]$Message\n    )\n\n    $url = \"https://api.statuspage.io/v1/pages/$PageId/incidents/$IncidentId.json\"\n    $headers = @{\"Authorization\"=\"OAuth $ApiKey\"}\n    $body = \"incident[status]=$Status\"\n\n    if($Message)\n    {\n        $body += \"&incident[message]=$Message\"\n    }\n\n    $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method PATCH -Body $body -ContentType application/x-www-form-urlencoded\n}\n\nValidate-Parameter $pageId -parameterName 'PageId'\nValidate-Parameter $apiKey = -parameterName 'ApiKey'\nValidate-Parameter $incidentName = -parameterName 'IncidentName'\nValidate-Parameter $incidentStatus -parameterName 'IncidentStatus'\n\n$incidentId = Get-InProgressScheduledIncidentByName -PageId $pageId -ApiKey $apiKey -Name $incidentName\nWrite-Verbose \"Found incident id: $incidentId\"\nWrite-Output \"Updating scheduled maintenance incident `\"$incidentName`\" [IncidentId: $incidentId]\"\nUpdate-ScheduledIncident -PageId $pageId -ApiKey $apiKey -IncidentId $incidentId -Status $incidentStatus -Message $incidentMessage \n",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Package.PackageId": null
  },
  "Category": "StatusPage",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/statuspageio-update-scheduled-maintenance-incident.json",
  "Website": "/step-templates/7bc83a07-8927-467e-a2eb-922609212e3a",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////gb1B9/vzicFNsNaJ3+7P0Oa3wN6goc5xkcVZ7/fn5/PbyOKs1+rDqdJ9mclluNqUjbDtNQAABKhJREFUeNrsXdt23DAItCxZF1u29/+/tsnZpE2bjXUFZMq85SlnFoHQgGGaBAKBQCAQCAQCgUAgEAjuiGV3znuv1Qf02x/O7cuNKMy780H9iODdPo9PwpoLDl/YGDswmS2eqgBn3EZkscagihHiOhgN61UlvB3IGE6rBmg3hllWo5phVhY0BqDSiwYxlbnNN777CtHVsgfVGWGnMMehAHCgG2XXCgR6Z2AOfKNsQQEioKVgUQEj4hwro8BhEI7XfCoEnOBMNq1QoDcePKCZWDQeb0wAHypWocIy4aEeTHiY2/u58Mi6B7nwOHnwmAwTHnX5rvbG2eUD0RmvqXlsFVnfY3+hiqz74yTkMZe+ow57Ie2s9iDiMZW9a0NMpuDzleANx2Mv0qQzS1KLR+dRcoP4gsraaypwPAoO1llYIFxOTB7ZB0tXSAZRo/HIjlh1ctTfAhkgj8nBmeObUSB5rHme3qKp/Vb7IHlk5li+SbyZPTyPFSc1MtA88gxievwfWB4rWqoKXKM2lCk3skHuwCPnDvF34DGl75CQjrvb84FI2QuUFuQSQvMWjy8Jjn9QtWml+2Su8pLtEV49HecRXf24sKYfp4MmqZzoueChQdjgEGoPVrJ2jVtLT0pA50/myEiYzTzQyVpaHjAnnqecdVdhrraqsboC5jqD5GvEWExslUFKtG4kJqbGII8yjXseIPiGZknyIu5hukisFyoQyrYFP+5clZvlhnC8p8hRlSxnnlDMzNc2SJI4zQ2Zvr5WS5L/Ri5oIuXhprI7ENgkS3G0qe3vCKRB60UaXt12ulEGrbU8NSO6S1yph9Z3DgXC6OvbssV0BMQiYrrFLPC4dU3EdXQRYCfRhb/h0kDE092HS0dfB/b2UiKugYgSIv8TEfcC+2cL2YsSQWciCxlzITIakc7hl45I5wsxkr0qO6coji4V6Js0GjoifdN4T0ek78NKFybfQzjJCxdJlGFBiXQVH8qljwHOViivTgALxh0FupMuyewqma60wnc/EdsSNyR1KysclEGrY6EnFcnh2yY6ld5SnQoIJdQ+xdBA6+s5F0BWeTr1IsBpouzQMOAr4hwpkx94JJ9oWH1FrU01vsqv6G74n9qckgaJaETaGs+SXylijq1raAWMVakAoFEqmzPTH9jFCRl17bLp1xnBMLGKBub0p81ErfiFLeUZMwwoRyFmN/lnPGj0dAdkvALcHXjkpAQrEx7Aie+GxQPYILbP53vkBrGq0weVxAZ5SiddPnElNcinBNTlo+PEHbIi8Oj0GTjZHfKXJNfjw/yr/H1G4tFnVAKJLPddIu0wvKKk9RtS6m0fJ1IigYFK1s0DXpAP1oX03jpyB/VgJUoIbUOQECNWRimkZSwVmgSUW9J5HxQWawaFISknyPMaDRMeYANzkXloLjw24TESDzBBjgsPNoOL+YyS5jPcm8+4dT4D8PmsJJjYLImY+Kzt4LNIZWKz2mbis2zoXdHhsf5p4rOQa2KzIq0nFSb798wgGxF5LHZ8PlRYrNp8moXH8tNnCsZiHe3H1cJiQfAnGQ4rm78kMPdfoi0QCAQCgUAgEAgEAoFA8Ae/BBgAaZFFuhLr9ZYAAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Wednesday, October 26, 2016