Azure / azure-cli

Azure Command-Line Interface
MIT License
3.97k stars 2.95k forks source link

associate resources to data collection endpoint #26628

Closed ipetko96 closed 10 months ago

ipetko96 commented 1 year ago

Related command

Is your feature request related to a problem? Please describe. I am not sure, but how can I associate existing resources to existing data collection endpoint. In portal there is + button to select resources that will be associated, but I need to achieve this through API.

Describe the solution you'd like New command something like az monitor data-collection endpoint association create would be useful.

Describe alternatives you've considered I also tried to go from the other side and create association in the data collection rule with az monitor data-collection rule association create but there is the same problem, no way of select and associate existing data collection endpoint.

Additional context

yonzhan commented 1 year ago

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

jtosuk commented 1 year ago

Another customer with the same problem, we are starting to make use of DCR and have thousands of resources (machines) to associate to the DCR's via the Data Collection Endpoint.

lckstrb commented 1 year ago

I am also in the same situation but using PowerShell commands. How can I assciate vms to data collection endpoint (not data collection rule)? The command which I could find, New-AzDataCollectionRuleAssociation can only be used to associate resources to data collection rule not to data collection endpoint...

ipetko96 commented 1 year ago

@lckstrb for now, you have few options on how to associate VMs to data collection endpoint. If you want to do it programmatically, look at these two options: templates or REST API
Third option is to manually click it in the Azure portal, which is good only for small number of VMs or for development\testing purposes.

AllyW commented 10 months ago

@ipetko96 @lckstrb Parameter endpoint-id has been added into az monitor data-collection rule association create which allows endpoint-id associated to a resource and released in azure extension already. Run az extension add --name monitor-control-service --upgrade and you'll get the new functionality.

unixsubhasish17 commented 7 months ago

Hello @AllyW ,

Thanks but it seems there is another issue while passing endpoint-id while creating association for a DCR,

➜ ~ az monitor data-collection rule association create --name "performance" --rule-id "/subscriptions/xxxxxxx/resourceGroups/RG/providers/Microsoft.Insights/dataCollectionRules/performance" --resource "/subscriptions/xxxxxxxx/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/abcdefg" --endpoint-id "/subscriptions/xxxxxxxxx/resourceGroups/Shared-RG/providers/Microsoft.Insights/dataCollectionEndpoints/dce" Error: Association name for resource to endpoint must be configurationAccessEndpoint

Any idea what is going wrong here?

ipetko96 commented 7 months ago

I can confirm, I was also able to reproduce this issue. After calling this command: az monitor data-collection rule association create --name myAssociation --rule-id XXX --resource XXX --endpoint-id XXX I get this exception:

(InvalidEndpointAssociationName) An association of data collection endpoint must be named 'configurationAccessEndpoint'.
Code: InvalidEndpointAssociationName
Message: An association of data collection endpoint must be named 'configurationAccessEndpoint'.
Exception Details:      (InvalidEndpointAssociationName) An association of data collection endpoint must be named 'configurationAccessEndpoint'.
        Code: InvalidEndpointAssociationName
        Message: An association of data collection endpoint must be named 'configurationAccessEndpoint'.
        Target: name

The reason why I did not report it earlier after implementing new parameter, was that we circumvent missing feature with bicep template, and even after parameter was added to az cli I didn't want to rework whole functioning deployment. And yes, in bicep there is exactly this name configurationAccessEndpoint

bicep template look like this:

resource association 'Microsoft.Insights/dataCollectionRuleAssociations@2022-06-01' = {
  dependsOn: [
    vm
  ]
  name: 'configurationAccessEndpoint'
  scope: vm
  properties: {
    dataCollectionEndpointId: dce_id
  }
}
unixsubhasish17 commented 7 months ago

Hello @ipetko96 ,

Yes, and thanks for your response. I was able to figure out last night about this.

This is really confusing and no where we found any document about it.

Ideally, we should not use data collection rule-id and endpoint id together. For example,

when we associate resource with DCR, we should not use endpoint id in the same command, so just to make it clear:

Below command to associate VM to DCR:

az monitor data-collection rule association create --name "DCR_NAME" --rule-id "DCR_Rule_ID" --resource "VM_Resource_ID" ==> In this command if we pass --endpoint-id it will always return error.

Below command to associate endpoint-id with VM:

az monitor data-collection rule association create --name "configurationAccessEndpoint" --resource "VM_resource_ID" --endpoint-id "Endpoint_ID"

I am totally surprise that this thing is not explicitly mentioned in the MS documents or may be its mentioned but I had a hard time to find it.

Anyway, thanks for your reply and I will get back to my work.

Have a nice evening !!

Thanks Subhasish