1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -110,7 +110,7 @@ class SplunkHTTPCollectorSource:
self.user = getpass.getuser()
def send_event(self, url, authtoken, validate_certs, include_milliseconds, batch, state, result, runtime):
if result._task_fields['args'].get('_ansible_check_mode') is True:
if result._task_fields["args"].get("_ansible_check_mode") is True:
self.ansible_check_mode = True
if result._task._role:
@ -118,33 +118,33 @@ class SplunkHTTPCollectorSource:
else:
ansible_role = None
if 'args' in result._task_fields:
del result._task_fields['args']
if "args" in result._task_fields:
del result._task_fields["args"]
data = {}
data['uuid'] = result._task._uuid
data['session'] = self.session
data["uuid"] = result._task._uuid
data["session"] = self.session
if batch is not None:
data['batch'] = batch
data['status'] = state
data["batch"] = batch
data["status"] = state
if include_milliseconds:
time_format = '%Y-%m-%d %H:%M:%S.%f +0000'
time_format = "%Y-%m-%d %H:%M:%S.%f +0000"
else:
time_format = '%Y-%m-%d %H:%M:%S +0000'
time_format = "%Y-%m-%d %H:%M:%S +0000"
data['timestamp'] = now().strftime(time_format)
data['host'] = self.host
data['ip_address'] = self.ip_address
data['user'] = self.user
data['runtime'] = runtime
data['ansible_version'] = ansible_version
data['ansible_check_mode'] = self.ansible_check_mode
data['ansible_host'] = result._host.name
data['ansible_playbook'] = self.ansible_playbook
data['ansible_role'] = ansible_role
data['ansible_task'] = result._task_fields
data['ansible_result'] = result._result
data["timestamp"] = now().strftime(time_format)
data["host"] = self.host
data["ip_address"] = self.ip_address
data["user"] = self.user
data["runtime"] = runtime
data["ansible_version"] = ansible_version
data["ansible_check_mode"] = self.ansible_check_mode
data["ansible_host"] = result._host.name
data["ansible_playbook"] = self.ansible_playbook
data["ansible_role"] = ansible_role
data["ansible_task"] = result._task_fields
data["ansible_result"] = result._result
# This wraps the json payload in and outer json event needed by Splunk
jsondata = json.dumps({"event": data}, cls=AnsibleJSONEncoder, sort_keys=True)
@ -152,19 +152,16 @@ class SplunkHTTPCollectorSource:
open_url(
url,
jsondata,
headers={
'Content-type': 'application/json',
'Authorization': f"Splunk {authtoken}"
},
method='POST',
validate_certs=validate_certs
headers={"Content-type": "application/json", "Authorization": f"Splunk {authtoken}"},
method="POST",
validate_certs=validate_certs,
)
class CallbackModule(CallbackBase):
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'notification'
CALLBACK_NAME = 'community.general.splunk'
CALLBACK_TYPE = "notification"
CALLBACK_NAME = "community.general.splunk"
CALLBACK_NEEDS_WHITELIST = True
def __init__(self, display=None):
@ -178,39 +175,40 @@ class CallbackModule(CallbackBase):
self.splunk = SplunkHTTPCollectorSource()
def _runtime(self, result):
return (
now() -
self.start_datetimes[result._task._uuid]
).total_seconds()
return (now() - self.start_datetimes[result._task._uuid]).total_seconds()
def set_options(self, task_keys=None, var_options=None, direct=None):
super().set_options(task_keys=task_keys, var_options=var_options, direct=direct)
self.url = self.get_option('url')
self.url = self.get_option("url")
if self.url is None:
self.disabled = True
self._display.warning('Splunk HTTP collector source URL was '
'not provided. The Splunk HTTP collector '
'source URL can be provided using the '
'`SPLUNK_URL` environment variable or '
'in the ansible.cfg file.')
self._display.warning(
"Splunk HTTP collector source URL was "
"not provided. The Splunk HTTP collector "
"source URL can be provided using the "
"`SPLUNK_URL` environment variable or "
"in the ansible.cfg file."
)
self.authtoken = self.get_option('authtoken')
self.authtoken = self.get_option("authtoken")
if self.authtoken is None:
self.disabled = True
self._display.warning('Splunk HTTP collector requires an authentication'
'token. The Splunk HTTP collector '
'authentication token can be provided using the '
'`SPLUNK_AUTHTOKEN` environment variable or '
'in the ansible.cfg file.')
self._display.warning(
"Splunk HTTP collector requires an authentication"
"token. The Splunk HTTP collector "
"authentication token can be provided using the "
"`SPLUNK_AUTHTOKEN` environment variable or "
"in the ansible.cfg file."
)
self.validate_certs = self.get_option('validate_certs')
self.validate_certs = self.get_option("validate_certs")
self.include_milliseconds = self.get_option('include_milliseconds')
self.include_milliseconds = self.get_option("include_milliseconds")
self.batch = self.get_option('batch')
self.batch = self.get_option("batch")
def v2_playbook_on_start(self, playbook):
self.splunk.ansible_playbook = basename(playbook._file_name)
@ -228,9 +226,9 @@ class CallbackModule(CallbackBase):
self.validate_certs,
self.include_milliseconds,
self.batch,
'OK',
"OK",
result,
self._runtime(result)
self._runtime(result),
)
def v2_runner_on_skipped(self, result, **kwargs):
@ -240,9 +238,9 @@ class CallbackModule(CallbackBase):
self.validate_certs,
self.include_milliseconds,
self.batch,
'SKIPPED',
"SKIPPED",
result,
self._runtime(result)
self._runtime(result),
)
def v2_runner_on_failed(self, result, **kwargs):
@ -252,9 +250,9 @@ class CallbackModule(CallbackBase):
self.validate_certs,
self.include_milliseconds,
self.batch,
'FAILED',
"FAILED",
result,
self._runtime(result)
self._runtime(result),
)
def runner_on_async_failed(self, result, **kwargs):
@ -264,9 +262,9 @@ class CallbackModule(CallbackBase):
self.validate_certs,
self.include_milliseconds,
self.batch,
'FAILED',
"FAILED",
result,
self._runtime(result)
self._runtime(result),
)
def v2_runner_on_unreachable(self, result, **kwargs):
@ -276,7 +274,7 @@ class CallbackModule(CallbackBase):
self.validate_certs,
self.include_milliseconds,
self.batch,
'UNREACHABLE',
"UNREACHABLE",
result,
self._runtime(result)
self._runtime(result),
)