StatusPage.io - Create Scheduled Maintenance Incident

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

Creates or updates a 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.

ComponentId

ComponentId

Optional component id to reference for the scheduled maintenance incident. Talk to your StatusPage.io administrator for details.

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']
$componentId = $OctopusParameters['ComponentId']

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 New-ScheduledIncident
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [string]$PageId,

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

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

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

        [Parameter(Mandatory=$false)]
        [string]$Componentid
    )

    $date = [System.DateTime]::Now.ToString("o")
    $url = "https://api.statuspage.io/v1/pages/$PageId/incidents.json"
    $headers = @{"Authorization"="OAuth $ApiKey"}
    $body = "incident[name]=$Name&incident[status]=$Status&incident[scheduled_for]=$date&incident[scheduled_until]=$date"

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

    if($Componentid)
    {
        $body += "&incident[component_ids][]=$Componentid"
    }

    $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method POST -Body $body
    $content = ConvertFrom-Json $response
    $content.id
}

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

Write-Output "Creating new scheduled maintenance incident `"$incidentName`" ..."
New-ScheduledIncident -PageId $pageId -ApiKey $apiKey -Name $incidentName -Status $incidentStatus -Message $incidentMessage -ComponentId $componentId

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": "5f8dbdd9-e309-4aa7-b1d3-b090876a959a",
  "Name": "StatusPage.io - Create Scheduled Maintenance Incident",
  "Description": "Creates or updates a scheduled maintenance incident on StatusPage.io",
  "Version": 5,
  "ExportedAt": "2016-10-26T18:49:13.955+00:00",
  "ActionType": "Octopus.Script",
  "Author": "nshenoy",
  "Parameters": [
    {
      "Id": "587dd594-5141-4c84-b204-0803935e2a5e",
      "Name": "IncidentName",
      "Label": "Scheduled Maintenance Name",
      "HelpText": "The name of the scheduled maintenance incident.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "a6de9c6a-4777-413e-a679-75af62846a95",
      "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": "49c1d937-7632-46f3-afc5-376d893deff9",
      "Name": "IncidentMessage",
      "Label": "Message",
      "HelpText": "Optional message to add to scheduled maintenance incident.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "b9a01157-aa89-4ae1-95ee-5b05b53b042a",
      "Name": "ComponentId",
      "Label": "ComponentId",
      "HelpText": "Optional component id to reference for the scheduled maintenance incident. Talk to your StatusPage.io administrator for details.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "29694b56-739a-4623-9040-0b2865fb15a4",
      "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": "c7d00d1c-e963-4be5-b088-83a945ed4540",
      "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$componentId = $OctopusParameters['ComponentId']\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 New-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]$Name,\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        [Parameter(Mandatory=$false)]\n        [string]$Componentid\n    )\n\n    $date = [System.DateTime]::Now.ToString(\"o\")\n    $url = \"https://api.statuspage.io/v1/pages/$PageId/incidents.json\"\n    $headers = @{\"Authorization\"=\"OAuth $ApiKey\"}\n    $body = \"incident[name]=$Name&incident[status]=$Status&incident[scheduled_for]=$date&incident[scheduled_until]=$date\"\n\n    if($Message)\n    {\n        $body += \"&incident[message]=$Message\"\n    }\n\n    if($Componentid)\n    {\n        $body += \"&incident[component_ids][]=$Componentid\"\n    }\n\n    $response = iwr -UseBasicParsing -Uri $url -Headers $headers -Method POST -Body $body\n    $content = ConvertFrom-Json $response\n    $content.id\n}\n\nValidate-Parameter $pageId -parameterName 'PageId'\nValidate-Parameter $apiKey = -parameterName 'ApiKey'\nValidate-Parameter $incidentName = -parameterName 'IncidentName'\nValidate-Parameter $incidentStatus -parameterName 'IncidentStatus'\n\nWrite-Output \"Creating new scheduled maintenance incident `\"$incidentName`\" ...\"\nNew-ScheduledIncident -PageId $pageId -ApiKey $apiKey -Name $incidentName -Status $incidentStatus -Message $incidentMessage -ComponentId $componentId\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-create-scheduled-maintenance-incident.json",
  "Website": "/step-templates/5f8dbdd9-e309-4aa7-b1d3-b090876a959a",
  "Logo": "iVBORw0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c7hl45I5wsxkr0qO6coji4V6Js0GjoifdN4T0ek78NKFybfQzjJCxdJlGFBiXQVH8qljwHOViivTgALxh0FupMuyewqma60wnc/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