0
votes

I am trying to deploy application insights alerts (non-classic) that use a search query as the signal logic criteria. I am using a resource manager template for this so that I can automate deployment.

When there is no data in the associated application insights resource then the alert deployment fails with the error:

properties.search.query is not a valid log or metric query properties.search.query is not a valid log search query

Once the application insights contains some data then the alert deployment succeeds without error.

This is a problem as I need to be able to deploy the alerts before my application is running and logging data.

1
I have the same problem. Did you find a workaround for this?Mats Mortensen
@MatsMortensen see answer belowGlen Thomas

1 Answers

0
votes

You can switch the application insights resource to an active state by inserting some data. You can use Powershell to do this via HTTP POST:

$body = (New-Object PSObject | 
Add-Member -PassThru NoteProperty name 'Microsoft.ApplicationInsights.Event' |  
Add-Member -PassThru NoteProperty time $([System.dateTime]::UtcNow.ToString('o')) |  
Add-Member -PassThru NoteProperty iKey '<INSERT-INSTRUMENTATION-KEY>' |  
Add-Member -PassThru NoteProperty data (New-Object PSObject |  
Add-Member -PassThru NoteProperty baseType 'EventData' | 
Add-Member -PassThru NoteProperty baseData (New-Object PSObject | 
Add-Member -PassThru NoteProperty ver 2 | 
Add-Member -PassThru NoteProperty name 'Hello!'))) | 
ConvertTo-JSON -depth 5; 
Invoke-WebRequest -Uri 'https://dc.services.visualstudio.com/v2/track' -Method 'POST' -UseBasicParsing -body $body

A short delay (~1 minute) may be required after this has happened.