| 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 |
| 11 |
version_added: "3.9.0" |
| 12 |
short_description: Managed Data Collection Endpoints |
| 13 |
description: |
| 14 |
- Create, update or delete the 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 |
required: true |
| 23 |
resource_group: |
| 24 |
description: |
| 25 |
- The name of the resource group in which the data collection endpoint is (if you use name) |
| 26 |
type: str |
| 27 |
required: true |
| 28 |
location: |
| 29 |
description: |
| 30 |
- The geo-location where the resource lives. |
| 31 |
- Default is resource group's location. |
| 32 |
type: str |
| 33 |
kind: |
| 34 |
description: |
| 35 |
- The kind of the resource. |
| 36 |
type: str |
| 37 |
choices: |
| 38 |
- Linux |
| 39 |
- Windows |
| 40 |
description: |
| 41 |
description: |
| 42 |
- Description of the data collection endpoint. |
| 43 |
type: str |
| 44 |
network_acls: |
| 45 |
description: |
| 46 |
- Network access control rules for the endpoints. |
| 47 |
type: dict |
| 48 |
suboptions: |
| 49 |
public_network_access: |
| 50 |
description: |
| 51 |
- The configuration to set whether network access from public internet to the endpoints are allowed. |
| 52 |
type: str |
| 53 |
choices: |
| 54 |
- Enabled |
| 55 |
- Disabled |
| 56 |
- SecuredByPerimeter |
| 57 |
state: |
| 58 |
description: |
| 59 |
- State of the data colleciton endpoint. |
| 60 |
- Set to C(present) to create a new endpoint. |
| 61 |
- Set to C(absent) to remove a endpoint. |
| 62 |
default: present |
| 63 |
type: str |
| 64 |
choices: |
| 65 |
- absent |
| 66 |
- present |
| 67 |
|
| 68 |
extends_documentation_fragment: |
| 69 |
- azure.azcollection.azure |
| 70 |
- azure.azcollection.azure_tags |
| 71 |
|
| 72 |
author: |
| 73 |
- magodo (@magodo) |
| 74 |
- Fred Sun (@Fred-sun) |
| 75 |
''' |
| 76 |
|
| 77 |
EXAMPLES = ''' |
| 78 |
- name: Create a new data collection endpoint |
| 79 |
azure.azcollection.azure_rm_monitordatacollectionendpoint: |
| 80 |
resource_group: v-xisuRG |
| 81 |
name: fredendpoint1 |
| 82 |
description: fredtestend |
| 83 |
kind: Linux |
| 84 |
network_acls: |
| 85 |
public_network_access: Enabled |
| 86 |
tags: |
| 87 |
key1: value1 |
| 88 |
|
| 89 |
- name: Delete the data collection endpoint |
| 90 |
azure.azcollection.azure_rm_monitordatacollectionendpoint: |
| 91 |
resource_group: v-xisuRG |
| 92 |
name: fredendpoint1 |
| 93 |
state: absent |
| 94 |
''' |
| 95 |
|
| 96 |
RETURN = ''' |
| 97 |
datacollectionendpoint: |
| 98 |
description: |
| 99 |
- The facts of data collection rule association. |
| 100 |
type: complex |
| 101 |
returned: always |
| 102 |
contains: |
| 103 |
configuration_access: |
| 104 |
description: |
| 105 |
- The endpoint used by clients to access their configuration. |
| 106 |
type: dict |
| 107 |
returned: always |
| 108 |
sample: {"endpoint": "https://fredendpoint-q7lu.eastus-1.handler.control.monitor.azure.com"} |
| 109 |
description: |
| 110 |
description: |
| 111 |
- Description of the data collection endpoint. |
| 112 |
type: str |
| 113 |
returned: always |
| 114 |
sample: Created |
| 115 |
etag: |
| 116 |
description: |
| 117 |
- Resource entity tag (ETag). |
| 118 |
type: str |
| 119 |
returned: always |
| 120 |
sample: "3d001f14-0000-0100-0000-68ca270a0000" |
| 121 |
id: |
| 122 |
description: |
| 123 |
- Fully qualified ID of the resource. |
| 124 |
type: str |
| 125 |
returned: always |
| 126 |
sample: "/subscriptions/xxx-xxx/resourceGroups/v-xisuRG/providers/Microsoft.Insights/dataCollectionEndpoints/fredendpoint" |
| 127 |
immutable_id: |
| 128 |
description: |
| 129 |
- The immutable ID of this data collection endpoint resource. |
| 130 |
- This property is READ-ONLY. |
| 131 |
type: str |
| 132 |
returned: always |
| 133 |
sample: dce-9897a7cde9b54676a1c07ab3ea222768 |
| 134 |
kind: |
| 135 |
description: |
| 136 |
- The kind of the resource. |
| 137 |
type: str |
| 138 |
returned: always |
| 139 |
sample: Linux |
| 140 |
location: |
| 141 |
description: |
| 142 |
- The geo-location where the resource lives. |
| 143 |
type: str |
| 144 |
returned: always |
| 145 |
sample: eastus |
| 146 |
logs_ingestion: |
| 147 |
description: |
| 148 |
- The endpoint used by clients to ingest logs. |
| 149 |
type: dict |
| 150 |
returned: always |
| 151 |
sample: {"endpoint": "https://fredendpoint-q7lu.eastus-1.ingest.monitor.azure.com"} |
| 152 |
metrics_ingestion: |
| 153 |
description: |
| 154 |
- The endpoint used by clients to ingest metrics. |
| 155 |
type: dict |
| 156 |
returned: always |
| 157 |
sample: {"endpoint": "https://fredendpoint-q7lu.eastus-1.metrics.ingest.monitor.azure.com"} |
| 158 |
name: |
| 159 |
description: |
| 160 |
- The name of the resource. |
| 161 |
type: str |
| 162 |
returned: always |
| 163 |
sample: testendpoint |
| 164 |
network_acls: |
| 165 |
description: |
| 166 |
- Network access control rules for the endpoints. |
| 167 |
type: dict |
| 168 |
returned: always |
| 169 |
sample: {"public_network_access": "Enabled"} |
| 170 |
provisioning_state: |
| 171 |
description: |
| 172 |
- The resource provisioning state. This property is READ-ONLY. |
| 173 |
type: str |
| 174 |
returned: always |
| 175 |
sample: Succeeded |
| 176 |
system_data: |
| 177 |
description: |
| 178 |
- Metadata pertaining to creation and last modification of the resource. |
| 179 |
type: dict |
| 180 |
returned: always |
| 181 |
sample: { |
| 182 |
"created_at": "2025-09-17T03:12:08.743499Z", |
| 183 |
"created_by": "00867800-0fa3-4d02-8bc8-35edac3a0d32", |
| 184 |
"created_by_type": "Application", |
| 185 |
"last_modified_at": "2025-09-17T03:12:08.743499Z", |
| 186 |
"last_modified_by": "00867800-0fa3-4d02-8bc8-35edac3a0d32", |
| 187 |
"last_modified_by_type": "Application" |
| 188 |
} |
| 189 |
tags: |
| 190 |
description: |
| 191 |
- Resource tags. |
| 192 |
returned: always |
| 193 |
type: dict |
| 194 |
sample: {'key1': 'value1'} |
| 195 |
type: |
| 196 |
description: |
| 197 |
- The type of the resource. |
| 198 |
returned: always |
| 199 |
type: str |
| 200 |
sample: "Microsoft.Insights/dataCollectionEndpoints" |
| 201 |
''' |
| 202 |
|
| 203 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt |
| 204 |
|
| 205 |
|
| 206 |
network_acls_spec = dict( |
| 207 |
public_network_access=dict( |
| 208 |
type='str', |
| 209 |
choices=["Enabled", "Disabled", "SecuredByPerimeter"] |
| 210 |
) |
| 211 |
) |
| 212 |
|
| 213 |
|
| 214 |
class AzureRMDataCollectionRuleEndpoint(AzureRMModuleBaseExt): |
| 215 |
"""Information class for an Azure RM Data Collection Rules""" |
| 216 |
|
| 217 |
def __init__(self): |
| 218 |
self.module_arg_spec = dict( |
| 219 |
name=dict(type='str', required=True), |
| 220 |
resource_group=dict(type='str', required=True), |
| 221 |
location=dict(type='str'), |
| 222 |
kind=dict(type='str', choices=['Linux', 'Windows']), |
| 223 |
description=dict(type='str'), |
| 224 |
state=dict(type='str', default='present', choices=['present', 'absent']), |
| 225 |
network_acls=dict( |
| 226 |
type='dict', |
| 227 |
options=network_acls_spec |
| 228 |
) |
| 229 |
) |
| 230 |
|
| 231 |
self.resource_group = None |
| 232 |
self.name = None |
| 233 |
self.location = None |
| 234 |
self.kind = None |
| 235 |
self.description = None |
| 236 |
self.network_acls = None |
| 237 |
self.tags = None |
| 238 |
self.state = None |
| 239 |
self.log_path = None |
| 240 |
self.log_mode = None |
| 241 |
self.body = dict() |
| 242 |
|
| 243 |
self.results = dict( |
| 244 |
changed=False, |
| 245 |
datacollectionendpoint=None |
| 246 |
) |
| 247 |
|
| 248 |
super(AzureRMDataCollectionRuleEndpoint, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 249 |
supports_check_mode=True, |
| 250 |
supports_tags=True, |
| 251 |
facts_module=True) |
| 252 |
|
| 253 |
def exec_module(self, **kwargs): |
| 254 |
"""Main module execution method""" |
| 255 |
|
| 256 |
for key in list(self.module_arg_spec.keys()) + ['tags']: |
| 257 |
if key in ['resource_group', 'state', 'name']: |
| 258 |
setattr(self, key, kwargs[key]) |
| 259 |
else: |
| 260 |
self.body[key] = kwargs[key] |
| 261 |
|
| 262 |
resource_group = self.get_resource_group(self.resource_group) |
| 263 |
if not self.body.get('location'): |
| 264 |
|
| 265 |
self.body['location'] = resource_group.location |
| 266 |
|
| 267 |
self.tags = self.body.get('tags') |
| 268 |
response = self.get_endpoint() |
| 269 |
changed = False |
| 270 |
if self.state == 'present': |
| 271 |
if response: |
| 272 |
self.log("The monitor data collection endpoint already exist") |
| 273 |
update_tags, self.body['tags'] = self.update_tags(response.get('tags', dict())) |
| 274 |
if update_tags: |
| 275 |
changed = True |
| 276 |
if self.body.get('description') and self.body['description'] != response.get('description'): |
| 277 |
changed = True |
| 278 |
else: |
| 279 |
self.body['description'] = response.get('description') |
| 280 |
if self.body.get('kind') and self.body.get('kind') != response.get('kind'): |
| 281 |
changed = True |
| 282 |
else: |
| 283 |
self.body['kind'] = response.get('kind') |
| 284 |
if self.body.get('network_acls') and self.body['network_acls'] != response.get('network_acls'): |
| 285 |
changed = True |
| 286 |
else: |
| 287 |
self.body['network_acls'] = response.get('network_acls') |
| 288 |
else: |
| 289 |
changed = True |
| 290 |
self.log("There is no monitor data collection endpoint, will create a new") |
| 291 |
|
| 292 |
if self.check_mode: |
| 293 |
self.log("Check mode test") |
| 294 |
elif changed: |
| 295 |
response = self.create_endpoint(self.body) |
| 296 |
else: |
| 297 |
if response: |
| 298 |
changed = True |
| 299 |
if self.check_mode: |
| 300 |
self.log("The monitor data collection endpoint already exist, will be delete") |
| 301 |
else: |
| 302 |
response = self.delete_endpoint() |
| 303 |
else: |
| 304 |
if self.check_mode: |
| 305 |
self.log("There is no monitor data collection endpoint.") |
| 306 |
|
| 307 |
self.results['datacollectionruleendpoint'] = response |
| 308 |
self.results['changed'] = changed |
| 309 |
return self.results |
| 310 |
|
| 311 |
def get_endpoint(self): |
| 312 |
''' |
| 313 |
Gets the specified data collection rule endpoint |
| 314 |
''' |
| 315 |
response = None |
| 316 |
try: |
| 317 |
response = self.monitor_management_client_data_collection_rules.data_collection_endpoints.get(resource_group_name=self.resource_group, |
| 318 |
data_collection_endpoint_name=self.name) |
| 319 |
except Exception as ex: |
| 320 |
self.log("Could not find data collection endpoint {0} in resource group {1}, Exception as {2}".format(self.name, self.resource_group, ex)) |
| 321 |
if response: |
| 322 |
return response.as_dict() |
| 323 |
|
| 324 |
def create_endpoint(self, body): |
| 325 |
''' |
| 326 |
Create a new Data Collection Endpoint |
| 327 |
''' |
| 328 |
response = None |
| 329 |
try: |
| 330 |
response = self.monitor_management_client_data_collection_rules.data_collection_endpoints.create(resource_group_name=self.resource_group, |
| 331 |
data_collection_endpoint_name=self.name, |
| 332 |
body=body) |
| 333 |
except Exception as ex: |
| 334 |
self.fail("Create the data collection endponts occurred exception, Exception as {0}".format(ex)) |
| 335 |
|
| 336 |
if response: |
| 337 |
return response.as_dict() |
| 338 |
|
| 339 |
def delete_endpoint(self): |
| 340 |
''' |
| 341 |
Delete the Data Collection Endpoint |
| 342 |
''' |
| 343 |
try: |
| 344 |
self.monitor_management_client_data_collection_rules.data_collection_endpoints.delete(resource_group_name=self.resource_group, |
| 345 |
data_collection_endpoint_name=self.name) |
| 346 |
except Exception as ex: |
| 347 |
self.fail("Delete the data collection endponts occurred exception, Exception as {0}".format(ex)) |
| 348 |
|
| 349 |
|
| 350 |
def main(): |
| 351 |
"""Main execution""" |
| 352 |
AzureRMDataCollectionRuleEndpoint() |
| 353 |
|
| 354 |
|
| 355 |
if __name__ == '__main__': |
| 356 |
main() |