Unable to create analytic rule from sysmon parse xml - extend operator failed to resolve scalar
hello, i'm trying to create the below analytic rule, the results appear absolutely fine within the logs pane when qorking on the query, the minute i goto create the analytic rule, i get the following error message:

"'extend' operator: Failed to resolve scalar expression named '["@Name"]'."
Steps to reproduce the behavior:
Go to 'Analytics' Click on 'Create Scheduled Query ' Click "Set Rule logic" Paste the below query Try to enable this rule See error
Event
| where Source == "Microsoft-Windows-Sysmon"
| extend RenderedDescription = tostring(split(RenderedDescription, ":")[0])
| extend EventData = parse_xml(EventData).DataItem.EventData.Data
| mv-expand bagexpansion=array EventData
| evaluate bag_unpack(EventData)
| extend Key=tostring(['@Name']), Value=['#text']
| evaluate pivot(Key, any(Value), TimeGenerated, Source, EventLog, Computer, EventID, RenderedDescription, MG, ManagementGroupName, Type, _ResourceId)
Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.
Hi @CraigCloudITPro, I had this exact same problem, try the change found in this pull: https://github.com/Azure/Azure-Sentinel/pull/2191/files
Hi @CraigCloudITPro, I had this exact same problem, try the change found in this pull: https://github.com/Azure/Azure-Sentinel/pull/2191/files
Hello Lodewyk, this still doesn't seem to work, i am now getting the below:
"'where' operator: Failed to resolve column or scalar expression named 'OriginalFileName'."
Event
| where Source == "Microsoft-Windows-Sysmon"
| extend RenderedDescription = tostring(split(RenderedDescription, ":")[0])
| extend EventData = parse_xml(EventData).DataItem.EventData.Data
| mv-expand bagexpansion=array EventData
| evaluate bag_unpack(EventData)
| extend Key = tostring(column_ifexists('@Name', "")), Value = column_ifexists('#text', "")
| evaluate pivot(Key, any (Value), TimeGenerated, Source, EventLog, Computer, EventID, RenderedDescription, Type, _ResourceId)
| where OriginalFileName == "Cmd.Exe"
Try this to pass evaluation, there should be a better way, but this will let it work for now.
|where column_ifexists('OriginalFileName', "") == "Cmd.Exe"
@shainw Any other Ideas?
Try this to pass evaluation, there should be a better way, but this will let it work for now.
|where column_ifexists('OriginalFileName', "") == "Cmd.Exe"@shainw Any other Ideas?
Thanks that seems to work now Lodewyk.
I agree there has to be a more efficient way to reduce the syntax character count here, otherwise it's going to get extremely complicated for a simple query.
@CraigCloudITPro - This is the current work around. The challenge here is that the required event may not be there for which the unpack iterates over, which means the subsequent fields are not available and hence the error. We are investigating to see if there is any better solution, but you can think of it as similar to not having a table in your workspace and attempting to query against that table, this is just one level deeper and requiring a specific event type to be available. Agreed, it is not a great experience and we will see what we can do.
@CraigCloudITPro - This is the current work around. The challenge here is that the required event may not be there for which the unpack iterates over, which means the subsequent fields are not available and hence the error. We are investigating to see if there is any better solution, but you can think of it as similar to not having a table in your workspace and attempting to query against that table, this is just one level deeper and requiring a specific event type to be available. Agreed, it is not a great experience and we will see what we can do.
But using my original code in the “Logs” when searching populates the exact results I want to see, it’s only when I goto create the Analytic Rule that it throws the errors.
What’s the differences between running the query in the Logs pane of LAWS or Sentinel vs actually creating the Analytic Rule?
@Ronmarsiano - Can you check on what might be causing this? It seems the table lookup is likely a very short time frame and if there is no event then the error occurs. In other words, it only looks at the last 10 minutes and if the correct Sysmon event is not there it doesn't work. Just a thought, Ron should be able to track down the reason. ;)
Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.
As mentioned in our documentation when using bag_unpack in scheduled alert rules we require using "column_ifexists"
- https://docs.microsoft.com/en-us/azure/sentinel/tutorial-detect-threats-custom#define-the-rule-query-logic-and-configure-settings
This is how the rule should look like - Event | where Source == "Microsoft-Windows-Sysmon" | extend RenderedDescription = tostring(split(RenderedDescription, ":")[0]) | extend EventData = parse_xml(EventData).DataItem.EventData.Data | mv-expand bagexpansion=array EventData | evaluate bag_unpack(EventData) | extend NameColumn = tostring(column_ifexists("@Name","")) | extend Key=tostring(column_ifexists("@Name","")), Value=tostring(column_ifexists("#text","")) | evaluate pivot(Key, any(Value), TimeGenerated, Source, EventLog, Computer, EventID, RenderedDescription, MG, ManagementGroupName, Type, _ResourceId)
Solution provided
Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.