Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_monitordatacollectionruleassociation_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import absolute_import, division, print_function
6 __metaclass__ = type
7
8 DOCUMENTATION = '''
9 ---
10 module: azure_rm_monitordatacollectionruleassociation_info
11 version_added: "3.9.0"
12 short_description: Get or list Data Collection Rule Association
13 description:
14 - Get or list Data Collection Rule Association.
15
16 options:
17 data_collection_endpoint_name:
18 description:
19 - The name of the data collection endpoint.
20 - The name is case insensitive.
21 type: str
22 data_collection_rule_name:
23 description:
24 - The name of the data collection rule.
25 - The name is case insensitive.
26 type: str
27 resource_uri:
28 description:
29 - The identifier of the resource.
30 type: str
31 association_name:
32 description:
33 - The name of the association.
34 - The name is case insensitive.
35 type: str
36 resource_group:
37 description:
38 - The name of the resource group in which the data collection rule association is (if you use name)
39 type: str
40 extends_documentation_fragment:
41 - azure.azcollection.azure
42
43 author:
44 - magodo (@magodo)
45 - Fred Sun (@Fred-sun)
46 '''
47
48 EXAMPLES = '''
49 - name: Get data collection rule association details
50 azure.azcollection.azure_rm_monitordatacollectionrulesassociation_info:
51 association_name: association01
52 resource_uri: "/subscriptions/xxx-xxx/resourceGroups/v-xisuRG/providers/Microsoft.Compute/virtualMachines/fredVM"
53
54 - name: List all data collection rule associations with data_collection_endpoint_name
55 azure.azcollection.azure_rm_monitordatacollectionrulesassociation_info:
56 resource_group: Resource_Group_Name
57 data_collection_endpoint_name: fredrpfx001-DCE
58
59 - name: List all data collection rule associations with data_collection_rule_name
60 azure.azcollection.azure_rm_monitordatacollectionrulesassociation_info:
61 resource_group: Resource_Group_Name
62 data_collection_rule_name: fredrpfx001-DCR
63
64 - name: List all data collection rule associations with the resource_uri
65 azure.azcollection.azure_rm_monitordatacollectionrulesassociation_info:
66 resource_uri: "/subscriptions/xxx-xxx/resourceGroups/v-xisuRG/providers/Microsoft.Compute/virtualMachines/fredVM"
67 '''
68
69 RETURN = '''
70 datacollectionruleassociations:
71 description:
72 - List of data collection rule association.
73 - Can be empty if listing data collection rule association.
74 type: complex
75 returned: always
76 contains:
77 data_collection_rule_id:
78 description:
79 - The resource ID of the data collection endpoint that is to be associated.
80 type: str
81 returned: when-used
82 sample: "/subscriptions/xxxxx/resourceGroups/v-xisuRG02/providers/Microsoft.Insights/dataCollectionRules/fredrpfx001-DCR"
83 data_collection_endpoint_id:
84 description:
85 - The resource ID of the data collection endpoint that is to be associated.
86 type: str
87 returned: when-used
88 sample: "/subscriptions/xxx-xxx/resourceGroups/v-xisuRG/providers/Microsoft.Insights/dataCollectionEndpoints/fredendpoint"
89 description:
90 description:
91 - Description of the association.
92 type: str
93 returned: always
94 sample: Create
95 etag:
96 description:
97 - Description of the association.
98 returned: always
99 type: str
100 sample: "0c00c2b5-0000-0800-0000-68ca0de80000"
101 id:
102 description:
103 - Fully qualified ID of the resource.
104 type: str
105 returned: always
106 sample: "/subscriptions/xxxxxxxxxx/resourceGroups/v-xisuRG/providers/Microsoft.Compute/virtualMachines/\
107 fredVM/providers/Microsoft.Insights/dataCollectionRuleAssociations/association01"
108 name:
109 description:
110 - Description of the association.
111 type: str
112 returned: always
113 sample: associationname
114 system_data:
115 description:
116 - Metadata pertaining to creation and last modification of the resource.
117 type: dict
118 returned: always
119 sample: {
120 "created_at": "2025-09-17T01:24:56.450551Z",
121 "created_by": "00867800-0fa3-4d02-8bc8-35edac3a0d32",
122 "created_by_type": "Application",
123 "last_modified_at": "2025-09-17T01:24:56.450551Z",
124 "last_modified_by": "00867800-0fa3-4d02-8bc8-35edac3a0d32",
125 "last_modified_by_type": "Application"
126 }
127 type:
128 description:
129 - The type of the resource.
130 type: str
131 returned: always
132 sample: "Microsoft.Insights/dataCollectionRuleAssociations"
133 '''
134
135 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
136
137
138 class AzureRMDataCollectionRuleAssociationInfo(AzureRMModuleBase):
139 """Information class for an Azure RM Data Collection Rules"""
140
141 def __init__(self):
142 self.module_arg_spec = dict(
143 resource_uri=dict(type='str'),
144 association_name=dict(type='str'),
145 data_collection_endpoint_name=dict(type='str'),
146 data_collection_rule_name=dict(type='str'),
147 resource_group=dict(type='str')
148 )
149
150 self.required_by = {
151 'data_collection_rule_name': 'resource_group',
152 'data_collection_endpoint_name': 'resource_group',
153 'association_name': 'resource_uri'
154 }
155
156 self.resource_uri = None
157 self.resource_group = None
158 self.association_name = None
159 self.data_collection_endpoint_name = None
160 self.data_collection_rule_name = None
161 self.log_path = None
162 self.log_mode = None
163
164 self.results = dict(
165 changed=False,
166 datacollectionruleassociations=[]
167 )
168
169 super(AzureRMDataCollectionRuleAssociationInfo, self).__init__(derived_arg_spec=self.module_arg_spec,
170 supports_check_mode=True,
171 supports_tags=False,
172 facts_module=True,
173 required_by=self.required_by)
174
175 def exec_module(self, **kwargs):
176 """Main module execution method"""
177
178 for key in self.module_arg_spec:
179 setattr(self, key, kwargs[key])
180
181 result = []
182 if self.association_name:
183 result = self.get_association(self.resource_uri, self.association_name)
184 elif self.data_collection_rule_name:
185 result = self.list_by_rule()
186 elif self.data_collection_endpoint_name:
187 result = self.list_by_data_collection_endpoint()
188 elif self.resource_uri:
189 result = self.list_by_resource()
190 else:
191 self.fail("One of association_name, data_collection_rule_name, data_collection_endpoint_name and resource_uri must be configured")
192
193 self.results['datacollectionruleassociations'] = result
194
195 return self.results
196
197 def get_association(self, resource_uri, association_name):
198 '''
199 Gets the specified association
200 '''
201 result = []
202 response = None
203
204 try:
205 response = self.monitor_management_client_data_collection_rules.data_collection_rule_associations.get(resource_uri=resource_uri,
206 association_name=association_name)
207 except Exception:
208 self.log("Could not find data collection rule assoication {0} in resource uri {1}".format(self.association_name, self.resource_uri))
209 return []
210 if response:
211 result = [response.as_dict()]
212
213 return result
214
215 def list_by_resource(self):
216 '''
217 Lists associations for the specified resource.
218 '''
219 result = []
220 response = None
221
222 try:
223 response = self.monitor_management_client_data_collection_rules.data_collection_rule_associations.list_by_resource(resource_uri=self.resource_uri)
224 except Exception as ex:
225 self.log("Could not list data collection rule assoication in resource uri {0}, Exception as {1}".format(self.resource_uri, ex))
226 return []
227 if response:
228 for item in response:
229 result.append(item.as_dict())
230
231 return result
232
233 def list_by_rule(self):
234 '''
235 Lists associations for the specified data collection rule.
236 '''
237 result = []
238 response = None
239 try:
240 response = self.monitor_management_client_data_collection_rules.data_collection_rule_associations.list_by_rule(
241 resource_group_name=self.resource_group,
242 data_collection_rule_name=self.data_collection_rule_name)
243 except Exception as ex:
244 self.log("Could not list assoication in data collection rule {0}, Exception as {1}".format(self.data_collection_rule_name, ex))
245 return []
246 if response:
247 for item in response:
248 association = item.as_dict()
249 result += self.get_association(association['id'].split('providers/microsoft.insights')[0], association['name'])
250
251 return result
252
253 def list_by_data_collection_endpoint(self):
254 '''
255 Lists associations for the specified data collection endpoint.
256 '''
257 result = []
258 response = None
259
260 try:
261 response = self.monitor_management_client_data_collection_rules.data_collection_rule_associations.list_by_data_collection_endpoint(
262 resource_group_name=self.resource_group,
263 data_collection_endpoint_name=self.data_collection_endpoint_name)
264 except Exception as ex:
265 self.log("Could not list associations for the data collection rule endpoint {0}, Exception as {1}".format(self.data_collection_endpoint_name, ex))
266 return []
267 if response:
268 for item in response:
269 result.append(item.as_dict())
270
271 return result
272
273
274 def main():
275 """Main execution"""
276 AzureRMDataCollectionRuleAssociationInfo()
277
278
279 if __name__ == '__main__':
280 main()