Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Alert Condition API with PowerShell


#1

I’m trying to automate the creation of alert conditions for our alert policy using PowerShell and am having trouble converting the syntax from the CURL example found on the API documentation site to PowerShell. My PowerShell is below. Does anyone happen to see what I’m doing wrong? It seems to be an issue in the terms array based on the error I’m getting back but I’m unsure as to what’s wrong. Thanks.

$body = @{
    condition = @{
        type = "apm_app_metric"
        name = "TEST Condition"
        enabled = $true
        entities = @(##MY_ENTITY_ID##)
        metric = "apdex"
        condition_scope = "application"
        terms = @(
            @{
                duration = "15"
                operator = "below"
                priority = "critical"
                threshold = "0.5"
                time_function = "all"
            }
        )
    }
}

$response = Invoke-WebRequest "https://api.newrelic.com/v2/alerts_conditions/policies/$($policyId).json" `
    -Method Post `
    -ContentType "application/json" `
    -Headers @{"X-Api-Key" = $adminApiKey} `
    -Body (ConvertTo-Json $body)

#2

Hey @BigNStrauss -

My knowledge of PowerShell is near non-existent if I’m honest. But, I did a quick search through the Explorers Hub and found this post by @jbiggley on creating their alerts through PowerShell:

The Terms definition in that script is as below;

 "terms": [
              {
                "duration": "30",
                "operator": "above",
                "priority": "critical",
                "threshold": "95",
                "time_function": "all"
              },
              {
                "duration": "30",
                "operator": "above",
                "priority": "warning",
                "threshold": "90",
                "time_function": "all"
              }
            ],

Hopefully this helps - or another Community member may be able to help more than I can :smiley:


#3

In addition to the terms, you may want to check the entities as that is marked up the same in your sample @BigNStrauss


#4

@RyanVeitch @stefan_garnham Thanks for the info guys, I checkout that guy’s monster of a script and changed mine to pass in the body data similar to how he did, and it’s working now. Appreciate the assistance.


#5

Excellent! I’m glad you got this figured out :smiley: Thanks for letting us know