%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/slack_notify.pyc

�
���^c@@s#dZddlmZmZmZddlZddlZddlZddl	m
Z
ddlmZ
ddlmZddlmZddlZeje�ZdZd	�Zd
�Zd�Zdd�Zdd
�Zdd�Zdd�Zddd�Zdde ddddd�Z!dS(uh
Module for sending messages to Slack

.. versionadded:: 2015.5.0

: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
    master/minion config.

    For example:

    .. code-block:: yaml

        slack:
          api_key: peWcBiMOS9HrZG15peWcBiMOS9HrZG15
i(tabsolute_importtunicode_literalstprint_functionN(tSaltInvocationError(t	urlencode(turljoin(trangeuslackcC@stS(uZ
    Return virtual name of the module.

    :return: The virtual name of the module.
    (t__virtualname__(((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt__virtual__)scC@s9tdd�ptdd�}|s5td��n|S(Nu
config.getu
slack.api_keyu
slack:api_keyuNo Slack API key found.(t__salt__R(tapi_key((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt_get_api_key2s
cC@s9tdd�ptdd�}|s5td��n|S(Nu
config.getu
slack.hooku
slack:hookuNo Slack WebHook url found(R	R(turl((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt_get_hook_id<s
cC@s4|st�}ntjjjddd|dt�S(u
    List all Slack rooms.

    :param api_key: The Slack admin api key.
    :return: The room list.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.list_rooms

        salt '*' slack.list_rooms api_key=peWcBiMOS9HrZG15peWcBiMOS9HrZG15
    tfunctionuroomsR
topts(Rtsalttutilstslacktqueryt__opts__(R
((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt
list_roomsEs
cC@s4|st�}ntjjjddd|dt�S(u
    List all Slack users.

    :param api_key: The Slack admin api key.
    :return: The user list.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.list_users

        salt '*' slack.list_users api_key=peWcBiMOS9HrZG15peWcBiMOS9HrZG15
    RuusersR
R(RRRRRR(R
((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt
list_users[s
cC@s�|st�}n|jd�r.|d}nt|�}|dr�|d}|r�x<tdt|��D]"}||d|krj||SqjWq�ntS(uW
    Find a room by name and return it.

    :param name:    The room name.
    :param api_key: The Slack admin api key.
    :return:        The room object.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.find_room name="random"

        salt '*' slack.find_room name="random" api_key=peWcBiMOS9HrZG15peWcBiMOS9HrZG15
    u#iuresumessageiuname(Rt
startswithRRtlentFalse(tnameR
trettroomstroom((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt	find_roomqs


cC@s~|st�}nt|�}|drz|d}|rzx<tdt|��D]"}||d|krN||SqNWqzntS(um
    Find a user by name and return it.

    :param name:        The user name.
    :param api_key:     The Slack admin api key.
    :return:            The user object.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.find_user name="ThomasHatch"

        salt '*' slack.find_user name="ThomasHatch" api_key=peWcBiMOS9HrZG15peWcBiMOS9HrZG15
    uresumessageiuname(RRRRR(RR
Rtuserstuser((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt	find_user�s

cC@s<|st�}n|s(tjd�n|jd�rm|jd�rmtjd||�dj|�}n|s�tjd�n|s�tjd�n|s�tjd�ni|d6|d	6|d
6}|dk	r�||d<ntjj	j
dd
d|dddidd6dt|�dt�}|dr4t
S|SdS(ub
    Send a message to a Slack channel.

    :param channel:     The channel name, either will work.
    :param message:     The message to send to the Slack channel.
    :param from_name:   Specify who the message is from.
    :param api_key:     The Slack api key, if not specified in the configuration.
    :param icon:        URL to an image to use as the icon for this message
    :return:            Boolean if message was sent successfully.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.post_message channel="Development Room" message="Build is done" from_name="Build Server"

    uchannel is a required option.u#u@uiChannel name must start with a hash or @. Prepending a hash and using "#%s" as channel name instead of %su#{0}ufrom_name is a required option.umessage is a required option.uchanneluusernameutextuicon_urlRumessageR
tmethoduPOSTtheader_dictu!application/x-www-form-urlencodeduContent-TypetdataRuresN(RtlogterrorRtwarningtformattNoneRRRRt
_urlencodeRtTrue(tchanneltmessaget	from_nameR
ticont
parameterstresult((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pytpost_message�s: 	



	
ugoodc
C@sLd}|st�}nt||�}	|s=tjd�n|r�ii|d6|d6|d6i|d6|d6gd6gd	6}
n
i|d
6}
|r�||
d<n|r�||
d<n|r�||
d
<ntitjjj|
�d6�}tjj	j
|	ddd|dt�}|ddkr&tSitd6|j
d|d�d6SdS(u-
    Send message to Slack incoming webhook.

    :param message:     The topic of message.
    :param attachment:  The message to send to the Slacke WebHook.
    :param color:       The color of border of left side
    :param short:       An optional flag indicating whether the value is short
                        enough to be displayed side-by-side with other values.
    :param identifier:  The identifier of WebHook.
    :param channel:     The channel to use instead of the WebHook default.
    :param username:    Username to use instead of WebHook default.
    :param icon_emoji:  Icon to use instead of WebHook default.
    :return:            Boolean if message was sent successfully.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.call_hook message='Hello, from SaltStack'

    u!https://hooks.slack.com/services/umessage is required optionufallbackucolorupretextuvalueushortufieldsuattachmentsutextuchanneluusernameu
icon_emojiupayloadR"uPOSTR$tstatusustatusi�uresubodyumessageN(R
t_urljoinR%R&R*RRtjsontdumpsthttpRR+Rtget(
R-t
attachmenttcolortshortt
identifierR,tusernamet
icon_emojitbase_urlRtpayloadR$R1((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt	call_hook�s@



'("t__doc__t
__future__RRRtloggingtsalt.utils.jsonRtsalt.utils.slacktsalt.exceptionsRtsalt.ext.six.moves.urllib.parseRR*RR4tsalt.ext.six.movesRtsalt.ext.six.moves.http_clientt	getLoggert__name__R%RRRR
R)RRRR!R2RRA(((s=/usr/lib/python2.7/site-packages/salt/modules/slack_notify.pyt<module>s6			
		" A

Zerion Mini Shell 1.0