Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

How to configure notification to mattermost #176

Closed
okiirawan opened this issue Feb 13, 2021 · 12 comments
Closed

How to configure notification to mattermost #176

okiirawan opened this issue Feb 13, 2021 · 12 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@okiirawan
Copy link

Hi,
Can someone help me how to configure argocd-notification to mattermost?

@askreet
Copy link
Contributor

askreet commented Feb 13, 2021

I've never used their software, but it looks like you want to send a request like this, perhaps (seems a post is the message to a channel?). You'll want to base this off of the webhook service to send the appropriate request, storing your mattermost token in the argocd-notifications-secret secret, as described here.

@alexmt alexmt added the documentation Improvements or additions to documentation label Feb 14, 2021
@ryota-sakamoto
Copy link
Member

Hi @alexmt
I'll do it

@maauso
Copy link

maauso commented Feb 16, 2021

Hey!

I'm in the same problem.

I'was trying to use webhook but in this case you need to define each channel and template for each webhook that you want to use.

The better approach would be to use a Mattermost bot, with enough rights to POST the messages to any channel.
I'm following the slack configuration to do it, but I'm having this error with the trigger.

level=debug msg="Sending request: POST /chat.postMessage HTTP/1.1\r\nHost: mattermost.company.org\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nattachments=%5B%7B%22color%22%3A%22%2318be52%22%2C%22title%22%3A%22dev-app-eks%22%2C%22title_link%22%3A%22http%3A%2F%2Fdev-argocd-app-server%2Fapplications%2Fdev-app-dev-eks-cluster00%22%2C%22text%22%3A%22%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Sync+Status%22%2C%22value%22%3A%22Synced%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Repository%22%2C%22value%22%3A%22https%3A%2F%2Fgithub.com%2Fwuakitv%2Fk8s-app.git%22%2C%22short%22%3Atrue%7D%5D%2C%22blocks%22%3Anull%7D%5D&channel=test-eks-alerts%2C+Main&text=%3Awhite_check_mark%3A+Application+dev-app-dev-eks-cluster00+has+been+successfully+synced+at+2021-02-16T12%3A33%3A55Z.%0ASync+operation+details+are+available+at%3A+http%3A%2F%2Fdev-argocd-app-server%2Fapplications%2Fdev-app-dev-eks-cluster00%3Foperation%3Dtrue+.%0A&token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" service=slack
time="2021-02-16T14:13:08Z" level=debug msg="Received response: HTTP/2.0 405 Method Not Allowed\r\nContent-Length: 0\r\nDate: Tue, 16 Feb 2021 14:13:08 GMT\r\n\r\n" service=slack
level=debug msg="Received response: HTTP/2.0 405 Method Not Allowed\r\nContent-Length: 0\r\nDate: Tue, 16 Feb 2021 14:15:08 GMT\r\n\r\n" service=slack

It seems that we can integrate it with mattermost Custom-names, but I didn't find any full configuration to do it

Agree with @okiirawan, any example?

@ryota-sakamoto
Copy link
Member

ryota-sakamoto commented Feb 16, 2021

@maauso
Mattermost is compatible with Slack(message format, not API interface).
So you can use webhook to use /api/v4/posts to post channel.

@alexmt
I think two patterns that this issue resolves.

  1. supporting mattermost service
  2. add documentation

Supporting mattermost service is more convenient than to use webhook service.
What do you think?

@okiirawan
Copy link
Author

@maauso
I'm able create notification using webhook and mattermost bot account. And message & trigger template copying from slack
Here are my argocd-notifications-cm

apiVersion: v1
data:
  context: |
    argocdUrl: "https://argo.xxxx.xxx"
  service.webhook.mattermost: |
    url: https://mattermost.xxxx.xxx/api/v4/posts
    headers: #optional headers
    - name: Authorization
      value: token $slack-token
    - name: Content-Type
      value: application/json
  template.mattermost-app-deployed: |
    webhook:
      mattermost:
        method: POST
        body: |
              {
                "channel_id":"xxxxxxxxxxxxxx",
                "message":":white_check_mark: Application {{.app.metadata.name}} is now running new version of deployments manifests",
                "props":{
                  "attachments":
                    [{
                      "title": "{{ .app.metadata.name}}",
                      "title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
                      "color": "#18be52",
                      "fields": [
                                 {
                                  "title": "Sync Status",
                                  "value": "{{.app.status.sync.status}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Repository",
                                  "value": "{{.app.spec.source.repoURL}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Revision",
                                  "value": "{{.app.status.sync.revision}}",
                                  "short": true
                                   }
                                  {{range $index, $c := .app.status.conditions}}
                                  {{if not $index}},{{end}}
                                  {{if $index}},{{end}}
                                  {
                                   "title": "{{$c.type}}",
                                   "value": "{{$c.message}}",
                                   "short": true
                                    }
                                  {{end}}
                                    ]
                                   }]
                                   }}
  template.mattermost-app-health-degraded: |
    webhook:
      mattermost:
        method: POST
        body: |
              {
                "channel_id":"xxxxxxxxxxxxxx",
                "message":":exclamation: Application {{.app.metadata.name}} has degraded.\nApplication details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.",
                "props":{
                  "attachments":
                    [{
                      "title": "{{ .app.metadata.name}}",
                      "title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
                      "color": "#f4c030",
                      "fields": [
                                 {
                                  "title": "Sync Status",
                                  "value": "{{.app.status.sync.status}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Repository",
                                  "value": "{{.app.spec.source.repoURL}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Revision",
                                  "value": "{{.app.status.sync.revision}}",
                                  "short": true
                                   }
                                  {{range $index, $c := .app.status.conditions}}
                                  {{if not $index}},{{end}}
                                  {{if $index}},{{end}}
                                  {
                                   "title": "{{$c.type}}",
                                   "value": "{{$c.message}}",
                                   "short": true
                                    }
                                  {{end}}
                                    ]
                                   }]
                                   }}
  template.mattermost-app-sync-failed: |
    webhook:
      mattermost:
        method: POST
        body: |
              {
                "channel_id":"xxxxxxxxxxxxxx",
                "message":":exclamation: The sync operation of application {{.app.metadata.name}} has failed at {{.app.status.operationState.finishedAt}} with the following error: {{.app.status.operationState.message}}\nSync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true",
                "props":{
                  "attachments":
                    [{
                      "title": "{{ .app.metadata.name}}",
                      "title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
                      "color": "#E96D76",
                      "fields": [
                                 {
                                  "title": "Sync Status",
                                  "value": "{{.app.status.sync.status}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Repository",
                                  "value": "{{.app.spec.source.repoURL}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Revision",
                                  "value": "{{.app.status.sync.revision}}",
                                  "short": true
                                   }
                                  {{range $index, $c := .app.status.conditions}}
                                  {{if not $index}},{{end}}
                                  {{if $index}},{{end}}
                                  {
                                   "title": "{{$c.type}}",
                                   "value": "{{$c.message}}",
                                   "short": true
                                    }
                                  {{end}}
                                    ]
                                   }]
                                   }}
  template.mattermost-app-sync-running: |
    webhook:
      mattermost:
        method: POST
        body: |
              {
                "channel_id":"xxxxxxxxxxxxxx",
                "message":"The sync operation of application {{.app.metadata.name}} has started at {{.app.status.operationState.startedAt}}.\nSync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true",
                "props":{
                  "attachments":
                    [{
                      "title": "{{ .app.metadata.name}}",
                      "title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
                      "color": "#0DADEA",
                      "fields": [
                                 {
                                  "title": "Sync Status",
                                  "value": "{{.app.status.sync.status}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Repository",
                                  "value": "{{.app.spec.source.repoURL}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Revision",
                                  "value": "{{.app.status.sync.revision}}",
                                  "short": true
                                   }
                                  {{range $index, $c := .app.status.conditions}}
                                  {{if not $index}},{{end}}
                                  {{if $index}},{{end}}
                                  {
                                   "title": "{{$c.type}}",
                                   "value": "{{$c.message}}",
                                   "short": true
                                    }
                                  {{end}}
                                    ]
                                   }]
                                   }}
  template.mattermost-app-sync-unknown: |
    webhook:
      mattermost:
        method: POST
        body: |
              {
                "channel_id":"xxxxxxxxxxxxxx",
                "message":":exclamation: Application {{.app.metadata.name}} sync is 'Unknown'.\nApplication details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
                "props":{
                  "attachments":
                    [{
                      "title": "{{ .app.metadata.name}}",
                      "title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
                      "color": "#E96D76",
                      "fields": [
                                 {
                                  "title": "Sync Status",
                                  "value": "{{.app.status.sync.status}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Repository",
                                  "value": "{{.app.spec.source.repoURL}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Revision",
                                  "value": "{{.app.status.sync.revision}}",
                                  "short": true
                                   }
                                  {{range $index, $c := .app.status.conditions}}
                                  {{if not $index}},{{end}}
                                  {{if $index}},{{end}}
                                  {
                                   "title": "{{$c.type}}",
                                   "value": "{{$c.message}}",
                                   "short": true
                                    }
                                  {{end}}
                                    ]
                                   }]
                                   }}
  template.mattermost-app-sync-succeeded: |
    webhook:
      mattermost:
        method: POST
        body: |
              {
                "channel_id":"xxxxxxxxxxxxxx",
                "message":":white_check_mark:Application {{.app.metadata.name}} has been successfully synced at {{.app.status.operationState.finishedAt}}.\nSync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .",
                "props":{
                  "attachments":
                    [{
                      "title": "{{ .app.metadata.name}}",
                      "title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
                      "color": "#18be52",
                      "fields": [
                                 {
                                  "title": "Sync Status",
                                  "value": "{{.app.status.sync.status}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Repository",
                                  "value": "{{.app.spec.source.repoURL}}",
                                  "short": true
                                   },
                                 {
                                  "title": "Revision",
                                  "value": "{{.app.status.sync.revision}}",
                                  "short": true
                                   }
                                  {{range $index, $c := .app.status.conditions}}
                                  {{if not $index}},{{end}}
                                  {{if $index}},{{end}}
                                  {
                                   "title": "{{$c.type}}",
                                   "value": "{{$c.message}}",
                                   "short": true
                                    }
                                  {{end}}
                                    ]
                                   }]
                                   }}
  trigger.on-deployed: |
    - description: Application is synced and healthy. Triggered once per commit.
      oncePer: app.status.sync.revision
      send:
      - mattermost-app-deployed
      when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
  trigger.on-health-degraded: |
    - description: Application has degraded
      send:
      - mattermost-app-health-degraded
      when: app.status.health.status == 'Degraded'
  trigger.on-sync-failed: |
    - description: Application syncing has failed
      send:
      - mattermost-app-sync-failed
      when: app.status.operationState.phase in ['Error', 'Failed']
  trigger.on-sync-running: |
    - description: Application is being synced
      send:
      - mattermost-app-sync-running
      when: app.status.operationState.phase in ['Running']
  trigger.on-sync-status-unknown: |
    - description: Application status is 'Unknown'
      send:
      - mattermost-app-sync-status-unknown
      when: app.status.sync.status == 'Unknown'
  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded
      send:
      - mattermost-app-sync-succeeded
      when: app.status.operationState.phase in ['Succeeded']
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: argocd-notifications-cm

Hey!

I'm in the same problem.

I'was trying to use webhook but in this case you need to define each channel and template for each webhook that you want to use.

The better approach would be to use a Mattermost bot, with enough rights to POST the messages to any channel.
I'm following the slack configuration to do it, but I'm having this error with the trigger.

level=debug msg="Sending request: POST /chat.postMessage HTTP/1.1\r\nHost: mattermost.company.org\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nattachments=%5B%7B%22color%22%3A%22%2318be52%22%2C%22title%22%3A%22dev-app-eks%22%2C%22title_link%22%3A%22http%3A%2F%2Fdev-argocd-app-server%2Fapplications%2Fdev-app-dev-eks-cluster00%22%2C%22text%22%3A%22%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Sync+Status%22%2C%22value%22%3A%22Synced%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Repository%22%2C%22value%22%3A%22https%3A%2F%2Fgithub.com%2Fwuakitv%2Fk8s-app.git%22%2C%22short%22%3Atrue%7D%5D%2C%22blocks%22%3Anull%7D%5D&channel=test-eks-alerts%2C+Main&text=%3Awhite_check_mark%3A+Application+dev-app-dev-eks-cluster00+has+been+successfully+synced+at+2021-02-16T12%3A33%3A55Z.%0ASync+operation+details+are+available+at%3A+http%3A%2F%2Fdev-argocd-app-server%2Fapplications%2Fdev-app-dev-eks-cluster00%3Foperation%3Dtrue+.%0A&token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" service=slack
time="2021-02-16T14:13:08Z" level=debug msg="Received response: HTTP/2.0 405 Method Not Allowed\r\nContent-Length: 0\r\nDate: Tue, 16 Feb 2021 14:13:08 GMT\r\n\r\n" service=slack
level=debug msg="Received response: HTTP/2.0 405 Method Not Allowed\r\nContent-Length: 0\r\nDate: Tue, 16 Feb 2021 14:15:08 GMT\r\n\r\n" service=slack

It seems that we can integrate it with mattermost Custom-names, but I didn't find any full configuration to do it

Agree with @okiirawan, any example?

@okiirawan
Copy link
Author

@maauso
Mattermost is compatible with Slack(message format, not API interface).
So you can use webhook to use /api/v4/posts to post channel.

@alexmt
I think two patterns that this issue resolves.

  1. supporting mattermost service
  2. add documentation

Supporting mattermost service is more convenient than to use webhook service.
What do you think?

Yes @ryota-sakamoto is more convenient if we have mattermost service

@alexmt
Copy link
Collaborator

alexmt commented Feb 17, 2021

Thank you for clarification @ryota-sakamoto!

I incorrectly assumed that it is 100% compatible. Since message creation is the hardest part I think it makes sense to support mattermost service and re-use code that constructs the slack message.

@ryota-sakamoto
Copy link
Member

I think so too.
I'll support mattermost service after complete #99

@EdYa
Copy link

EdYa commented Mar 3, 2021

@okiirawan Thanks for your example configuration.

Unfortunately it is not working for me in the expected way. E.g. I have to rename the property "message" within the body to "text" (see https://docs.mattermost.com/developer/webhooks-incoming.html#simple-incoming-webhook). Also the attachments are not working at all. Have you configured anything specific in your mattermost server to accept the slack format?

@Hunter-Thompson
Copy link

@okiirawan Thanks for your example configuration.

Unfortunately it is not working for me in the expected way. E.g. I have to rename the property "message" within the body to "text" (see https://docs.mattermost.com/developer/webhooks-incoming.html#simple-incoming-webhook). Also the attachments are not working at all. Have you configured anything specific in your mattermost server to accept the slack format?

@EdYa, did you create an incoming webhook? Or a Bot account? I believe the example is for a bot account.

It works fine for me when I use a Bot account. Just make sure to add the bot account to your MM team, and channel.

@EdYa
Copy link

EdYa commented Mar 3, 2021

@Hunter-Thompson: I have created an incominig webhook. So then I will try it out with a bot account.

Thanks for your quick reply and help.

@ryota-sakamoto ryota-sakamoto added enhancement New feature or request and removed documentation Improvements or additions to documentation labels Mar 14, 2021
@ryota-sakamoto ryota-sakamoto self-assigned this Mar 14, 2021
@ryota-sakamoto ryota-sakamoto added this to the v1.1 milestone Mar 17, 2021
@alexmt
Copy link
Collaborator

alexmt commented Mar 19, 2021

Implemented by #212

@alexmt alexmt closed this as completed Mar 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants