slack_notify.py (salt-3002.1) | : | slack_notify.py (salt-3002.2) | ||
---|---|---|---|---|
# -*- coding: utf-8 -*- | ||||
""" | """ | |||
Module for sending messages to Slack | Module for sending messages to Slack | |||
.. versionadded:: 2015.5.0 | .. versionadded:: 2015.5.0 | |||
:configuration: This module can be used by either passing an api key and version | :configuration: This module can be used by either passing an api key and version | |||
directly or by specifying both in a configuration profile in the salt | directly or by specifying both in a configuration profile in the salt | |||
master/minion config. | master/minion config. | |||
For example: | For example: | |||
.. code-block:: yaml | .. code-block:: yaml | |||
slack: | slack: | |||
api_key: peWcBiMOS9HrZG15peWcBiMOS9HrZG15 | api_key: peWcBiMOS9HrZG15peWcBiMOS9HrZG15 | |||
""" | """ | |||
# Import Python libs | ||||
from __future__ import absolute_import, print_function, unicode_literals | ||||
import logging | import logging | |||
import salt.ext.six.moves.http_client | import salt.ext.six.moves.http_client | |||
# Import Salt libs | ||||
import salt.utils.json | import salt.utils.json | |||
import salt.utils.slack | import salt.utils.slack | |||
from salt.exceptions import SaltInvocationError | from salt.exceptions import SaltInvocationError | |||
from salt.ext.six.moves import range | from salt.ext.six.moves import range | |||
# Import 3rd-party libs | ||||
# pylint: disable=import-error,no-name-in-module,redefined-builtin | # pylint: disable=import-error,no-name-in-module,redefined-builtin | |||
from salt.ext.six.moves.urllib.parse import urlencode as _urlencode | from salt.ext.six.moves.urllib.parse import urlencode as _urlencode | |||
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin | from salt.ext.six.moves.urllib.parse import urljoin as _urljoin | |||
# pylint: enable=import-error,no-name-in-module | # pylint: enable=import-error,no-name-in-module | |||
log = logging.getLogger(__name__) | log = logging.getLogger(__name__) | |||
__virtualname__ = "slack" | __virtualname__ = "slack" | |||
skipping to change at line 200 | skipping to change at line 193 | |||
# channel must start with a hash or an @ (direct-message channels) | # channel must start with a hash or an @ (direct-message channels) | |||
if not channel.startswith("#") and not channel.startswith("@"): | if not channel.startswith("#") and not channel.startswith("@"): | |||
log.warning( | log.warning( | |||
"Channel name must start with a hash or @. " | "Channel name must start with a hash or @. " | |||
'Prepending a hash and using "#%s" as ' | 'Prepending a hash and using "#%s" as ' | |||
"channel name instead of %s", | "channel name instead of %s", | |||
channel, | channel, | |||
channel, | channel, | |||
) | ) | |||
channel = "#{0}".format(channel) | channel = "#{}".format(channel) | |||
if not from_name: | if not from_name: | |||
log.error("from_name is a required option.") | log.error("from_name is a required option.") | |||
if not message: | if not message: | |||
log.error("message is a required option.") | log.error("message is a required option.") | |||
if not from_name: | if not from_name: | |||
log.error("from_name is a required option.") | log.error("from_name is a required option.") | |||
skipping to change at line 245 | skipping to change at line 238 | |||
short=False, | short=False, | |||
identifier=None, | identifier=None, | |||
channel=None, | channel=None, | |||
username=None, | username=None, | |||
icon_emoji=None, | icon_emoji=None, | |||
): | ): | |||
""" | """ | |||
Send message to Slack incoming webhook. | Send message to Slack incoming webhook. | |||
:param message: The topic of message. | :param message: The topic of message. | |||
:param attachment: The message to send to the Slacke WebHook. | :param attachment: The message to send to the Slack WebHook. | |||
:param color: The color of border of left side | :param color: The color of border of left side | |||
:param short: An optional flag indicating whether the value is short | :param short: An optional flag indicating whether the value is short | |||
enough to be displayed side-by-side with other values. | enough to be displayed side-by-side with other values. | |||
:param identifier: The identifier of WebHook. | :param identifier: The identifier of WebHook. | |||
:param channel: The channel to use instead of the WebHook default. | :param channel: The channel to use instead of the WebHook default. | |||
:param username: Username to use instead of WebHook default. | :param username: Username to use instead of WebHook default. | |||
:param icon_emoji: Icon to use instead of WebHook default. | :param icon_emoji: Icon to use instead of WebHook default. | |||
:return: Boolean if message was sent successfully. | :return: Boolean if message was sent successfully. | |||
CLI Example: | CLI Example: | |||
End of changes. 6 change blocks. | ||||
9 lines changed or deleted | 2 lines changed or added |