mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
[PR #9321/c3ed2144 backport][stable-10] callback plugins: use f-strings (#9357)
callback plugins: use f-strings (#9321)
* callback plugins: use f-strings
* add changelog frag
* manual change for few occurrences
* manual change for few occurrences
* adjustment from review
* adjustment from review
* adjustment from review
* Update plugins/callback/splunk.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* replace str templating with JSON templating
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c3ed2144e2
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
a13a6d284c
commit
3c7f05c42d
22 changed files with 251 additions and 253 deletions
|
@ -132,10 +132,10 @@ class CallbackModule(CallbackBase):
|
|||
xmldata = "<?xml version='1.0'?>\n"
|
||||
xmldata += "<checkresults>\n"
|
||||
xmldata += "<checkresult type='service'>\n"
|
||||
xmldata += "<hostname>%s</hostname>\n" % self.hostname
|
||||
xmldata += "<servicename>%s</servicename>\n" % self.servicename
|
||||
xmldata += "<state>%d</state>\n" % state
|
||||
xmldata += "<output>%s</output>\n" % msg
|
||||
xmldata += f"<hostname>{self.hostname}</hostname>\n"
|
||||
xmldata += f"<servicename>{self.servicename}</servicename>\n"
|
||||
xmldata += f"<state>{state}</state>\n"
|
||||
xmldata += f"<output>{msg}</output>\n"
|
||||
xmldata += "</checkresult>\n"
|
||||
xmldata += "</checkresults>\n"
|
||||
|
||||
|
@ -152,7 +152,7 @@ class CallbackModule(CallbackBase):
|
|||
validate_certs=self.validate_nrdp_certs)
|
||||
return response.read()
|
||||
except Exception as ex:
|
||||
self._display.warning("NRDP callback cannot send result {0}".format(ex))
|
||||
self._display.warning(f"NRDP callback cannot send result {ex}")
|
||||
|
||||
def v2_playbook_on_play_start(self, play):
|
||||
'''
|
||||
|
@ -170,17 +170,16 @@ class CallbackModule(CallbackBase):
|
|||
critical = warning = 0
|
||||
for host in hosts:
|
||||
stat = stats.summarize(host)
|
||||
gstats += "'%s_ok'=%d '%s_changed'=%d \
|
||||
'%s_unreachable'=%d '%s_failed'=%d " % \
|
||||
(host, stat['ok'], host, stat['changed'],
|
||||
host, stat['unreachable'], host, stat['failures'])
|
||||
gstats += (
|
||||
f"'{host}_ok'={stat['ok']} '{host}_changed'={stat['changed']} '{host}_unreachable'={stat['unreachable']} '{host}_failed'={stat['failures']} "
|
||||
)
|
||||
# Critical when failed tasks or unreachable host
|
||||
critical += stat['failures']
|
||||
critical += stat['unreachable']
|
||||
# Warning when changed tasks
|
||||
warning += stat['changed']
|
||||
|
||||
msg = "%s | %s" % (name, gstats)
|
||||
msg = f"{name} | {gstats}"
|
||||
if critical:
|
||||
# Send Critical
|
||||
self._send_nrdp(self.CRITICAL, msg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue