diff options
Diffstat (limited to 'automato/action.py')
-rw-r--r-- | automato/action.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/automato/action.py b/automato/action.py index 7bb50ea..785a0ee 100644 --- a/automato/action.py +++ b/automato/action.py @@ -1,5 +1,6 @@ from typing import Dict import logging +logger = logging.getLogger(__name__) from . import endpoint from . import trigger @@ -21,37 +22,37 @@ class Action: def _setup_triggers(self): for trg_list_item in self._trigger_cfg: if len(trg_list_item.keys()) != 1: - logging.error(f'Action "{self._name}" encountered error while adding trigger "{trg_list_item}"') + logger.error(f'Action "{self._name}" encountered error while adding trigger "{trg_list_item}"') raise Exception trg_key = list(trg_list_item.keys())[0] trg_config = trg_list_item[trg_key] if not trg_key in self._triggers: - logging.error(f'Action "{self._name}": Trigger "{trg_key}" is not configured.') + logger.error(f'Action "{self._name}": Trigger "{trg_key}" is not configured.') raise Exception self._configured_trigger_keys.append(trg_key) self._triggers[trg_key].addInstance(self._name, **trg_config) - logging.debug(f'Action "{self._name}" was registered with "{trg_key}"') + logger.debug(f'Action "{self._name}" was registered with "{trg_key}"') def execute(self): if not all([self._triggers[b].evaluate(self._name) for b in self._configured_trigger_keys]): - logging.debug(f'Action "{self._name}" will not execute. Conditions not met.') + logger.debug(f'Action "{self._name}" will not execute. Conditions not met.') return - logging.info(f'Executing Action "{self._name}". Conditions are met.') + logger.info(f'Executing Action "{self._name}". Conditions are met.') for then_item in self._then_cfg: if len(then_item.keys()) != 1: - logging.error(f'Action "{self._name}" encountered error while executing command "{then_item}"') + logger.error(f'Action "{self._name}" encountered error while executing command "{then_item}"') raise Exception cmd_key = list(then_item.keys())[0] cmd_config = then_item[cmd_key] - logging.info(f'Executing command "{cmd_key}"') + logger.info(f'Executing command "{cmd_key}"') endpoint, command = cmd_key.split('.', 1) self._endpoints[endpoint].executeCommand(command, **cmd_config) |