| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
DOCUMENTATION = ''' |
| 9 |
--- |
| 10 |
module: azure_rm_monitordatacollectionendpoint_info |
| 11 |
version_added: "3.9.0" |
| 12 |
short_description: Get or list Data Collection Endpoints |
| 13 |
description: |
| 14 |
- Get or list Data Collection Rules Endpoints. |
| 15 |
|
| 16 |
options: |
| 17 |
name: |
| 18 |
description: |
| 19 |
- The name of the data collection endpoint. |
| 20 |
- The name is case insensitive. |
| 21 |
type: str |
| 22 |
resource_group: |
| 23 |
description: |
| 24 |
- The name of the resource group in which the data collection endpoint is (if you use name) |
| 25 |
type: str |
| 26 |
tags: |
| 27 |
description: |
| 28 |
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. |
| 29 |
type: list |
| 30 |
elements: str |
| 31 |
|
| 32 |
extends_documentation_fragment: |
| 33 |
- azure.azcollection.azure |
| 34 |
|
| 35 |
author: |
| 36 |
- magodo (@magodo) |
| 37 |
- Fred Sun (@Fred-sun) |
| 38 |
''' |
| 39 |
|
| 40 |
EXAMPLES = ''' |
| 41 |
- name: Get data collection endpoint details |
| 42 |
azure.azcollection.azure_rm_monitordatacollectionendpoint_info: |
| 43 |
name: fredendpoint01 |
| 44 |
resource_group: Resource_Group_Name |
| 45 |
|
| 46 |
- name: List all data collection endpoints in specific resource group |
| 47 |
azure.azcollection.azure_rm_monitordatacollectionendpoint_info: |
| 48 |
resource_group: Resource_Group_Name |
| 49 |
|
| 50 |
- name: List all data collection endpoints in the current subscription |
| 51 |
azure.azcollection.azure_rm_monitordatacollectionendpoint_info: |
| 52 |
''' |
| 53 |
|
| 54 |
RETURN = ''' |
| 55 |
datacollectionendpoints: |
| 56 |
description: |
| 57 |
- List of data collection rule association. |
| 58 |
- Can be empty if listing data collection rule association. |
| 59 |
type: complex |
| 60 |
returned: always |
| 61 |
contains: |
| 62 |
configuration_access: |
| 63 |
description: |
| 64 |
- The endpoint used by clients to access their configuration. |
| 65 |
type: dict |
| 66 |
returned: always |
| 67 |
sample: {"endpoint": "https://fredendpoint-q7lu.eastus-1.handler.control.monitor.azure.com"} |
| 68 |
description: |
| 69 |
description: |
| 70 |
- Description of the data collection endpoint. |
| 71 |
type: str |
| 72 |
returned: always |
| 73 |
sample: Created |
| 74 |
etag: |
| 75 |
description: |
| 76 |
- Resource entity tag (ETag). |
| 77 |
type: str |
| 78 |
returned: always |
| 79 |
sample: "3d001f14-0000-0100-0000-68ca270a0000" |
| 80 |
id: |
| 81 |
description: |
| 82 |
- Fully qualified ID of the resource. |
| 83 |
type: str |
| 84 |
returned: always |
| 85 |
sample: "/subscriptions/xxx-xxx/resourceGroups/v-xisuRG/providers/Microsoft.Insights/dataCollectionEndpoints/fredendpoint" |
| 86 |
immutable_id: |
| 87 |
description: |
| 88 |
- The immutable ID of this data collection endpoint resource. |
| 89 |
- This property is READ-ONLY. |
| 90 |
type: str |
| 91 |
returned: always |
| 92 |
sample: dce-9897a7cde9b54676a1c07ab3ea222768 |
| 93 |
kind: |
| 94 |
description: |
| 95 |
- The kind of the resource. |
| 96 |
type: str |
| 97 |
returned: always |
| 98 |
sample: Linux |
| 99 |
logs_ingestion: |
| 100 |
description: |
| 101 |
- The endpoint used by clients to ingest logs. |
| 102 |
type: dict |
| 103 |
returned: always |
| 104 |
sample: {"endpoint": "https://fredendpoint-q7lu.eastus-1.ingest.monitor.azure.com"} |
| 105 |
metrics_ingestion: |
| 106 |
description: |
| 107 |
- The endpoint used by clients to ingest metrics. |
| 108 |
type: dict |
| 109 |
returned: always |
| 110 |
sample: {"endpoint": "https://fredendpoint-q7lu.eastus-1.metrics.ingest.monitor.azure.com"} |
| 111 |
name: |
| 112 |
description: |
| 113 |
- The name of the resource. |
| 114 |
type: str |
| 115 |
returned: always |
| 116 |
sample: testendpoint |
| 117 |
network_acls: |
| 118 |
description: |
| 119 |
- Network access control rules for the endpoints. |
| 120 |
type: dict |
| 121 |
returned: always |
| 122 |
sample: {"public_network_access": "Enabled"} |
| 123 |
provisioning_state: |
| 124 |
description: |
| 125 |
- The resource provisioning state. This property is READ-ONLY. |
| 126 |
type: str |
| 127 |
returned: always |
| 128 |
sample: Succeeded |
| 129 |
system_data: |
| 130 |
description: |
| 131 |
- Metadata pertaining to creation and last modification of the resource. |
| 132 |
type: dict |
| 133 |
returned: always |
| 134 |
sample: { |
| 135 |
"created_at": "2025-09-17T03:12:08.743499Z", |
| 136 |
"created_by": "00867800-0fa3-4d02-8bc8-35edac3a0d32", |
| 137 |
"created_by_type": "Application", |
| 138 |
"last_modified_at": "2025-09-17T03:12:08.743499Z", |
| 139 |
"last_modified_by": "00867800-0fa3-4d02-8bc8-35edac3a0d32", |
| 140 |
"last_modified_by_type": "Application" |
| 141 |
} |
| 142 |
tags: |
| 143 |
description: |
| 144 |
- Resource tags. |
| 145 |
returned: always |
| 146 |
type: dict |
| 147 |
sample: {'key1': 'value1'} |
| 148 |
type: |
| 149 |
description: |
| 150 |
- The type of the resource. |
| 151 |
returned: always |
| 152 |
type: str |
| 153 |
sample: "Microsoft.Insights/dataCollectionEndpoints" |
| 154 |
''' |
| 155 |
|
| 156 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 157 |
|
| 158 |
|
| 159 |
class AzureRMDataCollectionRuleEndpointInfo(AzureRMModuleBase): |
| 160 |
"""Information class for an Azure RM Data Collection Rules""" |
| 161 |
|
| 162 |
def __init__(self): |
| 163 |
self.module_arg_spec = dict( |
| 164 |
name=dict(type='str'), |
| 165 |
resource_group=dict(type='str'), |
| 166 |
tags=dict(type='list', elements='str') |
| 167 |
) |
| 168 |
|
| 169 |
self.required_by = { |
| 170 |
'name': 'resource_group' |
| 171 |
} |
| 172 |
|
| 173 |
self.resource_group = None |
| 174 |
self.name = None |
| 175 |
self.tags = None |
| 176 |
self.log_path = None |
| 177 |
self.log_mode = None |
| 178 |
|
| 179 |
self.results = dict( |
| 180 |
changed=False, |
| 181 |
datacollectionendpoints=[] |
| 182 |
) |
| 183 |
|
| 184 |
super(AzureRMDataCollectionRuleEndpointInfo, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 185 |
supports_check_mode=True, |
| 186 |
supports_tags=False, |
| 187 |
facts_module=True, |
| 188 |
required_by=self.required_by) |
| 189 |
|
| 190 |
def exec_module(self, **kwargs): |
| 191 |
"""Main module execution method""" |
| 192 |
|
| 193 |
for key in self.module_arg_spec: |
| 194 |
setattr(self, key, kwargs[key]) |
| 195 |
|
| 196 |
if self.name: |
| 197 |
result = self.get_endpoint() |
| 198 |
else: |
| 199 |
result = self.list_endpoints() |
| 200 |
|
| 201 |
self.results['datacollectionendpoints'] = result |
| 202 |
|
| 203 |
return self.results |
| 204 |
|
| 205 |
def get_endpoint(self): |
| 206 |
''' |
| 207 |
Gets the specified data collection rule endpoint |
| 208 |
''' |
| 209 |
result = [] |
| 210 |
response = None |
| 211 |
|
| 212 |
try: |
| 213 |
response = self.monitor_management_client_data_collection_rules.data_collection_endpoints.get(resource_group_name=self.resource_group, |
| 214 |
data_collection_endpoint_name=self.name) |
| 215 |
except Exception as ex: |
| 216 |
self.log("Could not find data collection endpoint {0} in resource group {1}, Exception as {2}".format(self.name, self.resource_group, ex)) |
| 217 |
return [] |
| 218 |
if response and self.has_tags(response.tags, self.tags): |
| 219 |
result = [response.as_dict()] |
| 220 |
return result |
| 221 |
|
| 222 |
def list_endpoints(self): |
| 223 |
''' |
| 224 |
Lists Data Collection Endpoint for the specified resource. |
| 225 |
''' |
| 226 |
result = [] |
| 227 |
response = None |
| 228 |
|
| 229 |
if self.resource_group: |
| 230 |
try: |
| 231 |
response = self.monitor_management_client_data_collection_rules.data_collection_endpoints.list_by_resource_group( |
| 232 |
resource_group_name=self.resource_group) |
| 233 |
except Exception as ex: |
| 234 |
self.log("Could not list data collection endponts in resource group {0}, Exception as {1}".format(self.resource_uri, ex)) |
| 235 |
return [] |
| 236 |
else: |
| 237 |
try: |
| 238 |
response = self.monitor_management_client_data_collection_rules.data_collection_endpoints.list_by_subscription() |
| 239 |
except Exception as ex: |
| 240 |
self.log("Could not list data collection endpoint in the subscription_id, Exception as {0}".format(ex)) |
| 241 |
return [] |
| 242 |
if response: |
| 243 |
for item in response: |
| 244 |
if self.has_tags(item.tags, self.tags): |
| 245 |
result.append(item.as_dict()) |
| 246 |
|
| 247 |
return result |
| 248 |
|
| 249 |
|
| 250 |
def main(): |
| 251 |
"""Main execution""" |
| 252 |
AzureRMDataCollectionRuleEndpointInfo() |
| 253 |
|
| 254 |
|
| 255 |
if __name__ == '__main__': |
| 256 |
main() |