Avoid deprecated utcnow() (#8222)

Avoid deprecated utcnow().
This commit is contained in:
Felix Fontein 2024-04-20 09:26:08 +02:00 committed by GitHub
parent 1b8e6bc95b
commit 524d5883b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 142 additions and 64 deletions

View file

@ -88,13 +88,16 @@ import uuid
import socket
import getpass
from datetime import datetime
from os.path import basename
from ansible.module_utils.urls import open_url
from ansible.parsing.ajson import AnsibleJSONEncoder
from ansible.plugins.callback import CallbackBase
from ansible_collections.community.general.plugins.module_utils.datetime import (
now,
)
class SplunkHTTPCollectorSource(object):
def __init__(self):
@ -134,7 +137,7 @@ class SplunkHTTPCollectorSource(object):
else:
time_format = '%Y-%m-%d %H:%M:%S +0000'
data['timestamp'] = datetime.utcnow().strftime(time_format)
data['timestamp'] = now().strftime(time_format)
data['host'] = self.host
data['ip_address'] = self.ip_address
data['user'] = self.user
@ -181,7 +184,7 @@ class CallbackModule(CallbackBase):
def _runtime(self, result):
return (
datetime.utcnow() -
now() -
self.start_datetimes[result._task._uuid]
).total_seconds()
@ -220,10 +223,10 @@ class CallbackModule(CallbackBase):
self.splunk.ansible_playbook = basename(playbook._file_name)
def v2_playbook_on_task_start(self, task, is_conditional):
self.start_datetimes[task._uuid] = datetime.utcnow()
self.start_datetimes[task._uuid] = now()
def v2_playbook_on_handler_task_start(self, task):
self.start_datetimes[task._uuid] = datetime.utcnow()
self.start_datetimes[task._uuid] = now()
def v2_runner_on_ok(self, result, **kwargs):
self.splunk.send_event(