mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Log individual custom conditions
This commit is contained in:
parent
6908034a86
commit
30be4b473f
1 changed files with 30 additions and 18 deletions
|
@ -232,7 +232,7 @@ def notify_custom_conditions(notifier_id=None, parameters=None):
|
||||||
|
|
||||||
evaluated_conditions = [None] # Set condition {0} to None
|
evaluated_conditions = [None] # Set condition {0} to None
|
||||||
|
|
||||||
for condition in custom_conditions:
|
for i, condition in enumerate(custom_conditions):
|
||||||
parameter = condition['parameter']
|
parameter = condition['parameter']
|
||||||
operator = condition['operator']
|
operator = condition['operator']
|
||||||
values = condition['value']
|
values = condition['value']
|
||||||
|
@ -241,7 +241,9 @@ def notify_custom_conditions(notifier_id=None, parameters=None):
|
||||||
|
|
||||||
# Set blank conditions to True (skip)
|
# Set blank conditions to True (skip)
|
||||||
if not parameter or not operator or not values:
|
if not parameter or not operator or not values:
|
||||||
evaluated_conditions.append(True)
|
evaluated = True
|
||||||
|
evaluated_conditions.append(evaluated)
|
||||||
|
logger.debug(u"Tautulli NotificationHandler :: {%s} Blank condition > %s" % (i+1, evaluated))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Make sure the condition values is in a list
|
# Make sure the condition values is in a list
|
||||||
|
@ -260,8 +262,8 @@ def notify_custom_conditions(notifier_id=None, parameters=None):
|
||||||
values = [helpers.cast_to_float(v) for v in values]
|
values = [helpers.cast_to_float(v) for v in values]
|
||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error(u"Tautulli NotificationHandler :: Unable to cast condition '%s', values '%s', to type '%s'."
|
logger.error(u"Tautulli NotificationHandler :: {%s} Unable to cast condition '%s', values '%s', to type '%s'."
|
||||||
% (parameter, values, parameter_type))
|
% (i+1, parameter, values, parameter_type))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Cast the parameter value to the correct type
|
# Cast the parameter value to the correct type
|
||||||
|
@ -276,50 +278,60 @@ def notify_custom_conditions(notifier_id=None, parameters=None):
|
||||||
parameter_value = helpers.cast_to_float(parameter_value)
|
parameter_value = helpers.cast_to_float(parameter_value)
|
||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error(u"Tautulli NotificationHandler :: Unable to cast parameter '%s', value '%s', to type '%s'."
|
logger.error(u"Tautulli NotificationHandler :: {%s} Unable to cast parameter '%s', value '%s', to type '%s'."
|
||||||
% (parameter, parameter_value, parameter_type))
|
% (i+1, parameter, parameter_value, parameter_type))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Check each condition
|
# Check each condition
|
||||||
if operator == 'contains':
|
if operator == 'contains':
|
||||||
evaluated_conditions.append(any(c in parameter_value for c in values))
|
evaluated = any(c in parameter_value for c in values)
|
||||||
|
|
||||||
elif operator == 'does not contain':
|
elif operator == 'does not contain':
|
||||||
evaluated_conditions.append(all(c not in parameter_value for c in values))
|
evaluated = all(c not in parameter_value for c in values)
|
||||||
|
|
||||||
elif operator == 'is':
|
elif operator == 'is':
|
||||||
evaluated_conditions.append(any(parameter_value == c for c in values))
|
evaluated = any(parameter_value == c for c in values)
|
||||||
|
|
||||||
elif operator == 'is not':
|
elif operator == 'is not':
|
||||||
evaluated_conditions.append(all(parameter_value != c for c in values))
|
evaluated = all(parameter_value != c for c in values)
|
||||||
|
|
||||||
elif operator == 'begins with':
|
elif operator == 'begins with':
|
||||||
evaluated_conditions.append(parameter_value.startswith(tuple(values)))
|
evaluated = parameter_value.startswith(tuple(values))
|
||||||
|
|
||||||
elif operator == 'ends with':
|
elif operator == 'ends with':
|
||||||
evaluated_conditions.append(parameter_value.endswith(tuple(values)))
|
evaluated = parameter_value.endswith(tuple(values))
|
||||||
|
|
||||||
elif operator == 'is greater than':
|
elif operator == 'is greater than':
|
||||||
evaluated_conditions.append(any(parameter_value > c for c in values))
|
evaluated = any(parameter_value > c for c in values)
|
||||||
|
|
||||||
elif operator == 'is less than':
|
elif operator == 'is less than':
|
||||||
evaluated_conditions.append(any(parameter_value < c for c in values))
|
evaluated = any(parameter_value < c for c in values)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.warn(u"Tautulli NotificationHandler :: Invalid condition operator '%s'." % operator)
|
evaluated = None
|
||||||
evaluated_conditions.append(None)
|
logger.warn(u"Tautulli NotificationHandler :: {%s} Invalid condition operator '%s' > %s."
|
||||||
|
% (i+1, operator, evaluated))
|
||||||
|
|
||||||
|
evaluated_conditions.append(evaluated)
|
||||||
|
logger.debug(u"Tautulli NotificationHandler :: {%s} %s | %s | %s > '%s' > %s"
|
||||||
|
% (i+1, parameter, operator, ' or '.join(["'%s'" % v for v in values]), parameter_value, evaluated))
|
||||||
|
|
||||||
if logic_groups:
|
if logic_groups:
|
||||||
# Format and evaluate the logic string
|
# Format and evaluate the logic string
|
||||||
try:
|
try:
|
||||||
evaluated_logic = helpers.eval_logic_groups_to_bool(logic_groups, evaluated_conditions)
|
evaluated_logic = helpers.eval_logic_groups_to_bool(logic_groups, evaluated_conditions)
|
||||||
|
logger.debug(u"Tautulli NotificationHandler :: Condition logic: %s > %s"
|
||||||
|
% (custom_conditions_logic, evaluated_logic))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(u"Tautulli NotificationHandler :: Unable to evaluate custom condition logic: %s." % e)
|
logger.error(u"Tautulli NotificationHandler :: Unable to evaluate custom condition logic: %s." % e)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
evaluated_logic = all(evaluated_conditions[1:])
|
|
||||||
|
|
||||||
logger.debug(u"Tautulli NotificationHandler :: Custom condition evaluated to '{}'. Conditions: {}.".format(
|
evaluated_logic = all(evaluated_conditions[1:])
|
||||||
|
logger.debug(u"Tautulli NotificationHandler :: Condition logic [blank]: %s > %s"
|
||||||
|
% (' and '.join(['{%s}' % (i+1) for i in range(len(custom_conditions))]), evaluated_logic))
|
||||||
|
|
||||||
|
logger.debug(u"Tautulli NotificationHandler :: Custom conditions evaluated to '{}'. Conditions: {}.".format(
|
||||||
evaluated_logic, evaluated_conditions[1:]))
|
evaluated_logic, evaluated_conditions[1:]))
|
||||||
|
|
||||||
return evaluated_logic
|
return evaluated_logic
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue