155
155
156
156
display = Display ()
157
157
158
- class AzureLogAnalyticsIngestionSource (object ):
159
158
160
- def __init__ (self , dce_url , dcr_id , disable_attempts , disable_on_failure , client_id , client_secret , tenant_id , stream_name , include_task_args , include_content ):
159
+ class AzureLogAnalyticsIngestionSource (object ):
160
+ def __init__ (self , dce_url , dcr_id , disable_attempts , disable_on_failure , client_id , client_secret , tenant_id , stream_name , include_task_args ,
161
+ include_content ):
161
162
self .dce_url = dce_url
162
163
self .dcr_id = dcr_id
163
164
self .disabled = False
@@ -185,21 +186,22 @@ def get_bearer_token(self):
185
186
'grant_type' : 'client_credentials' ,
186
187
'client_id' : self .client_id ,
187
188
'client_secret' : self .client_secret ,
188
- # The scope value comes from https://learn.microsoft.com/en-us/azure/azure-monitor/logs/logs-ingestion-api-overview#headers and https://learn.microsoft.com/en-us/entra/identity-platform/scopes-oidc#the-default-scope
189
+ # The scope value comes from https://learn.microsoft.com/en-us/azure/azure-monitor/logs/logs-ingestion-api-overview#headers
190
+ # and https://learn.microsoft.com/en-us/entra/identity-platform/scopes-oidc#the-default-scope
189
191
'scope' : 'https://monitor.azure.com/.default'
190
192
}
191
193
response = self .requests_session .post (url , data = payload )
192
194
response .raise_for_status ()
193
- self .token_expiration_time = datetime .now ()+ timedelta (seconds = response .json ().get ("expires_in" ))
195
+ self .token_expiration_time = datetime .now () + timedelta (seconds = response .json ().get ("expires_in" ))
194
196
return response .json ().get ('access_token' )
195
197
196
198
def is_token_valid (self ):
197
- return True if (datetime .now () + timedelta (seconds = 10 ))< self .token_expiration_time else False
199
+ return True if (datetime .now () + timedelta (seconds = 10 )) < self .token_expiration_time else False
198
200
199
201
# Method to send event data to the Azure Logs Ingestion API
200
202
# This replaces the legacy API call and now uses the Logs Ingestion API endpoint
201
203
def send_event (self , event_data ):
202
- if not ( self .is_token_valid () ):
204
+ if not self .is_token_valid ():
203
205
self .bearer_token = self .get_bearer_token ()
204
206
ingestion_url = f"{ self .dce_url } /dataCollectionRules/{ self .dcr_id } /streams/{ self .stream_name } ?api-version=2023-01-01"
205
207
headers = {
@@ -241,12 +243,12 @@ def _send_to_loganalytics(self, playbook_name, result, state):
241
243
if result ._task ._role :
242
244
ansible_role = str (result ._task ._role )
243
245
244
- #Include/Exclude task args
245
- if not ( self .include_task_args ) :
246
+ # Include/Exclude task args
247
+ if not self .include_task_args :
246
248
result ._task_fields .pop ('args' , None )
247
249
248
- #Include/Exclude content
249
- if not ( self .include_content ) :
250
+ # Include/Exclude content
251
+ if not self .include_content :
250
252
result ._result .pop ('content' , None )
251
253
252
254
# Build the event data
@@ -263,7 +265,7 @@ def _send_to_loganalytics(self, playbook_name, result, state):
263
265
"Result" : result ._result ,
264
266
"Session" : self .session
265
267
}]
266
- #Display event data
268
+ # Display event data
267
269
display .vvv (f"Event Data :{ str (event_data )} " )
268
270
269
271
# Send the event data using the new Logs Ingestion API method
@@ -300,7 +302,8 @@ def set_options(self, task_keys=None, var_options=None, direct=None):
300
302
301
303
# Initialize the AzureLogAnalyticsIngestionSource with the new settings
302
304
self .azure_loganalytics = AzureLogAnalyticsIngestionSource (
303
- self .dce_url , self .dcr_id , self .disable_attempts , self .disable_on_failure , self .client_id , self .client_secret , self .tenant_id , self .stream_name , self .include_task_args , self .include_content
305
+ self .dce_url , self .dcr_id , self .disable_attempts , self .disable_on_failure , self .client_id , self .client_secret , self .tenant_id , self .stream_name ,
306
+ self .include_task_args , self .include_content
304
307
)
305
308
306
309
# Input checks
0 commit comments