Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto send an outgoing webhook on incident archive #17310

Closed
mattermod opened this issue Mar 31, 2021 · 8 comments
Closed

Auto send an outgoing webhook on incident archive #17310

mattermod opened this issue Mar 31, 2021 · 8 comments
Assignees
Labels
Area/Integrations A mattermost integration (plugin, integration, etc) Difficulty/2:Medium Medium ticket Help Wanted Community help wanted Tech/Go Server Tech/ReactJS Web app Tech/TypeScript

Comments

@mattermod
Copy link
Contributor

mattermod commented Mar 31, 2021

This is a ticket for the Incident Collaboration plugin.

Add a new setting to the automation tab in the backstage to configure a new outgoing webhook, and send the outgoing webhook when the incident status is updated to Archived.

This should be fairly similar to the work done in mattermost/mattermost-plugin-playbooks#503, except the webhook is sent inside the UpdateStatus function, when the new status is successfully updated to Archived.

Backend work

  1. Add a new database migration that adds the following columns:
    1. On the IR_Playbook table, add:
    1. a text column named WebhookOnArchiveURL
    2. a boolean column named WebhookOnArchiveEnabled.
      1. On the IR_Incident table, add:
    3. a text column named WebhookOnArchiveURL.
  2. For each new column, add the corresponding fields to the server’s Playbook and Incident types. This will break some of the tests, so make sure to run make test and update the ones that are failing.
  3. Update the select queries in each of the Playbook and Incident SQL stores so the new columns are retrieved by default.
  4. In the API’s createIncident function, copy the WebhookOnArchiveURL field from the playbook to the incident, only if the playbook’s WebhookOnArchiveEnabled is true.
  5. In the API’s createPlaybook and updatePlaybook functions, make sure that the string passed in WebhookOnCreationURL is a valid URL, and return a http.StatusBadRequest if it is not.
  6. In the incident service’s UpdateStatus function, when the status is successfully updated to Archived, make a POST request to the webhook URL with a payload equal to the one sent with the on creation webhook. Take a look at the sendWebhookOnCreation function for inspiration on how to do it.

Frontend work

  1. Update the webapp’s Playbook type with the new fields added to the data model in the server.
  2. Add a new component WebhookOnArchive, very similar to WebhookOnCreation (check if it could be reused, maybe there is no need to write a brand new component).
  3. Update the AutomationSettings component to add a new Setting to the section “When an incident is archived” (create the section if it does not exist yet), that includes the new WebhookOnArchive component. You will need to update the props to receive the new values and functions that the WebhookOnArchive component will need.
  4. In the PlaybookEdit component, create the necessary functions to handle change and toggle of the new WebhookOnArchive component, and pass those functions and the corresponding values to the AutomationSettings component

Testing and documentation

  1. Test the webhook request with a test similar to the one done in mattermost/mattermost-plugin-playbooks@19df836, but testing when the status is updated to Archived.
  2. Make sure to document the webhook payload in the api.yaml file, similarly to the documentation done in mattermost/mattermost-plugin-playbooks@c0960b4.

If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.

New contributors please see our Developer's Guide.

JIRA: https://mattermost.atlassian.net/browse/MM-32419

@agarciamontoro agarciamontoro added Area/Integrations A mattermost integration (plugin, integration, etc) Difficulty/2:Medium Medium ticket Tech/Go Server Tech/ReactJS Web app Tech/TypeScript and removed Hacktoberfest labels Mar 31, 2021
@hakansa
Copy link

hakansa commented Apr 17, 2021

Can I work on this?

@agarciamontoro
Copy link
Member

Of course! Thank you for the interest, @hakansa! Feel free to get in touch if you need help with anything :)

@hakansa
Copy link

hakansa commented Apr 20, 2021

@agarciamontoro Thanks! I've started to updates on backend side. I have some questions;

  1. When I try to create an incident, I'm getting Incident Collaboration requires a Mattermost Cloud or Mattermost E20 License. . Is it OK?
  2. On frontend, I couldn't find where is incident automation settings Page. (in View) . I want to see page before adding the component.

@agarciamontoro
Copy link
Member

Hi @hakansa!

When I try to create an incident, I'm getting Incident Collaboration requires a Mattermost Cloud or Mattermost E20 License. . Is it OK?

That's expected, you cannot use the plugin without an E20 license. However, contributing to it is still encouraged, so you can bypass this restriction locally by enabling testing commands and developer mode: you need to go to System Console and, under Environment, click on Developer. There, you should set the following settings to true, as shown in the screenshot:

image

On frontend, I couldn't find where is incident automation settings Page. (in View) . I want to see page before adding the component.

I understand you mean the automation tab for the playbook, right? That's on the incident collaboration backstage. To access that (after you have configured the system console as described above), you need to go to the hamburger menu, and click on Incident Collaboration:

image

Then go to the Playbooks tab, create one playbook and click on the Automation tab:

image

Does this answer your questions?

@hakansa
Copy link

hakansa commented Apr 20, 2021

@agarciamontoro thanks for comprehensive answer. It answers all of my questions.

@hakansa
Copy link

hakansa commented Apr 20, 2021

Hi @agarciamontoro,
I'm trying to writing tests, but i'm a bit stucked. There is no test function for UpdateStatus function in server/incident/service_test.go . I guess I should add my test into TestUpdateStatus function, but i couldn't write TestUpdateStatus properly. How should I write test for UpdateStatus?
Thanks..

@agarciamontoro
Copy link
Member

There is no test function for UpdateStatus function in server/incident/service_test.go

You can add a new test function, no problem! It should be similar in structure to TestCreateIncident. Then, inside that function, you can add a t.Run() test similar to the one in mattermost/mattermost-plugin-playbooks@19df836. However, instead of testing that the webhook is sent when the incident is created, you'll need to do so when the status is archived. In order to do so you'll need to call the service's UpdateStatus function, passing an options struct that updates the status to Archived.
You don't even need to call CreateIncident, simply UpdateStatus. You'll need to mock the calls inside UpdateStatus function, such as the store's GetIncident function (among others); you can find an example of this mocking in these lines.

I hope this helps, but don't hesitate to ask for anything else if you still have doubts, I know it's a lot of info!

@hakansa
Copy link

hakansa commented Apr 21, 2021

@agarciamontoro very thanks for your help! I added the test function and created a PR: mattermost/mattermost-plugin-playbooks#526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Integrations A mattermost integration (plugin, integration, etc) Difficulty/2:Medium Medium ticket Help Wanted Community help wanted Tech/Go Server Tech/ReactJS Web app Tech/TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants