Created
May 26, 2014 20:27
-
-
Save henkmeulekamp/3441f937caf991d6500b to your computer and use it in GitHub Desktop.
Powershell script to set Pagerduty in maintenance mode for x minutes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[int]$minutes = 3, | |
[string]$requesterId = "<your-pager-duty-user-id>", | |
[string]$apiKey = "<your-pager-duty-api-token>", | |
[string]$description = "Deploy new version of app", | |
[string]$serviceIDs = "'<serviceId1>', '<serviceId2>', '<serviceId..>'" | |
) | |
function Execute-HTTPPostCommand() { | |
param( | |
[string] $target = $null | |
) | |
$webRequest = [System.Net.WebRequest]::Create($target) | |
$webRequest.ContentType = "application/json" | |
$PostStr = [System.Text.Encoding]::UTF8.GetBytes($Post) | |
$webrequest.ContentLength = $PostStr.Length | |
$webRequest.ServicePoint.Expect100Continue = $false | |
$webRequest.Headers.Add("Authorization", "Token token=$apiKey"); | |
$webRequest.Method = "POST" | |
$requestStream = $webRequest.GetRequestStream() | |
$requestStream.Write($PostStr, 0,$PostStr.length) | |
$requestStream.Close() | |
[System.Net.WebResponse] $resp = $webRequest.GetResponse(); | |
$rs = $resp.GetResponseStream(); | |
[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs; | |
[string] $results = $sr.ReadToEnd(); | |
return $results; | |
} | |
$currentdt = ((Get-Date)).ToString("yyyy-MM-ddTHH:mm:sszzzzZ"); | |
$currentEnddt = ((Get-Date).AddMinutes($minutes)).ToString("yyyy-MM-ddTHH:mm:sszzzzZ"); | |
$post = "{ | |
'maintenance_window': { | |
'start_time': '$currentdt', | |
'end_time': '$currentEnddt', | |
'description': '$description', | |
'service_ids': [ | |
$serviceIDs | |
] | |
}, | |
'requester_id': '$requesterId' | |
}" | |
Write-Host $post | |
$URL = "https://parkmobile.pagerduty.com/api/v1/maintenance_windows" | |
Execute-HTTPPostCommand $URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment