Closed anyasabo closed 7 years ago
For the record I'm getting the same error
Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'. At line:47 char:3
- CategoryInfo : OperationStopped: (:) [], InvalidCastException
- FullyQualifiedErrorId : Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.
But I see a response in the debug output
Body: [{"id":"subscriptions/bce7ec4f-86ce-4a55-9253-7de908a98ed0/resourceGroups/uks-rsg-all-prd/providers/Microsoft.OperationalInsights/workspaces/819631-OMS/savedSearches/raxunexpectedshutdown/schedules/raxunexpectedshutdown","etag":"W/\"datetime'2016-10-19T00%3A42%3A27.3128 973Z'\"","properties":{"Interval":5,"QueryTimeSpan":5,"Enabled":true,"NearRealTime":false}}]
What is interesting, is I was playing around to see about getting schedules/ with no savedsearch id, if there are multiple schedules (which I don't think is possible just testing) my get uri
notice there is NOTHING following /schedules except the API, and yet in the body that is returned, you see the id of the saved search.
@ravbhatnagar can you take a look?
I have get the same error but when I use Invoke-Restmethod I just get the correct output returned.
` $SubscriptionURI = "https://management.azure.com/subscriptions/$SubscriptionID/resourceGroups/stsomsrg/providers/Microsoft.OperationalInsights/workspaces/$omsworkspace/savedSearches/7ebe4b31-3604-40c0-932f-053392005464/schedules" +'?api-version=2015-11-01-preview'
$params = @{ ContentType = 'application/x-www-form-urlencoded' Headers = @{ 'authorization'="Bearer $($Token.access_token)" } Method = 'Get' URI = $SubscriptionURI }
Invoke-RestMethod @params -OutVariable OMSSchedules
$OMSSchedules | fl *
id
--
subscriptions/[mysubscriptionid]/resourceGroups/[myresourcegroup]/providers/Microsoft.OperationalInsights/workspaces/[myworkspace]/savedSearches/7ebe4b31-36...
id : subscriptions/[mysubscriptionid]/resourceGroups/[myresourcegroup]/providers/Microsoft.OperationalInsights/workspaces/[myworkspace]/savedSearches/7 ebe4b31-3604-40c0-932f-053392005464/schedules/b9cb3487-f7db-420a-b845-403b4a962888 etag : W/"datetime'2016-09-23T12%3A00%3A12.094347Z'" properties : @{Interval=60; QueryTimeSpan=120; Enabled=True; NearRealTime=False} ` So it seems to be something related to using the 'Newtonsoft.Json.Linq.JArray' class in the Get-AzureRMResource cmdlet.
/Stefan
We can confirm that this is a bug in the Operational Insights resource provider.
We’ll be making a fix in the resource provider to remove this bug. After we make the fix the document returned in response to making a call to /schedules will change to comply with Azure Resource Manager requirements.
Example call
armclient get https://management.azure.com/subscriptions/******/resourceGroups/mms-eus/providers/Microsoft.OperationalInsights/workspaces/*****/savedSearches/*****/schedules?api-version=2014-11-10
Current behavior:
[
{
"id": "subscriptions/********/resourceGroups/mms-eus/providers/Microsoft.OperationalInsights/workspaces/*****/savedSearches/*****/schedules/********",
"etag": "W/\"datetime'2016-10-19T02%3A49%3A47.8123398Z'\"",
"properties": {
"Interval": 5,
"QueryTimeSpan": 5,
"Enabled": true,
"NearRealTime": false
}
}
]
Behavior with bug fixed (array is returned in a property called “value”):
{
“value”: [
{
"id": "subscriptions/********/resourceGroups/mms-eus/providers/Microsoft.OperationalInsights/workspaces/*****/savedSearches/*****/schedules/********",
"etag": "W/\"datetime'2016-10-19T02%3A49%3A47.8123398Z'\"",
"properties": {
"Interval": 5,
"QueryTimeSpan": 5,
"Enabled": true,
"NearRealTime": false
}
}
]
}
Once this bug is fixed you will be able to use Get-AzureRMResource to retrieve the schedules for an alert.
We deployed the fix last night and verified that Get-AzureRmResource now returns the correct results.
Since this was a change in the resource provider, and not to the PowerShell, it is not necessary to update the Azure PowerShell modules to get this fix.
I'm closing this issue since we've released a fix.
Cmdlet(s)
Get-AzureRmResource
PowerShell Version
5.1.14393.223
Module Version
3.1.0
OS Version
10.0.14393.223
Description
When trying to use
Get-AzureRmResource
, it appears that if the service returns a 200 response with an empty array, the cmdlet doesn't know how to handle it and errors out. I received this error:Get-AzureRmResource : Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'Newtonsoft.Json.Linq.JObject'.
when accessing this resourceid:/subscriptions/$subscriptionId/resourceGroups/$workspaceRG/providers/Microsoft.OperationalInsights/workspaces/$WorkspaceName/savedSearches/$id/schedules
as there are no schedules for that saved search, but trying to access similar resources that return arrays works, e.g.:
/subscriptions/$subscriptionId/resourceGroups/$workspaceRG/providers/Microsoft.OperationalInsights/workspaces/$WorkspaceName/savedSearches
Debug Output
Script/Steps for Reproduction
Create a saved search in OMS but without a schedule, and run this with the appropriate vars assigned
trying do a
get-AzureRmResource -ResourceId "/subscriptions/$subscriptionId/resourceGroups/$workspaceRG/providers/Microsoft.OperationalInsights/workspaces/$WorkspaceName/savedSearches/$savedsearch
should work though.