> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aciona.me/llms.txt
> Use this file to discover all available pages before exploring further.

# Zabbix

> Connect Zabbix to aciona.me with a custom webhook media type.

## Overview

Zabbix has no standardized webhook format. The integration uses a **webhook media type** that builds aciona.me's canonical payload from the event macros.

|                     |                                        |
| ------------------- | -------------------------------------- |
| **Source type**     | `Zabbix`                               |
| **Mechanism**       | Webhook media type + action            |
| **Correlation**     | `triggerId` (`{EVENT.TRIGGERID}`)      |
| **Auto-resolution** | ✅ (action on PROBLEM **and** RECOVERY) |

## Prerequisites

* Zabbix with admin permission to create media types and actions.
* A service created in aciona.me and linked to a team with an active schedule.

## 1. Create the alert source in aciona.me

Under **Alert sources**, create a source of type **Zabbix**. Copy the URL and the token.

## 2. Create the media type

Under **Administration → Media types → Create media type**:

* **Type:** `Webhook`
* **Parameters:**

| Name           | Value                                                |
| -------------- | ---------------------------------------------------- |
| `aciona_url`   | `https://ingress.aciona.me/webhooks/<alertSourceId>` |
| `aciona_token` | `<sourceToken>`                                      |
| `event_id`     | `{EVENT.ID}`                                         |
| `trigger_id`   | `{EVENT.TRIGGERID}`                                  |
| `event_name`   | `{EVENT.NAME}`                                       |
| `severity`     | `{EVENT.SEVERITY}`                                   |
| `event_value`  | `{EVENT.VALUE}`                                      |
| `event_status` | `{EVENT.STATUS}`                                     |
| `opdata`       | `{EVENT.OPDATA}`                                     |
| `event_age`    | `{EVENT.AGE}`                                        |
| `host_name`    | `{HOST.NAME}`                                        |
| `host_ip`      | `{HOST.IP}`                                          |
| `host_tech`    | `{HOST.HOST}`                                        |

<Accordion title="Media type script" icon="code">
  ```javascript theme={null}
  function str(v) {
    return v === null || v === undefined ? '' : String(v);
  }
  function num(v) {
    var n = Number(v);
    return isFinite(n) ? n : 0;
  }

  var params = JSON.parse(value);

  var deeplink = '';
  if (str(params.event_id)) {
    deeplink =
      'https://zabbix.example.com/zabbix.php?action=problem.view&eventid=' +
      str(params.event_id);
  }

  var payload = {
    eventId: str(params.event_id),
    triggerId: str(params.trigger_id),
    name: str(params.event_name),
    severity: num(params.severity),
    value: num(params.event_value),
    status: str(params.event_status),
    opdata: str(params.opdata),
    age: str(params.event_age),
    host: str(params.host_name),
    hostIp: str(params.host_ip),
    hostTechnical: str(params.host_tech),
    url: deeplink,
  };

  var req = new HttpRequest();
  req.addHeader('Content-Type: application/json');
  req.addHeader('X-Aciona-Token: ' + params.aciona_token);

  Zabbix.log(4, '[aciona.me] sending triggerId=' + payload.triggerId);
  var response = req.post(params.aciona_url, JSON.stringify(payload));
  var status = req.getStatus();

  if (status < 200 || status >= 300) {
    Zabbix.log(3, '[aciona.me] failed: ' + status + ' ' + response);
    throw 'aciona.me HTTP ' + status;
  }

  return 'OK';
  ```

  Adjust the `deeplink` domain to your Zabbix. Validate the script in a test environment before applying it in production.
</Accordion>

## 3. Create the action

Under **Configuration → Actions → Trigger actions**, create an action whose operation sends the notification through the aciona.me media type.

<Warning>
  The action must fire on **PROBLEM and RECOVERY**. Zabbix already does this by default — just confirm there is no condition filtering it to `PROBLEM` only. Without the recovery event, incidents never close on their own.
</Warning>

## 4. Test

Force a trigger to fire (or use a test trigger) and confirm the incident in the dashboard. Then let the trigger return to normal and confirm the automatic resolution.

## How fields are translated

### State

| Condition                               | Effect                             |
| --------------------------------------- | ---------------------------------- |
| `value = 1`                             | Creates or aggregates an incident  |
| `value = 0`                             | Resolves automatically             |
| No `value`, `status = PROBLEM`          | Creates or aggregates an incident  |
| No `value`, `status = RESOLVED` or `OK` | Resolves automatically             |
| No `value` and no `status`              | Creates an incident (safe default) |

`value` takes precedence over `status`.

### Severity

| Zabbix priority    | Severity   |
| ------------------ | ---------- |
| 5 — Disaster       | `critical` |
| 4 — High           | `high`     |
| 3 — Average        | `warning`  |
| 2 — Warning        | `warning`  |
| 1 — Information    | `info`     |
| 0 — Not classified | `info`     |

### Service

The service hint comes from `{HOST.NAME}`. Either create services in aciona.me matching your hosts' visible names, or set a default service on the source.

## Required fields

`triggerId` and `name` are required. Without them the request is rejected with `400`.

## Troubleshooting

<AccordionGroup>
  <Accordion title="The incident opens but never closes" icon="triangle-alert">
    The action is filtered to `PROBLEM` only. Remove the condition so it also fires on `RECOVERY`.
  </Accordion>

  <Accordion title="400 response" icon="circle-x">
    `trigger_id` or `event_name` are missing from the media type parameters. Check the configured macros.
  </Accordion>

  <Accordion title="Nothing arrives" icon="unplug">
    Check the Zabbix server logs (the script logs at levels 3 and 4). Confirm the server has outbound HTTPS to `ingress.aciona.me`.
  </Accordion>
</AccordionGroup>
