mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 08:16:06 -07:00
Attempt at fixing custom condition json error
This commit is contained in:
parent
b5c52ac71e
commit
87d2d273d3
4 changed files with 20 additions and 21 deletions
|
@ -171,7 +171,7 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="custom_conditions_logic">Condition Logic</label>
|
<label for="custom_conditions_logic">Condition Logic</label>
|
||||||
<input type="text" class="form-control" name="custom_conditions_logic" id="custom_conditions_logic" value="${notifier['custom_conditions_logic']}" required />
|
<input type="text" class="form-control" name="custom_conditions_logic" id="custom_conditions_logic" value="${notifier['custom_conditions_logic']}" />
|
||||||
<div id="custom_conditions_logic_error" class="alert alert-danger" role="alert" style="padding-top: 5px; padding-bottom: 5px; margin: 0; display: none;"><i class="fa fa-exclamation-triangle" style="color: #a94442;"></i> <span></span></div>
|
<div id="custom_conditions_logic_error" class="alert alert-danger" role="alert" style="padding-top: 5px; padding-bottom: 5px; margin: 0; display: none;"><i class="fa fa-exclamation-triangle" style="color: #a94442;"></i> <span></span></div>
|
||||||
<p class="help-block">
|
<p class="help-block">
|
||||||
Optional: Enter custom logic to use when evaluating the conditions (e.g. <span class="inline-pre">{1} and ({2} or {3})</span>).
|
Optional: Enter custom logic to use when evaluating the conditions (e.g. <span class="inline-pre">{1} and ({2} or {3})</span>).
|
||||||
|
@ -333,11 +333,11 @@
|
||||||
$('#notifier-config-modal').unbind('hidden.bs.modal');
|
$('#notifier-config-modal').unbind('hidden.bs.modal');
|
||||||
|
|
||||||
// Need this for setting conditions since conditions contain the character "
|
// Need this for setting conditions since conditions contain the character "
|
||||||
$('#custom_conditions').val(${json.dumps(notifier["custom_conditions"]) | n});
|
$('#custom_conditions').val(JSON.stringify(${json.dumps(notifier["custom_conditions"]) | n}));
|
||||||
|
|
||||||
$('#condition-widget').filterer({
|
$('#condition-widget').filterer({
|
||||||
parameters: ${parameters | n},
|
parameters: ${json.dumps(parameters) | n},
|
||||||
conditions: ${notifier["custom_conditions"] | n},
|
conditions: ${json.dumps(notifier["custom_conditions"]) | n},
|
||||||
updateConditions: function(newConditions){
|
updateConditions: function(newConditions){
|
||||||
$('#custom_conditions').val(JSON.stringify(newConditions));
|
$('#custom_conditions').val(JSON.stringify(newConditions));
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,13 +208,7 @@ def notify_custom_conditions(notifier_id=None, parameters=None):
|
||||||
notifier_config = notifiers.get_notifier_config(notifier_id=notifier_id)
|
notifier_config = notifiers.get_notifier_config(notifier_id=notifier_id)
|
||||||
|
|
||||||
custom_conditions_logic = notifier_config['custom_conditions_logic']
|
custom_conditions_logic = notifier_config['custom_conditions_logic']
|
||||||
try:
|
custom_conditions = notifier_config['custom_conditions']
|
||||||
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 = []
|
|
||||||
|
|
||||||
if custom_conditions_logic or any(c for c in custom_conditions if c['value']):
|
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."
|
logger.debug(u"Tautulli NotificationHandler :: Checking custom notification conditions for notifier_id %s."
|
||||||
|
|
|
@ -94,6 +94,8 @@ AGENT_IDS = {'growl': 0,
|
||||||
'zapier': 24
|
'zapier': 24
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFAULT_CUSTOM_CONDITIONS = [{'parameter': '', 'operator': '', 'value': ''}]
|
||||||
|
|
||||||
|
|
||||||
def available_notification_agents():
|
def available_notification_agents():
|
||||||
agents = [{'label': 'Tautulli Remote Android App',
|
agents = [{'label': 'Tautulli Remote Android App',
|
||||||
|
@ -446,7 +448,6 @@ def get_notifier_config(notifier_id=None):
|
||||||
db = database.MonitorDatabase()
|
db = database.MonitorDatabase()
|
||||||
result = db.select_single('SELECT * FROM notifiers WHERE id = ?',
|
result = db.select_single('SELECT * FROM notifiers WHERE id = ?',
|
||||||
args=[notifier_id])
|
args=[notifier_id])
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -468,6 +469,14 @@ def get_notifier_config(notifier_id=None):
|
||||||
notifier_text[k] = {'subject': result.pop(k + '_subject'),
|
notifier_text[k] = {'subject': result.pop(k + '_subject'),
|
||||||
'body': result.pop(k + '_body')}
|
'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'] = config
|
||||||
result['config_options'] = notifier_config
|
result['config_options'] = notifier_config
|
||||||
result['actions'] = notifier_actions
|
result['actions'] = notifier_actions
|
||||||
|
@ -494,7 +503,9 @@ def add_notifier_config(agent_id=None, **kwargs):
|
||||||
'agent_name': agent['name'],
|
'agent_name': agent['name'],
|
||||||
'agent_label': agent['label'],
|
'agent_label': agent['label'],
|
||||||
'friendly_name': '',
|
'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':
|
if agent['name'] == 'scripts':
|
||||||
for a in available_notification_actions():
|
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'],
|
'agent_label': agent['label'],
|
||||||
'friendly_name': kwargs.get('friendly_name', ''),
|
'friendly_name': kwargs.get('friendly_name', ''),
|
||||||
'notifier_config': json.dumps(notifier_config),
|
'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', ''),
|
'custom_conditions_logic': kwargs.get('custom_conditions_logic', ''),
|
||||||
}
|
}
|
||||||
values.update(actions)
|
values.update(actions)
|
||||||
|
|
|
@ -3004,18 +3004,12 @@ class WebInterface(object):
|
||||||
def get_notifier_config_modal(self, notifier_id=None, **kwargs):
|
def get_notifier_config_modal(self, notifier_id=None, **kwargs):
|
||||||
result = notifiers.get_notifier_config(notifier_id=notifier_id)
|
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 = [
|
parameters = [
|
||||||
{'name': param['name'], 'type': param['type'], 'value': param['value']}
|
{'name': param['name'], 'type': param['type'], 'value': param['value']}
|
||||||
for category in common.NOTIFICATION_PARAMETERS for param in category['parameters']
|
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.expose
|
||||||
@cherrypy.tools.json_out()
|
@cherrypy.tools.json_out()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue