From c73078d1fbc524aa2773560e42b9e73d9302b3a7 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Sun, 21 Oct 2018 12:13:25 +0300 Subject: [PATCH] fix event ack for Zabbix 4.x, #629 --- src/datasource-zabbix/constants.js | 11 ++++++++--- .../connectors/zabbix_api/zabbixAPIConnector.js | 11 +++++++---- src/datasource-zabbix/zabbix/zabbix.js | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/datasource-zabbix/constants.js b/src/datasource-zabbix/constants.js index b52a6866c..3c8de5114 100644 --- a/src/datasource-zabbix/constants.js +++ b/src/datasource-zabbix/constants.js @@ -1,3 +1,7 @@ +// Data point +export const DATAPOINT_VALUE = 0; +export const DATAPOINT_TS = 1; + // Editor modes export const MODE_METRICS = 0; export const MODE_ITSERVICE = 1; @@ -17,9 +21,10 @@ export const SHOW_ALL_TRIGGERS = [0, 1]; export const SHOW_ALL_EVENTS = [0, 1]; export const SHOW_OK_EVENTS = 1; -// Data point -export const DATAPOINT_VALUE = 0; -export const DATAPOINT_TS = 1; +// Acknowledge +export const ZBX_ACK_ACTION_NONE = 0; +export const ZBX_ACK_ACTION_ACK = 2; +export const ZBX_ACK_ACTION_ADD_MESSAGE = 4; export const TRIGGER_SEVERITY = [ {val: 0, text: 'Not classified'}, diff --git a/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js b/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js index e6abf7815..343266946 100644 --- a/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js +++ b/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import * as utils from '../../../utils'; import { ZabbixAPICore } from './zabbixAPICore'; +import { ZBX_ACK_ACTION_NONE, ZBX_ACK_ACTION_ACK, ZBX_ACK_ACTION_ADD_MESSAGE } from '../../../constants'; /** * Zabbix API Wrapper. @@ -8,11 +9,12 @@ import { ZabbixAPICore } from './zabbixAPICore'; * Wraps API calls and provides high-level methods. */ export class ZabbixAPIConnector { - constructor(api_url, username, password, basicAuth, withCredentials, backendSrv) { + constructor(api_url, username, password, version, basicAuth, withCredentials, backendSrv) { this.url = api_url; this.username = username; this.password = password; - this.auth = ""; + this.auth = ''; + this.version = version; this.requestOptions = { basicAuth: basicAuth, @@ -90,10 +92,11 @@ export class ZabbixAPIConnector { //////////////////////////////// acknowledgeEvent(eventid, message) { - var params = { + const action = this.version >= 4 ? ZBX_ACK_ACTION_ACK + ZBX_ACK_ACTION_ADD_MESSAGE : ZBX_ACK_ACTION_NONE; + const params = { eventids: eventid, message: message, - action: 6 + action: action }; return this.request('event.acknowledge', params); diff --git a/src/datasource-zabbix/zabbix/zabbix.js b/src/datasource-zabbix/zabbix/zabbix.js index a1c300bdf..6badc491f 100644 --- a/src/datasource-zabbix/zabbix/zabbix.js +++ b/src/datasource-zabbix/zabbix/zabbix.js @@ -28,6 +28,7 @@ export class Zabbix { password, basicAuth, withCredentials, + zabbixVersion, cacheTTL, enableDirectDBConnection, dbConnectionDatasourceId, @@ -43,7 +44,7 @@ export class Zabbix { }; this.cachingProxy = new CachingProxy(cacheOptions); - this.zabbixAPI = new ZabbixAPIConnector(url, username, password, basicAuth, withCredentials, backendSrv); + this.zabbixAPI = new ZabbixAPIConnector(url, username, password, zabbixVersion, basicAuth, withCredentials, backendSrv); if (enableDirectDBConnection) { let dbConnectorOptions = {