Azure-Sentinel: ConvertSentinelRuleFrom-Yaml.ps1 converts to a JSON format that does not conform to ARM format

Describe the bug When using the ConvertSentinelRuleFrom-Yaml.ps1 script to convert a folder of YAML analytics rules to JSON, the CI/CD process fails due to an issue with the formatting (see error message below).

When exporting the same rules from Sentinel via GUI and coparing the formating of the exported JSON to the converted JSON the files are very different. I’m wondering if this is causing the problem? I can deploy the exported JSON back into Sentinel using VSCode + Azure DevOps + Repository in Sentinel absolutely fine.

To Reproduce Steps to reproduce the behavior:

  1. Use ConvertSentinelRuleFrom-Yaml.ps1 to convert a folder of YAMLs into JSONs
  2. Attempt to push to Azure Devops repository connected to Azure Sentinel workspace
  3. Instead receive error:

2022-11-14T16:18:21.9220516Z [Warning] Failed to deploy D:\a\1\s\Detections\NRT_AWS_ConsoleLogonWithoutMFA.json with error: 4:18:21 PM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template resource '<redacted-workspace-name>/Microsoft.SecurityInsights/' for type 'Microsoft.OperationalInsights/workspaces/providers/alertRules' at line '15' and column '81' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name. Please see https://aka.ms/arm-template/#resources for usage details.'.

  1. If you export a rule from Sentinel and compare it to the “converted” rule the formatting & fields are very different.

Expected behavior Expect to see analytics rules appear in Sentinel

Desktop (please complete the following information): Windows 10 22H2

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 36 (32 by maintainers)

Commits related to this issue

Most upvoted comments

The attached PR is merged. Thanks @azurekid for making this contribution.

I just tested running the HelpFunction provided above against my Yaml and all worked flawlessly - the code isn’t too dis-similar to what I came up with but does appaer more elegant.

Thanks for confirming this. Still working on extending the script to support other types of rules.

Thanks for extending your support on this issue @azurekid. Really appreciate your efforts, if possible can you please raise a PR and continue development?

Thanks @azurekid - I actually “fixed” this myself some time in December - I say “fixed” because I’m not proficient in Powershell so made the changes I needed to get the script working and has been for some time now. I raised this issue here to have the issue solved by a competent PS developer for the betterment of others.

I will review your script and see how I can improve mine, if that’s OK 😃