Zabbix

Parny | Zabbix Integration Guide

Parny supports direct integration with Zabbix alerts. Zabbix is a network and system monitoring tool that can create alarms to detect and prevent potential problems. This documentation explains how to redirect alarms created in Zabbix to a webhook using Parny.


Parny Settings


  1. Go to the Parny interface.

  2. Navigate to the "Services" section of your organization.

  3. Click on the "New Services" option in the upper right corner.

  4. Enter the relevant service name.

Service Name Usage: The service name here is independent of the structure and can be chosen according to the preferences of the organization.


  1. Select Zabbix from the list of integrations.

  2. Click "Add".

  3. After the service is created, the following screen will appear.


parny_zabbix_1_22_01_2025


  • You can now click on the token section of your service and copy your Zabbix Webhook URL.


Zabbix Configuration


  1. Add Webhook Media Type:

  • Navigate to AlertsMedia types or AdministrationMedia types on the left sidebar according to your Zabbix version.

  • Click on Create media type.

  • Configure the following:

    • Name: Parny (or any other name you prefer)

    • Type: Webhook

    • Parameters:

      • Enter the parameters list provided below.

    • Script:

      • Enter the JavaScript code provided below, ensuring it matches the requirements for Zabbix version 6.2 and later.

  • Save the changes.



parny_zabbix_4_v2



Parameters List:

  • alert_message: {ALERT.MESSAGE}

  • eventack: {EVENT.ACK.STATUS}

  • eventdate: {EVENT.DATE}

  • eventname: {ALERT.SUBJECT}

  • eventupdate: {EVENT.UPDATE.STATUS}

  • eventvalue: {EVENT.VALUE}

  • event_source: {EVENT.SOURCE}

  • hostip: {HOST.IP}

  • hostname: {HOST.NAME}

  • parnyUrl: https://zabbix.parny.io/alert/<your-parny-service-token-here>

  • severity: {EVENT.NSEVERITY}

  • triggerdesc: {TRIGGER.DESCRIPTION}

  • triggerid: {TRIGGER.ID}

  • url: {$ZABBIX.URL}



JavaScript Code for Zabbix version 6.2 and later:

try {
  var params = JSON.parse(value),
      req = new HttpRequest(),
      fields = {},
      resp = "";

  // Correspondence between the Parny and Zabbix severity level
  var severityMapping = [
    "info",    // Not classified
    "info",    // Information
    "warning", // Warning
    "warning", // Average
    "error",   // High
    "critical" // Disaster
  ];

  if (!severityMapping[params.severity]) {
    params.severity = "0";
  }

  if (params.eventname.length < 1) {
    throw 'incorrect value for variable "eventname". The value must be a non-empty string.';
  }
  if (isNaN(parseInt(params.severity)) || params.severity < 0 || params.severity > 5) {
    throw 'incorrect value for variable "severity". The value must be a number 0..5.';
  }

  req.addHeader('Content-Type: application/json');

  // Determine the event action and payload
  fields.payload = {
    summary: params.eventname,
    source: params.event_source === "1" ? "Discovery" : params.hostname + " : " + params.hostip,
    severity: severityMapping[params.severity]
  };

  fields.payload.custom_details = {
    "Alert message": params.alert_message
  };

  fields.client = "Zabbix";
  fields.client_url = params.url;

  // Set the event action based on eventvalue
  if ((params.eventvalue == 1 && params.eventupdate == 0) || params.event_source !== "0") {
    fields.event_action = "trigger";
  } else if (params.eventvalue == 1 && params.eventupdate == 1 && params.eventack == "Yes") {
    fields.event_action = "acknowledge";
  } else if (params.eventvalue == 0) {
    fields.event_action = "resolve";
  } else {
    throw "incorrect values. Update message without ack will not be sent.";
  }

  Zabbix.Log(4, "[Parny Webhook] Sending request:" + JSON.stringify(fields));
  resp = req.post(params.parnyUrl, JSON.stringify(fields));
  Zabbix.Log(4, "[Parny Webhook] Receiving response:" + resp);

  try {
    resp = JSON.parse(resp);
  } catch (error) {
    throw "incorrect response. Parny returned a non-JSON object.";
  }

  if (req.getStatus() != 200) {
    if (typeof resp === "object" && typeof resp.errors === "object" && typeof resp.errors[0] === "string") {
      throw resp.errors[0];
    } else {
      throw "Unknown error.";
    }
  }

  return "OK";
} catch (error) {
  Zabbix.Log(3, "[Parny Webhook] Notification failed: " + error);
  throw "Parny notification failed: " + error;
}



JavaScript Code for Zabbix version earlier than 6.2:

try {
  var params = JSON.parse(value),
      req = new CurlHttpRequest(),
      fields = {},
      resp = "";

  // Correspondence between the Parny and Zabbix severity level
  var severityMapping = [
    "info",    // Not classified
    "info",    // Information
    "warning", // Warning
    "warning", // Average
    "error",   // High
    "critical" // Disaster
  ];

  if (!severityMapping[params.severity]) {
    params.severity = "0";
  }

  if (params.eventname.length < 1) {
    throw 'incorrect value for variable "eventname". The value must be a non-empty string.';
  }
  if (isNaN(parseInt(params.severity)) || params.severity < 0 || params.severity > 5) {
    throw 'incorrect value for variable "severity". The value must be a number 0..5.';
  }

  req.AddHeader("Content-Type: application/json");

  // Determine the event action and payload
  fields.payload = {
    summary: params.eventname,
    source: params.event_source === "1" ? "Discovery" : params.hostname + " : " + params.hostip,
    severity: severityMapping[params.severity]
  };

  fields.payload.custom_details = {
    "Alert message": params.alert_message
  };

  fields.client = "Zabbix";
  fields.client_url = params.url;

  // Set the event action based on eventvalue
  if ((params.eventvalue == 1 && params.eventupdate == 0) || params.event_source !== "0") {
    fields.event_action = "trigger";
  } else if (params.eventvalue == 1 && params.eventupdate == 1 && params.eventack == "Yes") {
    fields.event_action = "acknowledge";
  } else if (params.eventvalue == 0) {
    fields.event_action = "resolve";
  } else {
    throw "incorrect values. Update message without ack will not be sent.";
  }

  Zabbix.Log(4, "[Parny Webhook] Sending request:" + JSON.stringify(fields));
  resp = req.Post(params.parnyUrl, JSON.stringify(fields));
  Zabbix.Log(4, "[Parny Webhook] Receiving response:" + resp);

  try {
    resp = JSON.parse(resp);
  } catch (error) {
    throw "incorrect response. Parny returned a non-JSON object.";
  }

  if (req.Status() != 200) {
    if (typeof resp === "object" && typeof resp.errors === "object" && typeof resp.errors[0] === "string") {
      throw resp.errors[0];
    } else {
      throw "Unknown error.";
    }
  }

  if (resp.status != "success") {
    throw "Unknown error.";
  }

  return "OK";
} catch (error) {
  Zabbix.Log(3, "[Parny Webhook] Notification failed: " + error);
  throw "Parny notification failed: " + error;
}



  1. Redirecting Alarms:

  • Create Action:

    • Navigate to AlertsActions or AdministrationActions according to your Zabbix version.

    • Click on Create action.

    • Enter a name in the "Action" field and select the "Enabled" option.

  • Conditions:

    • In the "Conditions" tab, specify the conditions under which the alarms will be triggered.

    • For example, if you want to receive an alert when a server goes offline, select the relevant server group by choosing the "Host group" option.

  • Operations:

    • Choose the "Webhook" option. Select the "Send message to users" option and choose the "Webhook" option.

    • Redirect the webhook to the Parny media type you previously created and make the necessary settings. Click the "Save" button to save the operation.



  1. Problem Recovery (Auto Resolve Alerts)

  • In the "Media Type" → "Message Templates" section, referring to the image below,ensure that the "Problem" and "Problem recovery" templates are the same. With this setting, the problem will be resolved on Parny automatically when the problem is resolved on Zabbix.



parny_zabbix_5



With these settings, your Zabbix alarms will be integrated into Parny, allowing you to manage them alongside your other alerts within your organization's Parny portal.

For any further questions, please contact us at: support@parny.io