Azure / azure-cli

Azure Command-Line Interface
MIT License
4.04k stars 3.01k forks source link

"Unexpected error" from `az monitor diagnostic-settings create` #26416

Open bn-jswick opened 1 year ago

bn-jswick commented 1 year ago

This is autogenerated. Please review and update as needed.

Describe the bug

Receiving a Python error for unused resource_group key when trying to create a diagnostic setting to export subscription level events to an event hub in another subscription.

Command Name az monitor diagnostic-settings create

Errors:

$ az monitor diagnostic-settings create  \
 --name "Audit" \
 --resource /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
 --logs '[{"category": "Administrative","enabled": true}, {"category": "Security","enabled": true}, {"category": "Policy","enabled": true}]' \
 --event-hub-rule "/subscriptions/yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy/resourcegroups/Security-Events/providers/Microsoft.EventHub/namespaces/Azure-Security-Event-Hub/eventhubs/azuresecurityevents/authorizationrules/GlobalSubscritpionAccess"
The command failed with an unexpected error. Here is the traceback:
'resource_group'
Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/aaz/_command.py", line 149, in __call__
    return self._handler(*args, **kwargs)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/command_modules/monitor/aaz/latest/monitor/diagnostic_settings/_create.py", line 33, in _handler
    self._execute_operations()
  File "/opt/az/lib/python3.10/site-packages/azure/cli/command_modules/monitor/aaz/latest/monitor/diagnostic_settings/_create.py", line 176, in _execute_operations
    self.pre_operations()
  File "/opt/az/lib/python3.10/site-packages/azure/cli/command_modules/monitor/operations/diagnostics_settings.py", line 100, in pre_operations
    rg = parse_resource_id(args.resource.to_serialized_data())['resource_group']
KeyError: 'resource_group'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

Expected Behavior

Should be able to use the diagnostic-settings create command from the CLI tool to create a diagnostic export rule. When I don't have permissions to the event hub rule, I should instead get an error that I don't have permissions to list the keys of the event hub rule.

Environment Summary

Linux-5.15.0-71-generic-x86_64-with-glibc2.35, Ubuntu 22.04.2 LTS
Python 3.10.10
Installer: DEB

azure-cli 2.48.1

Extensions:
account 0.2.1
azure-devops 0.18.0
datamigration 0.4.1
kusto 0.4.0

Dependencies:
msal 1.20.0
azure-mgmt-resource 22.0.0

Additional Context

azure-client-tools-bot-prd[bot] commented 1 year ago
Hi @bn-jswick Find similar issue https://github.com/Azure/azure-cli/issues/24957.
Issue title running Scenario0_Hello_World ./create_resources.sh comes across "KeyError: 'resource_group'"
Create time 2022-12-21
Comment number 6

Please confirm if this resolves your issue. Kindly react a 👍 or 👎 to this comment so that we can improve this robot.

yonzhan commented 1 year ago

Thank you for opening this issue, we will look into it.