Attempt at fixing custom condition json error

This commit is contained in:
JonnyWong16 2018-03-13 22:16:23 -07:00
commit 87d2d273d3
4 changed files with 20 additions and 21 deletions

View file

@ -208,13 +208,7 @@ def notify_custom_conditions(notifier_id=None, parameters=None):
notifier_config = notifiers.get_notifier_config(notifier_id=notifier_id)
custom_conditions_logic = notifier_config['custom_conditions_logic']
try:
custom_conditions = json.loads(notifier_config['custom_conditions']) or []
except ValueError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom condition: %s." % e)
logger.debug(u"Tautulli NotificationHandler :: Custom conditions json: %s "
% notifier_config['custom_conditions'])
custom_conditions = []
custom_conditions = notifier_config['custom_conditions']
if custom_conditions_logic or any(c for c in custom_conditions if c['value']):
logger.debug(u"Tautulli NotificationHandler :: Checking custom notification conditions for notifier_id %s."

View file

@ -94,6 +94,8 @@ AGENT_IDS = {'growl': 0,
'zapier': 24
}
DEFAULT_CUSTOM_CONDITIONS = [{'parameter': '', 'operator': '', 'value': ''}]
def available_notification_agents():
agents = [{'label': 'Tautulli Remote Android App',
@ -446,7 +448,6 @@ def get_notifier_config(notifier_id=None):
db = database.MonitorDatabase()
result = db.select_single('SELECT * FROM notifiers WHERE id = ?',
args=[notifier_id])
if not result:
return None
@ -468,6 +469,14 @@ def get_notifier_config(notifier_id=None):
notifier_text[k] = {'subject': result.pop(k + '_subject'),
'body': result.pop(k + '_body')}
try:
result['custom_conditions'] = json.loads(result['custom_conditions'])
except (ValueError, TypeError):
result['custom_conditions'] = DEFAULT_CUSTOM_CONDITIONS
if not result['custom_conditions_logic']:
result['custom_conditions_logic'] = ''
result['config'] = config
result['config_options'] = notifier_config
result['actions'] = notifier_actions
@ -494,7 +503,9 @@ def add_notifier_config(agent_id=None, **kwargs):
'agent_name': agent['name'],
'agent_label': agent['label'],
'friendly_name': '',
'notifier_config': json.dumps(get_agent_class(agent_id=agent['id']).config)
'notifier_config': json.dumps(get_agent_class(agent_id=agent['id']).config),
'custom_conditions': json.dumps(DEFAULT_CUSTOM_CONDITIONS),
'custom_conditions_logic': ''
}
if agent['name'] == 'scripts':
for a in available_notification_actions():
@ -549,7 +560,7 @@ def set_notifier_config(notifier_id=None, agent_id=None, **kwargs):
'agent_label': agent['label'],
'friendly_name': kwargs.get('friendly_name', ''),
'notifier_config': json.dumps(notifier_config),
'custom_conditions': kwargs.get('custom_conditions', ''),
'custom_conditions': kwargs.get('custom_conditions', json.dumps(DEFAULT_CUSTOM_CONDITIONS)),
'custom_conditions_logic': kwargs.get('custom_conditions_logic', ''),
}
values.update(actions)

View file

@ -3004,18 +3004,12 @@ class WebInterface(object):
def get_notifier_config_modal(self, notifier_id=None, **kwargs):
result = notifiers.get_notifier_config(notifier_id=notifier_id)
if not result['custom_conditions']:
result['custom_conditions'] = json.dumps([{'parameter': '', 'operator': '', 'value': ''}])
if not result['custom_conditions_logic']:
result['custom_conditions_logic'] = ''
parameters = [
{'name': param['name'], 'type': param['type'], 'value': param['value']}
for category in common.NOTIFICATION_PARAMETERS for param in category['parameters']
]
return serve_template(templatename="notifier_config.html", notifier=result, parameters=json.dumps(parameters))
return serve_template(templatename="notifier_config.html", notifier=result, parameters=parameters)
@cherrypy.expose
@cherrypy.tools.json_out()