Bitbucket
  • 10 May 2023
  • 4 Minutes to read
  • Dark
    Light
  • PDF

Bitbucket

  • Dark
    Light
  • PDF

Article Summary

AlertOps and Bitbucket

AlertOps’ alert management system can be integrated with Bitbucket to receive and respond to (predefined status mappings for pipeline build statuses) alerts/notifications through email, SMS, push notification or phone alerts. AlertOps would ensure that the alert would reach the appropriate team by using proper workflows, escalation policies and schedules. Based on your ruleset, incidents can be automatically opened and closed, depending on whether Bitbucket reports or notifies users of a problem or a recovery (any event for that matter).


AlertOps - Inbound Integration

We can define an inbound integration in AlertOps to receive the event/alert information from the Webhook that you will define.


At a high level this is how the flow looks like, you define an API integration in the AlertOps platform by defining settings like Integration Name, Escalation rules, recipient users/groups. Once an integration is defined, a unique API URL is generated. This acts as webhook or the gateway through which events from Bitbucket reach AlertOps and thus an incident/alert is created correspondingly. The API can be defined with various settings like URL mappings, filters, escalations etc. as required.

Text, letter  Description automatically generated


Configure Inbound Integration in AlertOps

  • Navigate to Configuration àIntegrations àAdd API Integration, the Email Integration Detail page opens
  • There are numerous integration options available in AlertOps, select Bitbucket
  • Once you select the integration, you can then specify basic settings like the integration name, escalation policy, names of the recipients/groups for which the alerts must be assigned to.
  • Once you click Submit, the API Integration will be created, and you will be given a unique URL which acts as the access point and needs to be configured at the source (in this case, Bitbucket), to send events. You can find the integration you just created, and you can give advanced settings and define various configurations for the alerts to be received and processed. For example, you can define when to open and close alerts based on the response obtained from the API call, filters for the incoming JSON payload etc.

Graphical user interface, text, application  Description automatically generated

  • Make a note of the API URL, which will be used in Bitbucket, so it calls a HTTP POST request to this URL with the body in JSON format containing the trigger specific information. Alerts/Events will be recorded in the ‘Inbound Log’ section table.
  • AlertOps automatically creates an alert when the incoming payload has the “commit_status^state” with a value “FAILED”. In the ‘Advanced Settings’ tab, (based on the incoming payload), you need to map the field of interest to the ‘SourceStatus’ field. AlertOps opens an alert when this field contains the value you mapped it with.
  • As you can see in the below screenshot, AlertOps will open an alert when the ‘commit_status^state’ field from the JSON payload received (mapped to Source Status field), contains “FAILED”. Alerts will be closed when this field comes with a value “SUCCESSFUL’ or ‘INPROGRESS’. You can similarly define URL mappings as you want, owing to the flexibility provided by AlertOps’ Open API integrations. You can provide other filters and match with regex as well. You can also test the generated URL with sample data.

Graphical user interface, application  Description automatically generated

Configuration of Bitbucket for AlertOps Integration

Now that we have setup AlertOps with the Bitbucket Inbound Integration, along with a unique API URL; we can now define a webhook there to access this API and send out events to AlertOps.

  • Setting up a webhook for your project/repository is very simple. You can setup webhooks at a repository level. Go to your “Repositories”, select your repo and then in the navigation tab in the left pane select “Repository Settings”.
  • Now under “Workflow”, select “Webhooks” and then click “Add Webhook”. Give a title and under URL, paste the API URL which you got in the previous section.
  • Under “Triggers”, check “Choose from a full list of Triggers” and select the options as provided in the screenshot below and then save. You can choose any trigger as and how you want. However, you will have to verify the event payload that will be sent to AlertOps for properly mapping it to open and close alerts. More information on event payloads is given through the links in the Reference section (this integration is to send notifications for pipeline build statuses)

Graphical user interface, text, application, email  Description automatically generated

  • You have now created an integration, where any build status changes for a pipeline process would send out a notification to AlertOps for incident management. You can view the requests logs that were sent out from Bitbucket by selecting “View Requests” under actions of the webhook you created. You can view the response payload details as well.

Table  Description automatically generated

  • That’s it! You have integrated Bitbucket Pipelines with AlertOps. Notifications sent from Bitbucket can be seen in ‘Inbound Logs’/'Alerts' in AlertOps.

Alert Triggering Information: 

AlertOps will automatically create an incident when a new alert is received from Bitbucket when the commit_status^state status field contains “FAILED”.

If an alert with status “FAILED” matches an existing Open Alert, AlertOps will recognize the new alert as a duplicate and ignore the alert. The alert will be recorded in the Inbound Messages table as “Mapped Appended.”

AlertOps will automatically close the same incident when an alert with a commit_status^state status contains “SUCCESSFUL” or “INPROGRESS”.


Was this article helpful?

What's Next
ESC

Eddy, a super-smart generative AI, opening up ways to have tailored queries and responses