diff --git a/salt/returners/slack_returner.py b/salt/returners/slack_returner.py index 7bd5faf91b8c..b35eb9979d42 100644 --- a/salt/returners/slack_returner.py +++ b/salt/returners/slack_returner.py @@ -14,6 +14,7 @@ slack.as_user (required to see the profile picture of your bot) slack.profile (optional) slack.changes(optional, only show changes and failed states) + slack.only_show_failed(optional, only show failed states) slack.yaml_format(optional, format the json in yaml format) @@ -110,6 +111,7 @@ def _get_options(ret=None): 'as_user': 'as_user', 'api_key': 'api_key', 'changes': 'changes', + 'only_show_failed': 'only_show_failed', 'yaml_format': 'yaml_format', } @@ -188,6 +190,7 @@ def returner(ret): as_user = _options.get('as_user') api_key = _options.get('api_key') changes = _options.get('changes') + only_show_failed = _options.get('only_show_failed') yaml_format = _options.get('yaml_format') if not channel: @@ -206,9 +209,16 @@ def returner(ret): log.error('slack.api_key not defined in salt config') return + if only_show_failed and changes: + log.error('cannot define both slack.changes and slack.only_show_failed in salt config') + return + returns = ret.get('return') if changes is True: - returns = dict((key, value) for key, value in returns.items() if value['result'] is not True or value['changes']) + returns = {(key, value) for key, value in returns.items() if value['result'] is not True or value['changes']} + + if only_show_failed is True: + returns = {(key, value) for key, value in returns.items() if value['result'] is not True} if yaml_format is True: returns = salt.utils.yaml.safe_dump(returns)