Created
June 2, 2022 01:42
-
-
Save liamkinne/11f228939cc69946abe36df1bdb45371 to your computer and use it in GitHub Desktop.
Send alerts to Opsgenie using PowerShell
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
function New-OpsgenieAlert { | |
param ( | |
[parameter(Mandatory=$true)][string]$ApiKey, | |
[parameter(Mandatory=$true)][string]$Message, | |
[parameter(Mandatory=$false)][string]$Alias, | |
[parameter(Mandatory=$false)][string]$Description, | |
[parameter(Mandatory=$false)][PSCustomObject[]]$Responders, | |
[parameter(Mandatory=$false)][PSCustomObject[]]$VisibleTo, | |
[parameter(Mandatory=$false)][string[]]$Actions, | |
[parameter(Mandatory=$false)][string[]]$Tags, | |
[parameter(Mandatory=$false)][PSCustomObject[]]$Details, | |
[parameter(Mandatory=$false)][string]$Entity = "PowerShell", | |
[parameter(Mandatory=$false)][string]$Source, | |
[parameter(Mandatory=$false)][string]$Priority, | |
[parameter(Mandatory=$false)][string]$User, | |
[parameter(Mandatory=$false)][string]$Note | |
) | |
$params = @{ | |
"message"=$Message; | |
"alias"=$Alias; | |
"description"=$Description; | |
"responders"=$Responders; | |
"visibleTo"=$VisibleTo; | |
"actions"=$Actions; | |
"tags"=$Tags; | |
"details"=$Details; | |
"entity"=$Entity; | |
"source"=$Source; | |
"priority"=$Priority; | |
"user"=$User; | |
"note"=$Note; | |
} | |
Invoke-RestMethod -Uri "https://api.opsgenie.com/v2/alerts" ` | |
-ContentType "application/json" ` | |
-Method POST ` | |
-Body ($params|ConvertTo-Json) ` | |
-Headers @{"Authorization"="GenieKey $ApiKey"} | |
} | |
# Usage: | |
# New-OpsgenieAlert ` | |
# -ApiKey $OpsgenieKey ` | |
# -Message "Failed to do a thing." ` | |
# -Description "So I created this alert." ` | |
# -Priority "P3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment