Pingdom - Create Uptime Check

Octopus.Script exported 06/11/2018 by sarbis belongs to 'Pingdom' category.

Creates Pingdom http check using Create New Check API method.

Parameters

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

Username

Pingdom.Username

Mandatory.

Password

Pingdom.Password

Mandatory.

App key

Pingdom.AppKey

Mandatory.

Name

Pingdom.CheckName

Mandatory.

Target

Pingdom.CheckTarget

Mandatory.

Interval

Pingdom.CheckIntervalMinutes

Check interval in minutes. Integer (1, 5, 15, 30, 60)

Contact Ids

Pingdom.CheckContactIds

Pingdom contact identifiers. For example contactids=154325,465231,765871.

Pingdom.CheckIntegrationIds

Pingdom.CheckIntegrationIds

Send notification when down

Pingdom.CheckSendNotificationWhenDown

Send notification when down n times.

Notify every

Pingdom.CheckNotifyAgainEvery

Notify again every n result. 0 means that no extra notifications will be sent.

Send to email

Pingdom.CheckSendToEmail = True

Notify when back up

Pingdom.CheckNotifyWhenBackUp = True

Notify when back up again.

Tags

Pingdom.CheckTags

Pingdom check tags. Example: octopus,azure.

Http encryption enabled

Pingdom.CheckHttpEncryptionEnabled

Http target port

Pingdom.CheckHttpTargetPort

Auth

Pingdom.CheckAuth

Username and password for target HTTP authentication. Example: user:password.

Should contain

Pingdom.CheckShouldContain

Target site should contain this string.

Should not contain

Pingdom.CheckShouldNotContain

Target site should NOT contain this string. If shouldcontain is also set, this parameter is not allowed.

Post data

Pingdom.CheckPostData

Data that should be posted to the web page, for example submission data for a sign-up or login form. The data needs to be formatted in the same way as a web browser would send it to the web server

Error when failed

Pingdom.ThrowErrorWhenFailed

When checked, throws Octopus exception if template script has failed.

Script body

Steps based on this template will execute the following PowerShell script.
Show script
# Ref https://www.pingdom.com/resources/api#MethodCreate+New+Check

Function Get-Parameter() {
    Param(
        [parameter(Mandatory=$true)]
        [string]$Name, 
        [switch]$Required, 
        $Default, 
        [switch]$FailOnValidate
    )

    $result = $null
    $errMessage = [string]::Empty

    If ($OctopusParameters -ne $null) {
        $result = $OctopusParameters[$Name]
        Write-Host ("Octopus parameter value for " + $Name + ": " + $result)
    }

    If ($result -eq $null) {
        $variable = Get-Variable $Name -EA SilentlyContinue
        if ($variable -ne $null) {
            $result = $variable.Value
        }
    }

    If ($result -eq $null -or [string]::IsNullOrEmpty($result)) {
        If ($Required) {
            $errMessage = "Missing value for $Name"
        } ElseIf (-Not $Default -eq $null) {
            Write-Host ("Default value: " + $Default)
            $result = $Default
        }
    }

    If (-Not [string]::IsNullOrEmpty($errMessage)) {
        If ($FailOnValidate) {
            Throw $errMessage
        } Else {
            Write-Warning $errMessage
        }
    }

    return $result
}

Function Test-Any() { 
   begin { 
      $any = $false
   } 
   process { 
      $any = $true
   } 
   end { 
      $any
   } 
} 

& {
    Write-Host "Start PingdomCreateUptimeCheck"

    Add-Type -AssemblyName System.Web

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    $throwErrorWhenFailed = [System.Convert]::ToBoolean([string](Get-Parameter -Name "Pingdom.ThrowErrorWhenFailed" -Default "False"))

    $pingdomUsername = [string] (Get-Parameter -Name "Pingdom.Username" -Required -FailOnValidate:$throwErrorWhenFailed)
    $pingdomPassword = [string] (Get-Parameter -Name "Pingdom.Password" -Required -FailOnValidate:$throwErrorWhenFailed)
    $pingdomAppKey = [string] (Get-Parameter -Name "Pingdom.AppKey" -Required -FailOnValidate:$throwErrorWhenFailed)

    $pingdomCheckName = [string] (Get-Parameter -Name "Pingdom.CheckName" -Required -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckTarget = [string] (Get-Parameter -Name "Pingdom.CheckTarget" -Required -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckType = "http"
    $pingdomCheckIntervalMinutes = [System.Nullable[int]] (Get-Parameter -Name "Pingdom.CheckIntervalMinutes" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckContactIds = [string] (Get-Parameter -Name "Pingdom.CheckContactIds" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckSendNotificationWhenDown = [System.Nullable[int]] (Get-Parameter -Name "Pingdom.CheckSendNotificationWhenDown" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckNotifyAgainEvery = [System.Nullable[int]] (Get-Parameter -Name "Pingdom.CheckNotifyAgainEvery" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckNotifyWhenBackUp = [string](Get-Parameter -Name "Pingdom.CheckNotifyWhenBackUp" -Default "True" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckTags = [string] (Get-Parameter -Name "Pingdom.CheckTags" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckHttpUrl = [string] (Get-Parameter -Name "Pingdom.CheckHttpUrl" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckHttpEncryptionEnabled = [string](Get-Parameter -Name "Pingdom.CheckHttpEncryptionEnabled" -Default "False" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckHttpTargetPort = [System.Nullable[int]] (Get-Parameter -Name "Pingdom.CheckHttpTargetPort" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckAuth = [string] (Get-Parameter -Name "Pingdom.CheckAuth" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckShouldContain = [string] (Get-Parameter -Name "Pingdom.CheckShouldContain" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckShouldNotContain = [string] (Get-Parameter -Name "Pingdom.CheckShouldNotContain" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckPostData = [string] (Get-Parameter -Name "Pingdom.CheckPostData" -FailOnValidate:$throwErrorWhenFailed)
    $pingdomCheckIntegrationIds = [string] (Get-Parameter -Name "Pingdom.CheckIntegrationIds" -FailOnValidate:$throwErrorWhenFailed)

    $apiVersion = "2.1"
    $url = "https://api.pingdom.com/api/{0}/checks" -f $apiVersion
    $securePassword = ConvertTo-SecureString $pingdomPassword -AsPlainText -Force
    $credential = New-Object System.Management.Automation.PSCredential($pingdomUsername, $securePassword)
    $headers = @{ 
        "App-Key" = $pingdomAppKey
    }

    # Validate if check already registered

    Write-Host "Getting uptime check list to find check by name: $url"
    Try {
        $response = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" -Credential $credential -Headers $headers
    } Catch {
        $errMessage = "Error occured when getting uptime check in Pingdom: " + $_.Exception.Message
        If($throwErrorWhenFailed -eq $true) {
            Write-Error $errMessage
        }
        Else {
            Write-Warning $errMessage
        }
    }

    $checkExists = $response.checks | Where-Object { $_.name -eq $pingdomCheckName } | Test-Any
    If ($checkExists -eq $true) {
        Write-Host "Check with name $pingdomCheckName already registered. New check will not be created!"
        Exit
    }

    # Create new check

    $apiParameters = @{}
    $apiParameters.Add("name", $pingdomCheckName)
    $apiParameters.Add("host", $pingdomCheckTarget)
    $apiParameters.Add("type", $pingdomCheckType)
    $apiParameters.Add("contactids", $pingdomCheckContactIds)
    $apiParameters.Add("integrationids", $pingdomCheckIntegrationIds)
    If ($pingdomCheckIntervalMinutes -ne $null) {
        $apiParameters.Add("resolution", $pingdomCheckIntervalMinutes)
    }
    If ($pingdomCheckSendNotificationWhenDown -ne $null) {
        $apiParameters.Add("sendnotificationwhendown", $pingdomCheckSendNotificationWhenDown)
    }
    If ($pingdomCheckNotifyAgainEvery -ne $null) {
        $apiParameters.Add("notifyagainevery", $pingdomCheckNotifyAgainEvery)
    }
    If ($pingdomCheckNotifyWhenBackUp -ne $null) {
        $apiParameters.Add("notifywhenbackup", $pingdomCheckNotifyWhenBackUp.ToLower())
    }
    If ($pingdomCheckTags -ne $null) {
        $apiParameters.Add("tags", $pingdomCheckTags)
    }
    If (-Not [string]::IsNullOrEmpty($pingdomCheckHttpUrl)) {
        $apiParameters.Add("url", $pingdomCheckHttpUrl)
    }
    If ($pingdomCheckHttpEncryptionEnabled -ne $null) {
        $apiParameters.Add("encryption", $pingdomCheckHttpEncryptionEnabled.ToLower())
    }
    If ($pingdomCheckHttpTargetPort -ne $null) {
        $apiParameters.Add("port", $pingdomCheckHttpTargetPort)
    }
    If (-Not [string]::IsNullOrEmpty($pingdomCheckAuth)) {
        $apiParameters.Add("auth", $pingdomCheckAuth)
    }
    If (-Not [string]::IsNullOrEmpty($pingdomCheckShouldContain)) {
        $apiParameters.Add("shouldcontain", $pingdomCheckShouldContain)
    }
    If (-Not [string]::IsNullOrEmpty($pingdomCheckShouldNotContain)) {
        $apiParameters.Add("shouldnotcontain", $pingdomCheckShouldNotContain)
    }
    If (-Not [string]::IsNullOrEmpty($pingdomCheckPostData )) {
        $apiParameters.Add("postdata", $pingdomCheckPostData)
    }

    If ($apiParameters.Count -gt 0) {
        $queryString = ""
        $apiParameters.Keys | ForEach-Object { 
            $queryString += ($_ + "=" + [System.Web.HttpUtility]::UrlEncode($apiParameters.Item($_)) + "&")
        }
        $requestBody = $queryString.Substring(0, $queryString.Length - 1)
        $url += "?$requestBody"
    }

    Write-Host "Creating new uptime check: $url"
    Write-Host "Request body: $requestBody"
    Try {
        $response = Invoke-RestMethod -Uri $url -Method Post -Body $requestBody -ContentType "application/json" -Credential $credential -Headers $headers
        Write-Host ("Successfully added uptime check in Pingdom: Name = " + $response.check.name + ", Id = " + $response.check.id)
    } Catch {
        $errMessage = "Error occured when adding uptime check in Pingdom: " + $_.Exception + "`n"
        $errMessage += "Response: " + $_
        If($throwErrorWhenFailed -eq $true) {
            Write-Error $errMessage
        }
        Else {
            Write-Warning $errMessage
        }
    }

    Write-Host "End PingdomCreateUptimeCheck"
}

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

Show JSON
{
  "Id": "70ea4820-7d02-4015-a691-8c77b5ab14d5",
  "Name": "Pingdom - Create Uptime Check",
  "Description": "Creates Pingdom http check using [Create New Check API method](https://www.pingdom.com/resources/api#MethodCreate+New+Check).",
  "Version": 43,
  "ExportedAt": "2018-06-11T13:49:31.508Z",
  "ActionType": "Octopus.Script",
  "Author": "sarbis",
  "Parameters": [
    {
      "Id": "16cdd666-9822-428c-9c1e-fb8943039a98",
      "Name": "Pingdom.Username",
      "Label": "Username",
      "HelpText": "Mandatory.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "d5b36e0f-3c55-4b63-9971-4c9147218514",
      "Name": "Pingdom.Password",
      "Label": "Password",
      "HelpText": "Mandatory.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      },
      "Links": {}
    },
    {
      "Id": "2f33c3ed-202a-4711-8897-a47329c18b8d",
      "Name": "Pingdom.AppKey",
      "Label": "App key",
      "HelpText": "Mandatory.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "754d2183-3b3b-4170-898b-f759af555f69",
      "Name": "Pingdom.CheckName",
      "Label": "Name",
      "HelpText": "Mandatory.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "c04286a9-d4e4-4c33-985e-67f52b3a9549",
      "Name": "Pingdom.CheckTarget",
      "Label": "Target",
      "HelpText": "Mandatory.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "96e4c38b-4d43-4083-ace3-510f945a4202",
      "Name": "Pingdom.CheckIntervalMinutes",
      "Label": "Interval",
      "HelpText": "Check interval in minutes. Integer (1, 5, 15, 30, 60)",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "7fc1f49f-446c-4836-8966-b1786d45f6b1",
      "Name": "Pingdom.CheckContactIds",
      "Label": "Contact Ids",
      "HelpText": "Pingdom contact identifiers. For example contactids=154325,465231,765871.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "f76811df-7a79-4fee-a491-46c6ce4bc813",
      "Name": "Pingdom.CheckIntegrationIds",
      "Label": "",
      "HelpText": null,
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "963c6ff8-b79e-408d-9729-036b58c42857",
      "Name": "Pingdom.CheckSendNotificationWhenDown",
      "Label": "Send notification when down",
      "HelpText": "Send notification when down n times.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "6ba72782-3eee-465c-9176-659de024f8dd",
      "Name": "Pingdom.CheckNotifyAgainEvery",
      "Label": "Notify every",
      "HelpText": "Notify again every n result. 0 means that no extra notifications will be sent.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "9ad13abe-13ab-466c-bd0e-a51637bece3b",
      "Name": "Pingdom.CheckSendToEmail",
      "Label": "Send to email",
      "HelpText": null,
      "DefaultValue": "True",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      },
      "Links": {}
    },
    {
      "Id": "8a958bb9-5a61-4956-b79d-7f990271b127",
      "Name": "Pingdom.CheckNotifyWhenBackUp",
      "Label": "Notify when back up",
      "HelpText": "Notify when back up again.",
      "DefaultValue": "True",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      },
      "Links": {}
    },
    {
      "Id": "93e9f063-b0b9-495b-8774-fd140b96a640",
      "Name": "Pingdom.CheckTags",
      "Label": "Tags",
      "HelpText": "Pingdom check tags. Example: octopus,azure.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "9d579e60-2228-4521-9178-2da35817d0b8",
      "Name": "Pingdom.CheckHttpEncryptionEnabled",
      "Label": "Http encryption enabled",
      "HelpText": null,
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      },
      "Links": {}
    },
    {
      "Id": "e289c1f6-cfbc-4774-ac97-395ac353b3b3",
      "Name": "Pingdom.CheckHttpTargetPort",
      "Label": "Http target port",
      "HelpText": null,
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "dcda6fd8-9e42-40c4-9213-f77e9e67b974",
      "Name": "Pingdom.CheckAuth",
      "Label": "Auth",
      "HelpText": "Username and password for target HTTP authentication. Example: user:password.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "bab9c934-dfb4-42c3-817f-22b58a8ef3d5",
      "Name": "Pingdom.CheckShouldContain",
      "Label": "Should contain",
      "HelpText": "Target site should contain this string.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "96e83352-1dce-4d16-bce7-0f8d4929ced7",
      "Name": "Pingdom.CheckShouldNotContain",
      "Label": "Should not contain",
      "HelpText": "Target site should NOT contain this string. If shouldcontain is also set, this parameter is not allowed.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "60570a61-678f-4ef2-90e5-c70d7b53ecb4",
      "Name": "Pingdom.CheckPostData",
      "Label": "Post data",
      "HelpText": "Data that should be posted to the web page, for example submission data for a sign-up or login form. The data needs to be formatted in the same way as a web browser would send it to the web server",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      },
      "Links": {}
    },
    {
      "Id": "fdb84b63-f86b-4aff-b9e9-e9166d512f51",
      "Name": "Pingdom.ThrowErrorWhenFailed",
      "Label": "Error when failed",
      "HelpText": "When checked, throws Octopus exception if template script has failed.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      },
      "Links": {}
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false",
    "Octopus.Action.Package.DownloadOnTentacle": "False",
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Package.PackageId": null,
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "# Ref https://www.pingdom.com/resources/api#MethodCreate+New+Check\n\nFunction Get-Parameter() {\n    Param(\n        [parameter(Mandatory=$true)]\n        [string]$Name, \n        [switch]$Required, \n        $Default, \n        [switch]$FailOnValidate\n    )\n\n    $result = $null\n    $errMessage = [string]::Empty\n\n    If ($OctopusParameters -ne $null) {\n        $result = $OctopusParameters[$Name]\n        Write-Host (\"Octopus parameter value for \" + $Name + \": \" + $result)\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 [string]::IsNullOrEmpty($result)) {\n        If ($Required) {\n            $errMessage = \"Missing value for $Name\"\n        } ElseIf (-Not $Default -eq $null) {\n            Write-Host (\"Default value: \" + $Default)\n            $result = $Default\n        }\n    }\n\n    If (-Not [string]::IsNullOrEmpty($errMessage)) {\n        If ($FailOnValidate) {\n            Throw $errMessage\n        } Else {\n            Write-Warning $errMessage\n        }\n    }\n\n    return $result\n}\n\nFunction Test-Any() { \n   begin { \n      $any = $false\n   } \n   process { \n      $any = $true\n   } \n   end { \n      $any\n   } \n} \n\n& {\n    Write-Host \"Start PingdomCreateUptimeCheck\"\n\n    Add-Type -AssemblyName System.Web\n\n    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n    $throwErrorWhenFailed = [System.Convert]::ToBoolean([string](Get-Parameter -Name \"Pingdom.ThrowErrorWhenFailed\" -Default \"False\"))\n\n    $pingdomUsername = [string] (Get-Parameter -Name \"Pingdom.Username\" -Required -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomPassword = [string] (Get-Parameter -Name \"Pingdom.Password\" -Required -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomAppKey = [string] (Get-Parameter -Name \"Pingdom.AppKey\" -Required -FailOnValidate:$throwErrorWhenFailed)\n\n    $pingdomCheckName = [string] (Get-Parameter -Name \"Pingdom.CheckName\" -Required -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckTarget = [string] (Get-Parameter -Name \"Pingdom.CheckTarget\" -Required -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckType = \"http\"\n    $pingdomCheckIntervalMinutes = [System.Nullable[int]] (Get-Parameter -Name \"Pingdom.CheckIntervalMinutes\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckContactIds = [string] (Get-Parameter -Name \"Pingdom.CheckContactIds\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckSendNotificationWhenDown = [System.Nullable[int]] (Get-Parameter -Name \"Pingdom.CheckSendNotificationWhenDown\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckNotifyAgainEvery = [System.Nullable[int]] (Get-Parameter -Name \"Pingdom.CheckNotifyAgainEvery\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckNotifyWhenBackUp = [string](Get-Parameter -Name \"Pingdom.CheckNotifyWhenBackUp\" -Default \"True\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckTags = [string] (Get-Parameter -Name \"Pingdom.CheckTags\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckHttpUrl = [string] (Get-Parameter -Name \"Pingdom.CheckHttpUrl\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckHttpEncryptionEnabled = [string](Get-Parameter -Name \"Pingdom.CheckHttpEncryptionEnabled\" -Default \"False\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckHttpTargetPort = [System.Nullable[int]] (Get-Parameter -Name \"Pingdom.CheckHttpTargetPort\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckAuth = [string] (Get-Parameter -Name \"Pingdom.CheckAuth\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckShouldContain = [string] (Get-Parameter -Name \"Pingdom.CheckShouldContain\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckShouldNotContain = [string] (Get-Parameter -Name \"Pingdom.CheckShouldNotContain\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckPostData = [string] (Get-Parameter -Name \"Pingdom.CheckPostData\" -FailOnValidate:$throwErrorWhenFailed)\n    $pingdomCheckIntegrationIds = [string] (Get-Parameter -Name \"Pingdom.CheckIntegrationIds\" -FailOnValidate:$throwErrorWhenFailed)\n\n    $apiVersion = \"2.1\"\n    $url = \"https://api.pingdom.com/api/{0}/checks\" -f $apiVersion\n    $securePassword = ConvertTo-SecureString $pingdomPassword -AsPlainText -Force\n    $credential = New-Object System.Management.Automation.PSCredential($pingdomUsername, $securePassword)\n    $headers = @{ \n        \"App-Key\" = $pingdomAppKey\n    }\n\n    # Validate if check already registered\n\n    Write-Host \"Getting uptime check list to find check by name: $url\"\n    Try {\n        $response = Invoke-RestMethod -Uri $url -Method Get -ContentType \"application/json\" -Credential $credential -Headers $headers\n    } Catch {\n        $errMessage = \"Error occured when getting uptime check in Pingdom: \" + $_.Exception.Message\n        If($throwErrorWhenFailed -eq $true) {\n            Write-Error $errMessage\n        }\n        Else {\n            Write-Warning $errMessage\n        }\n    }\n\n    $checkExists = $response.checks | Where-Object { $_.name -eq $pingdomCheckName } | Test-Any\n    If ($checkExists -eq $true) {\n        Write-Host \"Check with name $pingdomCheckName already registered. New check will not be created!\"\n        Exit\n    }\n\n    # Create new check\n\n    $apiParameters = @{}\n    $apiParameters.Add(\"name\", $pingdomCheckName)\n    $apiParameters.Add(\"host\", $pingdomCheckTarget)\n    $apiParameters.Add(\"type\", $pingdomCheckType)\n    $apiParameters.Add(\"contactids\", $pingdomCheckContactIds)\n    $apiParameters.Add(\"integrationids\", $pingdomCheckIntegrationIds)\n    If ($pingdomCheckIntervalMinutes -ne $null) {\n        $apiParameters.Add(\"resolution\", $pingdomCheckIntervalMinutes)\n    }\n    If ($pingdomCheckSendNotificationWhenDown -ne $null) {\n        $apiParameters.Add(\"sendnotificationwhendown\", $pingdomCheckSendNotificationWhenDown)\n    }\n    If ($pingdomCheckNotifyAgainEvery -ne $null) {\n        $apiParameters.Add(\"notifyagainevery\", $pingdomCheckNotifyAgainEvery)\n    }\n    If ($pingdomCheckNotifyWhenBackUp -ne $null) {\n        $apiParameters.Add(\"notifywhenbackup\", $pingdomCheckNotifyWhenBackUp.ToLower())\n    }\n    If ($pingdomCheckTags -ne $null) {\n        $apiParameters.Add(\"tags\", $pingdomCheckTags)\n    }\n    If (-Not [string]::IsNullOrEmpty($pingdomCheckHttpUrl)) {\n        $apiParameters.Add(\"url\", $pingdomCheckHttpUrl)\n    }\n    If ($pingdomCheckHttpEncryptionEnabled -ne $null) {\n        $apiParameters.Add(\"encryption\", $pingdomCheckHttpEncryptionEnabled.ToLower())\n    }\n    If ($pingdomCheckHttpTargetPort -ne $null) {\n        $apiParameters.Add(\"port\", $pingdomCheckHttpTargetPort)\n    }\n    If (-Not [string]::IsNullOrEmpty($pingdomCheckAuth)) {\n        $apiParameters.Add(\"auth\", $pingdomCheckAuth)\n    }\n    If (-Not [string]::IsNullOrEmpty($pingdomCheckShouldContain)) {\n        $apiParameters.Add(\"shouldcontain\", $pingdomCheckShouldContain)\n    }\n    If (-Not [string]::IsNullOrEmpty($pingdomCheckShouldNotContain)) {\n        $apiParameters.Add(\"shouldnotcontain\", $pingdomCheckShouldNotContain)\n    }\n    If (-Not [string]::IsNullOrEmpty($pingdomCheckPostData )) {\n        $apiParameters.Add(\"postdata\", $pingdomCheckPostData)\n    }\n\n    If ($apiParameters.Count -gt 0) {\n        $queryString = \"\"\n        $apiParameters.Keys | ForEach-Object { \n            $queryString += ($_ + \"=\" + [System.Web.HttpUtility]::UrlEncode($apiParameters.Item($_)) + \"&\")\n        }\n        $requestBody = $queryString.Substring(0, $queryString.Length - 1)\n        $url += \"?$requestBody\"\n    }\n\n    Write-Host \"Creating new uptime check: $url\"\n    Write-Host \"Request body: $requestBody\"\n    Try {\n        $response = Invoke-RestMethod -Uri $url -Method Post -Body $requestBody -ContentType \"application/json\" -Credential $credential -Headers $headers\n        Write-Host (\"Successfully added uptime check in Pingdom: Name = \" + $response.check.name + \", Id = \" + $response.check.id)\n    } Catch {\n        $errMessage = \"Error occured when adding uptime check in Pingdom: \" + $_.Exception + \"`n\"\n        $errMessage += \"Response: \" + $_\n        If($throwErrorWhenFailed -eq $true) {\n            Write-Error $errMessage\n        }\n        Else {\n            Write-Warning $errMessage\n        }\n    }\n\n    Write-Host \"End PingdomCreateUptimeCheck\"\n}"
  },
  "Category": "Pingdom",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates/pingdom-create-uptime-check.json",
  "Website": "/step-templates/70ea4820-7d02-4015-a691-8c77b5ab14d5",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRFGxsa/////veBsKMC5N2GxbYB//AA8uMAUEwOzb4A/vq+4tMB+/nk//Q/hn4JzsNEZBIFNAAABylJREFUeNrsnYuWmyAQhkkQGOT2/m9bMMlGDepABEkPs910zzamfv5zQUAgt//ESAfpIB2kg3SQDtJBOkgH6SAdpIN0kA7SQTpIB+kgHeRHQbTWox5PMf9BWlcH0ePdGF7EjLnfdRWQAMFLWwZMIshYHuIlzb0gyL0axgNFlwEZeXW7FwDRhl9gZjwbZOQX2f1ckDvnjZOQ1jm8e50HcikHkoS0z4EjIT/AgSIh7earuY3fg2jOf4LkEMS0AWK+BRl5I3b/EoQ3Y9+BfCeIUEpJbyy8+J9FQUlIsQhRAYAx+fcVXuQXLPoLkFxBhJAPJZiklFr/RQPJxKNUEUlICUHUJABjFsjcwIZfellUgcRFzq8hD4wVxAImE2XMBsnxLBEwqCXbZmmIF3Gyb5FzW1kiyLEhxkyWEDHq3AxMTg0RLwejR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