{"action":"created","comment":{"url":"https://api.github.com/repos/ansible/ansible/pulls/comments/100786508","pull_request_review_id":21500782,"id":100786508,"diff_hunk":"@@ -0,0 +1,160 @@\n+#!/usr/bin/python\n+# -*- coding: utf-8 -*-\n+\n+# Benjamin Jolivot <bjolivot@gmail.com>\n+# Inspired by slack module :\n+#    # (c) 2017, Steve Pletcher <steve@steve-pletcher.com>\n+#    # (c) 2016, René Moser <mail@renemoser.net>\n+#    # (c) 2015, Stefan Berggren <nsg@nsg.cc>\n+#    # (c) 2014, Ramon de la Fuente <ramon@delafuente.nl>)\n+\n+# This file is part of Ansible\n+#\n+# Ansible is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# Ansible is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n+\n+\n+ANSIBLE_METADATA = {'status': ['preview'],\n+                    'supported_by': 'community',\n+                    'version': '1.0'}\n+\n+DOCUMENTATION = \"\"\"\n+module: mattermost\n+short_description: Send Mattermost notifications\n+description:\n+    - The M(mattermost) module sends notifications to U(http://your.mattermost.url) via the Incoming WebHook integration\n+version_added: \"2.3\"\n+author: \"Benjamin Jolivot (@bjolivot)\"\n+options:\n+  url:\n+    description:\n+      - Mattermost url (i.e. http://mattermost.yourcompany.com)\n+    required: true\n+  api_key:\n+    description:\n+      - Mattermost webhook api key. Log into your mattermost site, go to\n+        Menu -> Integration -> Incomming Webhook -> Add Incomming Webhook\n+        This will give you full URL. api_key is the last part.\n+        http://mattermost.example.com/hooks/C(API_KEY)\n+    required: true\n+  text:\n+    description:\n+      - Text to send. Note that the module does not handle escaping characters.\n+    required: true\n+  channel:\n+    description:\n+      - Channel to send the message to. If absent, the message goes to the channel selected for the I(api_key).\n+    required: false\n+    default: None\n+  username:\n+    description:\n+      - This is the sender of the message (Username Override need to be enabled by mattermost admin, see mattermost doc, default C(Ansible)).\n+    required: false\n+    default: \"Ansible\"\n+  icon_url:\n+    description:\n+      - Url for the message sender's icon (default C(https://www.ansible.com/favicon.ico))\n+    required: false\n+  validate_certs:\n+    description:\n+      - If C(no), SSL certificates will not be validated. This should only be used\n+        on personally controlled sites using self-signed certificates.\n+    required: false\n+    default: 'yes'\n+    choices:\n+      - 'yes'\n+      - 'no'\n+\"\"\"\n+\n+EXAMPLES = \"\"\"\n+- name: Send notification message via Mattermost\n+  mattermost:\n+    url: http://mattermost.example.com\n+    api_key: my_api_key\n+    text: '{{ inventory_hostname }} completed'\n+\n+- name: Send notification message via Slack all options\n+  mattermost:\n+    url: http://mattermost.example.com\n+    api_key: my_api_key\n+    text: '{{ inventory_hostname }} completed'\n+    channel: notifications\n+    username: 'Ansible on {{ inventory_hostname }}'\n+    icon_url: http://www.example.com/some-image-file.png\n+\"\"\"\n+\n+RETURN = '''\n+payload:\n+    description: Mattermost payload\n+    returned: success\n+    type: string\n+webhook_url:\n+    description: URL the webhook is sent to\n+    returned: success\n+    type: string\n+'''\n+\n+\n+def main():\n+    module = AnsibleModule(\n+        supports_check_mode=True,\n+        argument_spec = dict(\n+            url         = dict(type='str', required=True),\n+            api_key     = dict(type='str', required=True,  no_log=True),\n+            text        = dict(type='str', required=True),\n+            channel     = dict(type='str', required=False,  default=None),\n+            username    = dict(type='str', default='Ansible'),\n+            icon_url    = dict(type='str', default='https://www.ansible.com/favicon.ico'),\n+            validate_certs = dict(default='yes', type='bool'),\n+        )\n+    )\n+    #init return dict\n+    retkwargs = dict(changed=False, msg=\"OK\")\n+\n+    #define webhook\n+    webhook_url = \"{0}/hooks/{1}\".format(module.params['url'],module.params['api_key'])\n+    retkwargs['webhook_url'] = webhook_url\n+\n+    #define payload\n+    payload = { }\n+    for param in ['text', 'channel', 'username', 'icon_url']:\n+        if module.params[param] is not None:\n+            payload[param] = module.params[param]\n+\n+    payload=module.jsonify(payload)\n+    retkwargs['payload'] = payload\n+\n+    #http headers\n+    headers = {\n+        'Content-Type': 'application/json',\n+        'Accept': 'application/json',\n+    }\n+\n+    #send request\n+    response, info = fetch_url(module=module, url=webhook_url, headers=headers, method='POST', data=payload)\n+\n+\n+    if info['status'] != 200:\n+        #some problem\n+        retkwargs['msg'] = \"Failed to send mattermost message, the error was: {0}\".format(info['msg'])\n+        module.fail_json(**retkwargs)\n+\n+    #Looks good\n+    module.exit_json(**retkwargs)\n+\n+\n+from ansible.module_utils.basic import *\n+from ansible.module_utils.urls import *","path":"lib/ansible/modules/notification/mattermost.py","position":null,"original_position":157,"commit_id":"6b82eb63c72a8a19ef9d7c7e8a49188357ff4179","original_commit_id":"833c9227bc67e94083a266783f1dacb50761c9c9","user":{"login":"bjolivot","id":7072700,"avatar_url":"https://avatars.githubusercontent.com/u/7072700?v=3","gravatar_id":"","url":"https://api.github.com/users/bjolivot","html_url":"https://github.com/bjolivot","followers_url":"https://api.github.com/users/bjolivot/followers","following_url":"https://api.github.com/users/bjolivot/following{/other_user}","gists_url":"https://api.github.com/users/bjolivot/gists{/gist_id}","starred_url":"https://api.github.com/users/bjolivot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjolivot/subscriptions","organizations_url":"https://api.github.com/users/bjolivot/orgs","repos_url":"https://api.github.com/users/bjolivot/repos","events_url":"https://api.github.com/users/bjolivot/events{/privacy}","received_events_url":"https://api.github.com/users/bjolivot/received_events","type":"User","site_admin":false},"body":"Done\r\nnot sure if top of the module if before or after documentation\r\nMoved before documentation.","created_at":"2017-02-13T12:52:40Z","updated_at":"2017-02-13T12:52:40Z","html_url":"https://github.com/ansible/ansible/pull/21247#discussion_r100786508","pull_request_url":"https://api.github.com/repos/ansible/ansible/pulls/21247","_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible/pulls/comments/100786508"},"html":{"href":"https://github.com/ansible/ansible/pull/21247#discussion_r100786508"},"pull_request":{"href":"https://api.github.com/repos/ansible/ansible/pulls/21247"}}},"pull_request":{"url":"https://api.github.com/repos/ansible/ansible/pulls/21247","id":105637309,"html_url":"https://github.com/ansible/ansible/pull/21247","diff_url":"https://github.com/ansible/ansible/pull/21247.diff","patch_url":"https://github.com/ansible/ansible/pull/21247.patch","issue_url":"https://api.github.com/repos/ansible/ansible/issues/21247","number":21247,"state":"open","locked":false,"title":"Ansible Mattermost Module","user":{"login":"bjolivot","id":7072700,"avatar_url":"https://avatars.githubusercontent.com/u/7072700?v=3","gravatar_id":"","url":"https://api.github.com/users/bjolivot","html_url":"https://github.com/bjolivot","followers_url":"https://api.github.com/users/bjolivot/followers","following_url":"https://api.github.com/users/bjolivot/following{/other_user}","gists_url":"https://api.github.com/users/bjolivot/gists{/gist_id}","starred_url":"https://api.github.com/users/bjolivot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjolivot/subscriptions","organizations_url":"https://api.github.com/users/bjolivot/orgs","repos_url":"https://api.github.com/users/bjolivot/repos","events_url":"https://api.github.com/users/bjolivot/events{/privacy}","received_events_url":"https://api.github.com/users/bjolivot/received_events","type":"User","site_admin":false},"body":"##### ISSUE TYPE\r\n<!--- Pick one below and delete the rest: -->\r\n - New Module Pull Request\r\n\r\n##### COMPONENT NAME\r\n<!--- mattermost -->\r\nmattermost\r\n\r\n##### ANSIBLE VERSION\r\n<!--- Paste verbatim output from “ansible --version” between quotes below -->\r\n```\r\nansible 2.3.0 (mattermost 1a0011908c) last updated 2017/02/10 16:03:08 (GMT +200)\r\n  config file = /home/ben/.ansible.cfg\r\n  configured module search path = Default w/o overrides\r\n```\r\n\r\n##### SUMMARY\r\n<!--- Describe the change, including rationale and design decisions -->\r\n\r\nNew module for sending notifications to Mattermost.\r\n\r\n<!---\r\nIf you are fixing an existing issue, please include \"Fixes #nnn\" in your\r\ncommit message and your description; but you should still explain what\r\nthe change does.\r\n-->\r\n\r\n","created_at":"2017-02-10T14:26:45Z","updated_at":"2017-02-13T12:52:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"05d5214128c1cb370119e1ce6cfa571b6be7caab","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ansible/ansible/pulls/21247/commits","review_comments_url":"https://api.github.com/repos/ansible/ansible/pulls/21247/comments","review_comment_url":"https://api.github.com/repos/ansible/ansible/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/21247/comments","statuses_url":"https://api.github.com/repos/ansible/ansible/statuses/6b82eb63c72a8a19ef9d7c7e8a49188357ff4179","head":{"label":"bjolivot:mattermost","ref":"mattermost","sha":"6b82eb63c72a8a19ef9d7c7e8a49188357ff4179","user":{"login":"bjolivot","id":7072700,"avatar_url":"https://avatars.githubusercontent.com/u/7072700?v=3","gravatar_id":"","url":"https://api.github.com/users/bjolivot","html_url":"https://github.com/bjolivot","followers_url":"https://api.github.com/users/bjolivot/followers","following_url":"https://api.github.com/users/bjolivot/following{/other_user}","gists_url":"https://api.github.com/users/bjolivot/gists{/gist_id}","starred_url":"https://api.github.com/users/bjolivot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjolivot/subscriptions","organizations_url":"https://api.github.com/users/bjolivot/orgs","repos_url":"https://api.github.com/users/bjolivot/repos","events_url":"https://api.github.com/users/bjolivot/events{/privacy}","received_events_url":"https://api.github.com/users/bjolivot/received_events","type":"User","site_admin":false},"repo":{"id":81566872,"name":"ansible","full_name":"bjolivot/ansible","owner":{"login":"bjolivot","id":7072700,"avatar_url":"https://avatars.githubusercontent.com/u/7072700?v=3","gravatar_id":"","url":"https://api.github.com/users/bjolivot","html_url":"https://github.com/bjolivot","followers_url":"https://api.github.com/users/bjolivot/followers","following_url":"https://api.github.com/users/bjolivot/following{/other_user}","gists_url":"https://api.github.com/users/bjolivot/gists{/gist_id}","starred_url":"https://api.github.com/users/bjolivot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjolivot/subscriptions","organizations_url":"https://api.github.com/users/bjolivot/orgs","repos_url":"https://api.github.com/users/bjolivot/repos","events_url":"https://api.github.com/users/bjolivot/events{/privacy}","received_events_url":"https://api.github.com/users/bjolivot/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bjolivot/ansible","description":"Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.","fork":true,"url":"https://api.github.com/repos/bjolivot/ansible","forks_url":"https://api.github.com/repos/bjolivot/ansible/forks","keys_url":"https://api.github.com/repos/bjolivot/ansible/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bjolivot/ansible/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bjolivot/ansible/teams","hooks_url":"https://api.github.com/repos/bjolivot/ansible/hooks","issue_events_url":"https://api.github.com/repos/bjolivot/ansible/issues/events{/number}","events_url":"https://api.github.com/repos/bjolivot/ansible/events","assignees_url":"https://api.github.com/repos/bjolivot/ansible/assignees{/user}","branches_url":"https://api.github.com/repos/bjolivot/ansible/branches{/branch}","tags_url":"https://api.github.com/repos/bjolivot/ansible/tags","blobs_url":"https://api.github.com/repos/bjolivot/ansible/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bjolivot/ansible/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bjolivot/ansible/git/refs{/sha}","trees_url":"https://api.github.com/repos/bjolivot/ansible/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bjolivot/ansible/statuses/{sha}","languages_url":"https://api.github.com/repos/bjolivot/ansible/languages","stargazers_url":"https://api.github.com/repos/bjolivot/ansible/stargazers","contributors_url":"https://api.github.com/repos/bjolivot/ansible/contributors","subscribers_url":"https://api.github.com/repos/bjolivot/ansible/subscribers","subscription_url":"https://api.github.com/repos/bjolivot/ansible/subscription","commits_url":"https://api.github.com/repos/bjolivot/ansible/commits{/sha}","git_commits_url":"https://api.github.com/repos/bjolivot/ansible/git/commits{/sha}","comments_url":"https://api.github.com/repos/bjolivot/ansible/comments{/number}","issue_comment_url":"https://api.github.com/repos/bjolivot/ansible/issues/comments{/number}","contents_url":"https://api.github.com/repos/bjolivot/ansible/contents/{+path}","compare_url":"https://api.github.com/repos/bjolivot/ansible/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bjolivot/ansible/merges","archive_url":"https://api.github.com/repos/bjolivot/ansible/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bjolivot/ansible/downloads","issues_url":"https://api.github.com/repos/bjolivot/ansible/issues{/number}","pulls_url":"https://api.github.com/repos/bjolivot/ansible/pulls{/number}","milestones_url":"https://api.github.com/repos/bjolivot/ansible/milestones{/number}","notifications_url":"https://api.github.com/repos/bjolivot/ansible/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bjolivot/ansible/labels{/name}","releases_url":"https://api.github.com/repos/bjolivot/ansible/releases{/id}","deployments_url":"https://api.github.com/repos/bjolivot/ansible/deployments","created_at":"2017-02-10T13:17:03Z","updated_at":"2017-02-10T13:17:19Z","pushed_at":"2017-02-13T12:51:59Z","git_url":"git://github.com/bjolivot/ansible.git","ssh_url":"git@github.com:bjolivot/ansible.git","clone_url":"https://github.com/bjolivot/ansible.git","svn_url":"https://github.com/bjolivot/ansible","homepage":"http://ansible.com/","size":65714,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"ansible:devel","ref":"devel","sha":"e9b009510fd8fa91e01e22b2d701f6e894f12fe9","user":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"repo":{"id":3638964,"name":"ansible","full_name":"ansible/ansible","owner":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ansible/ansible","description":"Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.","fork":false,"url":"https://api.github.com/repos/ansible/ansible","forks_url":"https://api.github.com/repos/ansible/ansible/forks","keys_url":"https://api.github.com/repos/ansible/ansible/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ansible/ansible/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ansible/ansible/teams","hooks_url":"https://api.github.com/repos/ansible/ansible/hooks","issue_events_url":"https://api.github.com/repos/ansible/ansible/issues/events{/number}","events_url":"https://api.github.com/repos/ansible/ansible/events","assignees_url":"https://api.github.com/repos/ansible/ansible/assignees{/user}","branches_url":"https://api.github.com/repos/ansible/ansible/branches{/branch}","tags_url":"https://api.github.com/repos/ansible/ansible/tags","blobs_url":"https://api.github.com/repos/ansible/ansible/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ansible/ansible/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ansible/ansible/git/refs{/sha}","trees_url":"https://api.github.com/repos/ansible/ansible/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ansible/ansible/statuses/{sha}","languages_url":"https://api.github.com/repos/ansible/ansible/languages","stargazers_url":"https://api.github.com/repos/ansible/ansible/stargazers","contributors_url":"https://api.github.com/repos/ansible/ansible/contributors","subscribers_url":"https://api.github.com/repos/ansible/ansible/subscribers","subscription_url":"https://api.github.com/repos/ansible/ansible/subscription","commits_url":"https://api.github.com/repos/ansible/ansible/commits{/sha}","git_commits_url":"https://api.github.com/repos/ansible/ansible/git/commits{/sha}","comments_url":"https://api.github.com/repos/ansible/ansible/comments{/number}","issue_comment_url":"https://api.github.com/repos/ansible/ansible/issues/comments{/number}","contents_url":"https://api.github.com/repos/ansible/ansible/contents/{+path}","compare_url":"https://api.github.com/repos/ansible/ansible/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ansible/ansible/merges","archive_url":"https://api.github.com/repos/ansible/ansible/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ansible/ansible/downloads","issues_url":"https://api.github.com/repos/ansible/ansible/issues{/number}","pulls_url":"https://api.github.com/repos/ansible/ansible/pulls{/number}","milestones_url":"https://api.github.com/repos/ansible/ansible/milestones{/number}","notifications_url":"https://api.github.com/repos/ansible/ansible/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ansible/ansible/labels{/name}","releases_url":"https://api.github.com/repos/ansible/ansible/releases{/id}","deployments_url":"https://api.github.com/repos/ansible/ansible/deployments","created_at":"2012-03-06T14:58:02Z","updated_at":"2017-02-13T12:44:29Z","pushed_at":"2017-02-13T12:52:03Z","git_url":"git://github.com/ansible/ansible.git","ssh_url":"git@github.com:ansible/ansible.git","clone_url":"https://github.com/ansible/ansible.git","svn_url":"https://github.com/ansible/ansible","homepage":"http://ansible.com/","size":65782,"stargazers_count":21366,"watchers_count":21366,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6822,"mirror_url":null,"open_issues_count":2404,"forks":6822,"open_issues":2404,"watchers":21366,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible/pulls/21247"},"html":{"href":"https://github.com/ansible/ansible/pull/21247"},"issue":{"href":"https://api.github.com/repos/ansible/ansible/issues/21247"},"comments":{"href":"https://api.github.com/repos/ansible/ansible/issues/21247/comments"},"review_comments":{"href":"https://api.github.com/repos/ansible/ansible/pulls/21247/comments"},"review_comment":{"href":"https://api.github.com/repos/ansible/ansible/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ansible/ansible/pulls/21247/commits"},"statuses":{"href":"https://api.github.com/repos/ansible/ansible/statuses/6b82eb63c72a8a19ef9d7c7e8a49188357ff4179"}}}}
{"actor":{"display_login":"bjolivot"}}