Format Webhook data strings only

This commit is contained in:
JonnyWong16 2018-08-12 10:54:39 -07:00
parent 4648e3df5f
commit 5736e12bc3
2 changed files with 21 additions and 17 deletions

View file

@ -1128,10 +1128,7 @@ def traverse_map(obj, func):
for k, v in obj.iteritems(): for k, v in obj.iteritems():
new_obj[traverse_map(k, func)] = traverse_map(v, func) new_obj[traverse_map(k, func)] = traverse_map(v, func)
elif isinstance(obj, basestring): else:
new_obj = func(obj) new_obj = func(obj)
else:
new_obj = obj
return new_obj return new_obj

View file

@ -1058,20 +1058,27 @@ def build_notify_text(subject='', body='', notify_action=None, parameters=None,
script_args = [] script_args = []
elif agent_id == 25: elif agent_id == 25:
try: if body:
body = json.loads(body) try:
except ValueError as e: body = json.loads(body)
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom webhook json data: %s. Using fallback." % e) except ValueError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom webhook json data: %s. Using fallback." % e)
body = ''
try: if body:
body = json.dumps(helpers.traverse_map(body, def str_format(s):
lambda x: custom_formatter.format(x, **parameters).decode(plexpy.SYS_ENCODING, 'ignore'))) if isinstance(s, basestring):
except LookupError as e: return custom_formatter.format(s, **parameters).decode(plexpy.SYS_ENCODING, 'ignore')
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in webhook data. Using fallback." % e) return s
body = ''
except Exception as e: try:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom webhook data: %s. Using fallback." % e) body = json.dumps(helpers.traverse_map(body, str_format))
body = '' except LookupError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in webhook data. Using fallback." % e)
body = ''
except Exception as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom webhook data: %s. Using fallback." % e)
body = ''
else: else:
try: try: