mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
parent
1b8e6bc95b
commit
524d5883b8
19 changed files with 142 additions and 64 deletions
|
@ -59,13 +59,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 AzureLogAnalyticsSource(object):
|
||||
def __init__(self):
|
||||
|
@ -93,7 +96,7 @@ class AzureLogAnalyticsSource(object):
|
|||
return "https://{0}.ods.opinsights.azure.com/api/logs?api-version=2016-04-01".format(workspace_id)
|
||||
|
||||
def __rfc1123date(self):
|
||||
return datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
return now().strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
|
||||
def send_event(self, workspace_id, shared_key, state, result, runtime):
|
||||
if result._task_fields['args'].get('_ansible_check_mode') is True:
|
||||
|
@ -167,7 +170,7 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
def _seconds_since_start(self, result):
|
||||
return (
|
||||
datetime.utcnow() -
|
||||
now() -
|
||||
self.start_datetimes[result._task._uuid]
|
||||
).total_seconds()
|
||||
|
||||
|
@ -185,10 +188,10 @@ class CallbackModule(CallbackBase):
|
|||
self.loganalytics.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.loganalytics.send_event(
|
||||
|
|
|
@ -99,7 +99,6 @@ from ansible import context
|
|||
import socket
|
||||
import uuid
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
try:
|
||||
import logstash
|
||||
|
@ -109,6 +108,10 @@ except ImportError:
|
|||
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.datetime import (
|
||||
now,
|
||||
)
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
|
||||
|
@ -126,7 +129,7 @@ class CallbackModule(CallbackBase):
|
|||
"pip install python-logstash for Python 2"
|
||||
"pip install python3-logstash for Python 3")
|
||||
|
||||
self.start_time = datetime.utcnow()
|
||||
self.start_time = now()
|
||||
|
||||
def _init_plugin(self):
|
||||
if not self.disabled:
|
||||
|
@ -185,7 +188,7 @@ class CallbackModule(CallbackBase):
|
|||
self.logger.info("ansible start", extra=data)
|
||||
|
||||
def v2_playbook_on_stats(self, stats):
|
||||
end_time = datetime.utcnow()
|
||||
end_time = now()
|
||||
runtime = end_time - self.start_time
|
||||
summarize_stat = {}
|
||||
for host in stats.processed.keys():
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -46,13 +46,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 SumologicHTTPCollectorSource(object):
|
||||
def __init__(self):
|
||||
|
@ -84,8 +87,7 @@ class SumologicHTTPCollectorSource(object):
|
|||
data['uuid'] = result._task._uuid
|
||||
data['session'] = self.session
|
||||
data['status'] = state
|
||||
data['timestamp'] = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S '
|
||||
'+0000')
|
||||
data['timestamp'] = now().strftime('%Y-%m-%d %H:%M:%S +0000')
|
||||
data['host'] = self.host
|
||||
data['ip_address'] = self.ip_address
|
||||
data['user'] = self.user
|
||||
|
@ -123,7 +125,7 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
def _runtime(self, result):
|
||||
return (
|
||||
datetime.utcnow() -
|
||||
now() -
|
||||
self.start_datetimes[result._task._uuid]
|
||||
).total_seconds()
|
||||
|
||||
|
@ -144,10 +146,10 @@ class CallbackModule(CallbackBase):
|
|||
self.sumologic.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.sumologic.send_event(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue