Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion salt/returners/slack_returner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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',
}

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down