# Zabbix & Better Stack integration

This integration allows you to create Uptime incidents from Zabbix automatically.

## Connecting Zabbix and Uptime

1. Go to [Integrations](https://uptime.betterstack.com/team/0/integrations/ ";_blank") and click the **Importing data** tab.
2. Find the Zabbix card and click **Add**.
3. Name your Zabbix integration (e.g., `Backend service`) and click **Save changes**.
4. Copy the script from the integration settings. You will need it in a moment.

### In Zabbix

#### Create a media type

1. Go to your Zabbix dashboard.
2. In the upper right corner, click **Create media type**.
3. For **Name**, enter `Uptime`.
4. For **Type**, select **Webhook**.
5. Remove all parameters except **Message: {ALERT.MESSAGE}**.
6. Paste the script from your Better Stack integration settings into the **Script** field.

    ```ts
    [label Zabbix Media type Script]
    // Make a POST request to the Uptime Zabbix Webhook
    // https://uptime.betterstack.com/api/v2/zabbix/webhook/sHvzVfzMofxz6eD4XdZEEqdF

    var request = new CurlHttpRequest();
    request.AddHeader('Content-Type: application/json');

    var response = 
request.Post('https://uptime.betterstack.com/api/v2/zabbix/webhook/sHvzVfzMofxz6eD4XdZEEqdF', value);
    if (request.Status() != 200) {
      throw 'Response code: ' + request.Status();
    }

    return response;
    ```
1. Ensure **Enabled** is checked and click **Add**.

#### Create a user

1. Go to **Administration** > **Users** and click **Create user**.
2. For **Alias**, enter `Uptime user`.
3. Add this user to a group and enter any password.
4. Go to the **Permissions** tab and grant the user read permissions for the necessary hosts.
5. Go to the **Media** tab and add **Uptime** as a new media type.
6. In the **Send to** field, enter any value (it is required but not used).
7. Select the severities you want to report to Uptime.
8. Click **Add** to save the media, then **Add** again to save the user.

#### Create an action

1. Go to **Configuration** > **Actions** and click **Create action**.
2. For **Name**, enter `Uptime Action`.
3. (Optional) Add conditions to restrict the action.
4. Go to the **Operations** tab.
5. Set **Default operation step duration** to `1m`.
6. Under **Operations**, click **Add**.
7. In **Send to Users**, select **Uptime user**.
8. In **Send only to**, select **Uptime**.
9. Check **Custom message** and paste the operational message from your Better Stack integration settings into the **Message** field.
10. Click **Add** to save the operation.
11. Repeat the steps above for **Recovery operations** and **Update operations**, using their respective messages.
12. After configuring all operations, click **Add** to save the action.

You're done. Now, when Zabbix triggers an alert, an incident will be created in Uptime.
