refactor: move zabbix modules
This commit is contained in:
291
dist/datasource-zabbix/zabbix/connectors/sql/zabbixDBConnector.js
vendored
Normal file
291
dist/datasource-zabbix/zabbix/connectors/sql/zabbixDBConnector.js
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['lodash'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP, TREND_TO_TABLE_MAP, consolidateByFunc, consolidateByTrendColumns, ZabbixDBConnector, TEST_MYSQL_QUERY, itemid_format, TEST_POSTGRES_QUERY;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function convertGrafanaTSResponse(time_series, items, addHostName) {
|
||||
var hosts = _.uniqBy(_.flatten(_.map(items, 'hosts')), 'hostid'); //uniqBy is needed to deduplicate
|
||||
var grafanaSeries = _.map(time_series, function (series) {
|
||||
var itemid = series.name;
|
||||
var item = _.find(items, { 'itemid': itemid });
|
||||
var alias = item.name;
|
||||
if (_.keys(hosts).length > 1 && addHostName) {
|
||||
//only when actual multi hosts selected
|
||||
var host = _.find(hosts, { 'hostid': item.hostid });
|
||||
alias = host.name + ": " + alias;
|
||||
}
|
||||
// zabbixCachingProxy deduplicates requests and returns one time series for equal queries.
|
||||
// Clone is needed to prevent changing of series object shared between all targets.
|
||||
var datapoints = _.cloneDeep(series.points);
|
||||
return {
|
||||
target: alias,
|
||||
datapoints: datapoints
|
||||
};
|
||||
});
|
||||
|
||||
return _.sortBy(grafanaSeries, 'target');
|
||||
}
|
||||
|
||||
function compactSQLQuery(query) {
|
||||
return query.replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
function buildSQLHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
||||
var dialect = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'mysql';
|
||||
|
||||
if (dialect === 'postgres') {
|
||||
return buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction);
|
||||
} else {
|
||||
return buildMysqlHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction);
|
||||
}
|
||||
}
|
||||
|
||||
function buildSQLTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
||||
var dialect = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'mysql';
|
||||
|
||||
if (dialect === 'postgres') {
|
||||
return buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn);
|
||||
} else {
|
||||
return buildMysqlTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn);
|
||||
}
|
||||
}
|
||||
|
||||
///////////
|
||||
// MySQL //
|
||||
///////////
|
||||
|
||||
function buildMysqlHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
||||
var time_expression = 'clock DIV ' + intervalSec + ' * ' + intervalSec;
|
||||
var query = '\n SELECT itemid AS metric, ' + time_expression + ' AS time_sec, ' + aggFunction + '(value) AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY ' + time_expression + ', metric\n ORDER BY time_sec ASC\n ';
|
||||
return query;
|
||||
}
|
||||
|
||||
function buildMysqlTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
||||
var time_expression = 'clock DIV ' + intervalSec + ' * ' + intervalSec;
|
||||
var query = '\n SELECT itemid AS metric, ' + time_expression + ' AS time_sec, ' + aggFunction + '(' + valueColumn + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY ' + time_expression + ', metric\n ORDER BY time_sec ASC\n ';
|
||||
return query;
|
||||
}
|
||||
|
||||
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
|
||||
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
||||
var query = '\n SELECT to_char(itemid, \'' + itemid_format + '\') AS metric, ' + time_expression + ' AS time, ' + aggFunction + '(value) AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY 1, 2\n ORDER BY time ASC\n ';
|
||||
return query;
|
||||
}
|
||||
|
||||
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
|
||||
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
|
||||
var query = '\n SELECT to_char(itemid, \'' + itemid_format + '\') AS metric, ' + time_expression + ' AS time, ' + aggFunction + '(' + valueColumn + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY 1, 2\n ORDER BY time ASC\n ';
|
||||
return query;
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}],
|
||||
execute: function () {
|
||||
_createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
DEFAULT_QUERY_LIMIT = 10000;
|
||||
HISTORY_TO_TABLE_MAP = {
|
||||
'0': 'history',
|
||||
'1': 'history_str',
|
||||
'2': 'history_log',
|
||||
'3': 'history_uint',
|
||||
'4': 'history_text'
|
||||
};
|
||||
TREND_TO_TABLE_MAP = {
|
||||
'0': 'trends',
|
||||
'3': 'trends_uint'
|
||||
};
|
||||
consolidateByFunc = {
|
||||
'avg': 'AVG',
|
||||
'min': 'MIN',
|
||||
'max': 'MAX',
|
||||
'sum': 'SUM',
|
||||
'count': 'COUNT'
|
||||
};
|
||||
consolidateByTrendColumns = {
|
||||
'avg': 'value_avg',
|
||||
'min': 'value_min',
|
||||
'max': 'value_max'
|
||||
};
|
||||
|
||||
_export('ZabbixDBConnector', ZabbixDBConnector = function () {
|
||||
function ZabbixDBConnector(sqlDataSourceId, options, backendSrv, datasourceSrv) {
|
||||
_classCallCheck(this, ZabbixDBConnector);
|
||||
|
||||
this.backendSrv = backendSrv;
|
||||
this.datasourceSrv = datasourceSrv;
|
||||
|
||||
var limit = options.limit;
|
||||
this.sqlDataSourceId = sqlDataSourceId;
|
||||
this.limit = limit || DEFAULT_QUERY_LIMIT;
|
||||
|
||||
this.loadSQLDataSource(sqlDataSourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to load DS with given id to check it's exist.
|
||||
* @param {*} datasourceId ID of SQL data source
|
||||
*/
|
||||
|
||||
|
||||
_createClass(ZabbixDBConnector, [{
|
||||
key: 'loadSQLDataSource',
|
||||
value: function loadSQLDataSource(datasourceId) {
|
||||
var _this = this;
|
||||
|
||||
var ds = _.find(this.datasourceSrv.getAll(), { 'id': datasourceId });
|
||||
if (ds) {
|
||||
return this.datasourceSrv.loadDatasource(ds.name).then(function (ds) {
|
||||
_this.sqlDataSourceType = ds.meta.id;
|
||||
return ds;
|
||||
});
|
||||
} else {
|
||||
return Promise.reject('SQL Data Source with ID ' + datasourceId + ' not found');
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'testSQLDataSource',
|
||||
value: function testSQLDataSource() {
|
||||
var testQuery = TEST_MYSQL_QUERY;
|
||||
if (this.sqlDataSourceType === 'postgres') {
|
||||
testQuery = TEST_POSTGRES_QUERY;
|
||||
}
|
||||
return this.invokeSQLQuery(testQuery);
|
||||
}
|
||||
}, {
|
||||
key: 'getHistory',
|
||||
value: function getHistory(items, timeFrom, timeTill, options) {
|
||||
var _this2 = this;
|
||||
|
||||
var intervalMs = options.intervalMs,
|
||||
consolidateBy = options.consolidateBy;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
var aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _.groupBy(items, 'value_type');
|
||||
var promises = _.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _.map(items, 'itemid').join(', ');
|
||||
var table = HISTORY_TO_TABLE_MAP[value_type];
|
||||
|
||||
var dialect = _this2.sqlDataSourceType;
|
||||
var query = buildSQLHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, dialect);
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return _this2.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function (results) {
|
||||
return _.flatten(results);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getTrends',
|
||||
value: function getTrends(items, timeFrom, timeTill, options) {
|
||||
var _this3 = this;
|
||||
|
||||
var intervalMs = options.intervalMs,
|
||||
consolidateBy = options.consolidateBy;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
var aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _.groupBy(items, 'value_type');
|
||||
var promises = _.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _.map(items, 'itemid').join(', ');
|
||||
var table = TREND_TO_TABLE_MAP[value_type];
|
||||
var valueColumn = _.includes(['avg', 'min', 'max'], consolidateBy) ? consolidateBy : 'avg';
|
||||
valueColumn = consolidateByTrendColumns[valueColumn];
|
||||
|
||||
var dialect = _this3.sqlDataSourceType;
|
||||
var query = buildSQLTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn, dialect);
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return _this3.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function (results) {
|
||||
return _.flatten(results);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'handleGrafanaTSResponse',
|
||||
value: function handleGrafanaTSResponse(history, items) {
|
||||
var addHostName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
|
||||
return convertGrafanaTSResponse(history, items, addHostName);
|
||||
}
|
||||
}, {
|
||||
key: 'invokeSQLQuery',
|
||||
value: function invokeSQLQuery(query) {
|
||||
var queryDef = {
|
||||
refId: 'A',
|
||||
format: 'time_series',
|
||||
datasourceId: this.sqlDataSourceId,
|
||||
rawSql: query,
|
||||
maxDataPoints: this.limit
|
||||
};
|
||||
|
||||
return this.backendSrv.datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
queries: [queryDef]
|
||||
}
|
||||
}).then(function (response) {
|
||||
var results = response.data.results;
|
||||
if (results['A']) {
|
||||
return results['A'].series;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return ZabbixDBConnector;
|
||||
}());
|
||||
|
||||
_export('ZabbixDBConnector', ZabbixDBConnector);
|
||||
|
||||
TEST_MYSQL_QUERY = 'SELECT itemid AS metric, clock AS time_sec, value_avg AS value FROM trends_uint LIMIT 1';
|
||||
itemid_format = 'FM99999999999999999999';
|
||||
TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'' + itemid_format + '\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=zabbixDBConnector.js.map
|
||||
1
dist/datasource-zabbix/zabbix/connectors/sql/zabbixDBConnector.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbix/connectors/sql/zabbixDBConnector.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
106
dist/datasource-zabbix/zabbix/connectors/zabbixConnector.js
vendored
Normal file
106
dist/datasource-zabbix/zabbix/connectors/zabbixConnector.js
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _createClass, ZabbixConnector;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
ZabbixConnector = function () {
|
||||
function ZabbixConnector() {
|
||||
_classCallCheck(this, ZabbixConnector);
|
||||
}
|
||||
|
||||
_createClass(ZabbixConnector, [{
|
||||
key: "testDataSource",
|
||||
value: function testDataSource() {}
|
||||
}, {
|
||||
key: "getHistory",
|
||||
value: function getHistory() {}
|
||||
}, {
|
||||
key: "getTrends",
|
||||
value: function getTrends() {}
|
||||
}, {
|
||||
key: "getGroups",
|
||||
value: function getGroups() {}
|
||||
}, {
|
||||
key: "getHosts",
|
||||
value: function getHosts() {}
|
||||
}, {
|
||||
key: "getApps",
|
||||
value: function getApps() {}
|
||||
}, {
|
||||
key: "getItems",
|
||||
value: function getItems() {}
|
||||
}, {
|
||||
key: "getItemsByIDs",
|
||||
value: function getItemsByIDs() {}
|
||||
}, {
|
||||
key: "getMacros",
|
||||
value: function getMacros() {}
|
||||
}, {
|
||||
key: "getGlobalMacros",
|
||||
value: function getGlobalMacros() {}
|
||||
}, {
|
||||
key: "getLastValue",
|
||||
value: function getLastValue() {}
|
||||
}, {
|
||||
key: "getTriggers",
|
||||
value: function getTriggers() {}
|
||||
}, {
|
||||
key: "getEvents",
|
||||
value: function getEvents() {}
|
||||
}, {
|
||||
key: "getAlerts",
|
||||
value: function getAlerts() {}
|
||||
}, {
|
||||
key: "getHostAlerts",
|
||||
value: function getHostAlerts() {}
|
||||
}, {
|
||||
key: "getAcknowledges",
|
||||
value: function getAcknowledges() {}
|
||||
}, {
|
||||
key: "getITService",
|
||||
value: function getITService() {}
|
||||
}, {
|
||||
key: "getSLA",
|
||||
value: function getSLA() {}
|
||||
}, {
|
||||
key: "getVersion",
|
||||
value: function getVersion() {}
|
||||
}]);
|
||||
|
||||
return ZabbixConnector;
|
||||
}();
|
||||
|
||||
_export("default", ZabbixConnector);
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=zabbixConnector.js.map
|
||||
1
dist/datasource-zabbix/zabbix/connectors/zabbixConnector.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbix/connectors/zabbixConnector.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/datasource-zabbix/zabbix/connectors/zabbixConnector.js"],"names":["ZabbixConnector"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIqBA,qB;AAEnB,mCAAc;AAAA;AAAE;;;;2CAEC,CAAE;;;uCAEN,CAAE;;;sCAEH,CAAE;;;sCAEF,CAAE;;;qCAEH,CAAE;;;oCAEH,CAAE;;;qCAED,CAAE;;;0CAEG,CAAE;;;sCAEN,CAAE;;;4CAEI,CAAE;;;yCAEL,CAAE;;;wCAEH,CAAE;;;sCAEJ,CAAE;;;sCAEF,CAAE;;;0CAEE,CAAE;;;4CAEA,CAAE;;;yCAEL,CAAE;;;mCAER,CAAE;;;uCAEE,CAAE;;;;;;yBAxCIA,e","file":"zabbixConnector.js","sourcesContent":["/**\n * Base class for all Zabbix connectors\n */\n\nexport default class ZabbixConnector {\n\n constructor() {}\n\n testDataSource() {}\n\n getHistory() {}\n\n getTrends() {}\n\n getGroups() {}\n\n getHosts() {}\n\n getApps() {}\n\n getItems() {}\n\n getItemsByIDs() {}\n\n getMacros() {}\n\n getGlobalMacros() {}\n\n getLastValue() {}\n\n getTriggers() {}\n\n getEvents() {}\n\n getAlerts() {}\n\n getHostAlerts() {}\n\n getAcknowledges() {}\n\n getITService() {}\n\n getSLA() {}\n\n getVersion() {}\n}\n"]}
|
||||
547
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js
vendored
Normal file
547
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js
vendored
Normal file
@@ -0,0 +1,547 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['lodash', '../../../utils', './zabbixAPICore'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _, utils, ZabbixAPICoreService, _slicedToArray, _createClass, ZabbixAPIConnector;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function filterTriggersByAcknowledge(triggers, acknowledged) {
|
||||
if (acknowledged === 0) {
|
||||
return _.filter(triggers, function (trigger) {
|
||||
return trigger.lastEvent.acknowledged === "0";
|
||||
});
|
||||
} else if (acknowledged === 1) {
|
||||
return _.filter(triggers, function (trigger) {
|
||||
return trigger.lastEvent.acknowledged === "1";
|
||||
});
|
||||
} else {
|
||||
return triggers;
|
||||
}
|
||||
}
|
||||
|
||||
function isNotAuthorized(message) {
|
||||
return message === "Session terminated, re-login, please." || message === "Not authorised." || message === "Not authorized.";
|
||||
}
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}, function (_utils) {
|
||||
utils = _utils;
|
||||
}, function (_zabbixAPICore) {
|
||||
ZabbixAPICoreService = _zabbixAPICore.ZabbixAPICoreService;
|
||||
}],
|
||||
execute: function () {
|
||||
_slicedToArray = function () {
|
||||
function sliceIterator(arr, i) {
|
||||
var _arr = [];
|
||||
var _n = true;
|
||||
var _d = false;
|
||||
var _e = undefined;
|
||||
|
||||
try {
|
||||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
||||
_arr.push(_s.value);
|
||||
|
||||
if (i && _arr.length === i) break;
|
||||
}
|
||||
} catch (err) {
|
||||
_d = true;
|
||||
_e = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_n && _i["return"]) _i["return"]();
|
||||
} finally {
|
||||
if (_d) throw _e;
|
||||
}
|
||||
}
|
||||
|
||||
return _arr;
|
||||
}
|
||||
|
||||
return function (arr, i) {
|
||||
if (Array.isArray(arr)) {
|
||||
return arr;
|
||||
} else if (Symbol.iterator in Object(arr)) {
|
||||
return sliceIterator(arr, i);
|
||||
} else {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
_createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
_export('ZabbixAPIConnector', ZabbixAPIConnector = function () {
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixAPIConnector(api_url, username, password, basicAuth, withCredentials, backendSrv) {
|
||||
_classCallCheck(this, ZabbixAPIConnector);
|
||||
|
||||
this.url = api_url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.auth = "";
|
||||
|
||||
this.requestOptions = {
|
||||
basicAuth: basicAuth,
|
||||
withCredentials: withCredentials
|
||||
};
|
||||
|
||||
this.loginPromise = null;
|
||||
this.loginErrorCount = 0;
|
||||
this.maxLoginAttempts = 3;
|
||||
|
||||
this.zabbixAPICore = new ZabbixAPICoreService(backendSrv);
|
||||
|
||||
this.getTrend = this.getTrend_ZBXNEXT1193;
|
||||
//getTrend = getTrend_30;
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
// Core method wrappers //
|
||||
//////////////////////////
|
||||
|
||||
_createClass(ZabbixAPIConnector, [{
|
||||
key: 'request',
|
||||
value: function request(method, params) {
|
||||
var _this = this;
|
||||
|
||||
return this.zabbixAPICore.request(this.url, method, params, this.requestOptions, this.auth).catch(function (error) {
|
||||
if (isNotAuthorized(error.data)) {
|
||||
// Handle auth errors
|
||||
_this.loginErrorCount++;
|
||||
if (_this.loginErrorCount > _this.maxLoginAttempts) {
|
||||
_this.loginErrorCount = 0;
|
||||
return null;
|
||||
} else {
|
||||
return _this.loginOnce().then(function () {
|
||||
return _this.request(method, params);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Handle API errors
|
||||
var message = error.data ? error.data : error.statusText;
|
||||
return Promise.reject(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'loginOnce',
|
||||
value: function loginOnce() {
|
||||
var _this2 = this;
|
||||
|
||||
if (!this.loginPromise) {
|
||||
this.loginPromise = Promise.resolve(this.login().then(function (auth) {
|
||||
_this2.auth = auth;
|
||||
_this2.loginPromise = null;
|
||||
return auth;
|
||||
}));
|
||||
}
|
||||
return this.loginPromise;
|
||||
}
|
||||
}, {
|
||||
key: 'login',
|
||||
value: function login() {
|
||||
return this.zabbixAPICore.login(this.url, this.username, this.password, this.requestOptions);
|
||||
}
|
||||
}, {
|
||||
key: 'getVersion',
|
||||
value: function getVersion() {
|
||||
return this.zabbixAPICore.getVersion(this.url, this.requestOptions);
|
||||
}
|
||||
}, {
|
||||
key: 'acknowledgeEvent',
|
||||
value: function acknowledgeEvent(eventid, message) {
|
||||
var params = {
|
||||
eventids: eventid,
|
||||
message: message
|
||||
};
|
||||
|
||||
return this.request('event.acknowledge', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getGroups',
|
||||
value: function getGroups() {
|
||||
var params = {
|
||||
output: ['name'],
|
||||
sortfield: 'name',
|
||||
real_hosts: true
|
||||
};
|
||||
|
||||
return this.request('hostgroup.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getHosts',
|
||||
value: function getHosts(groupids) {
|
||||
var params = {
|
||||
output: ['name', 'host'],
|
||||
sortfield: 'name'
|
||||
};
|
||||
if (groupids) {
|
||||
params.groupids = groupids;
|
||||
}
|
||||
|
||||
return this.request('host.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getApps',
|
||||
value: function getApps(hostids) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
hostids: hostids
|
||||
};
|
||||
|
||||
return this.request('application.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getItems',
|
||||
value: function getItems(hostids, appids, itemtype) {
|
||||
var params = {
|
||||
output: ['name', 'key_', 'value_type', 'hostid', 'status', 'state'],
|
||||
sortfield: 'name',
|
||||
webitems: true,
|
||||
filter: {},
|
||||
selectHosts: ['hostid', 'name']
|
||||
};
|
||||
if (hostids) {
|
||||
params.hostids = hostids;
|
||||
}
|
||||
if (appids) {
|
||||
params.applicationids = appids;
|
||||
}
|
||||
if (itemtype === 'num') {
|
||||
// Return only numeric metrics
|
||||
params.filter.value_type = [0, 3];
|
||||
}
|
||||
if (itemtype === 'text') {
|
||||
// Return only text metrics
|
||||
params.filter.value_type = [1, 2, 4];
|
||||
}
|
||||
|
||||
return this.request('item.get', params).then(utils.expandItems);
|
||||
}
|
||||
}, {
|
||||
key: 'getItemsByIDs',
|
||||
value: function getItemsByIDs(itemids) {
|
||||
var params = {
|
||||
itemids: itemids,
|
||||
output: ['name', 'key_', 'value_type', 'hostid', 'status', 'state'],
|
||||
webitems: true,
|
||||
selectHosts: ['hostid', 'name']
|
||||
};
|
||||
|
||||
return this.request('item.get', params).then(utils.expandItems);
|
||||
}
|
||||
}, {
|
||||
key: 'getMacros',
|
||||
value: function getMacros(hostids) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
hostids: hostids
|
||||
};
|
||||
|
||||
return this.request('usermacro.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getGlobalMacros',
|
||||
value: function getGlobalMacros() {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
globalmacro: true
|
||||
};
|
||||
|
||||
return this.request('usermacro.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getLastValue',
|
||||
value: function getLastValue(itemid) {
|
||||
var params = {
|
||||
output: ['lastvalue'],
|
||||
itemids: itemid
|
||||
};
|
||||
return this.request('item.get', params).then(function (items) {
|
||||
return items.length ? items[0].lastvalue : null;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getHistory',
|
||||
value: function getHistory(items, timeFrom, timeTill) {
|
||||
var _this3 = this;
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _.groupBy(items, 'value_type');
|
||||
var promises = _.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _.map(items, 'itemid');
|
||||
var params = {
|
||||
output: 'extend',
|
||||
history: value_type,
|
||||
itemids: itemids,
|
||||
sortfield: 'clock',
|
||||
sortorder: 'ASC',
|
||||
time_from: timeFrom
|
||||
};
|
||||
|
||||
// Relative queries (e.g. last hour) don't include an end time
|
||||
if (timeTill) {
|
||||
params.time_till = timeTill;
|
||||
}
|
||||
|
||||
return _this3.request('history.get', params);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(_.flatten);
|
||||
}
|
||||
}, {
|
||||
key: 'getTrend_ZBXNEXT1193',
|
||||
value: function getTrend_ZBXNEXT1193(items, timeFrom, timeTill) {
|
||||
var _this4 = this;
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _.groupBy(items, 'value_type');
|
||||
var promises = _.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _.map(items, 'itemid');
|
||||
var params = {
|
||||
output: 'extend',
|
||||
trend: value_type,
|
||||
itemids: itemids,
|
||||
sortfield: 'clock',
|
||||
sortorder: 'ASC',
|
||||
time_from: timeFrom
|
||||
};
|
||||
|
||||
// Relative queries (e.g. last hour) don't include an end time
|
||||
if (timeTill) {
|
||||
params.time_till = timeTill;
|
||||
}
|
||||
|
||||
return _this4.request('trend.get', params);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(_.flatten);
|
||||
}
|
||||
}, {
|
||||
key: 'getTrend_30',
|
||||
value: function getTrend_30(items, time_from, time_till, value_type) {
|
||||
var self = this;
|
||||
var itemids = _.map(items, 'itemid');
|
||||
|
||||
var params = {
|
||||
output: ["itemid", "clock", value_type],
|
||||
itemids: itemids,
|
||||
time_from: time_from
|
||||
};
|
||||
|
||||
// Relative queries (e.g. last hour) don't include an end time
|
||||
if (time_till) {
|
||||
params.time_till = time_till;
|
||||
}
|
||||
|
||||
return self.request('trend.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getITService',
|
||||
value: function getITService(serviceids) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
serviceids: serviceids
|
||||
};
|
||||
return this.request('service.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getSLA',
|
||||
value: function getSLA(serviceids, timeRange) {
|
||||
var _timeRange = _slicedToArray(timeRange, 2),
|
||||
timeFrom = _timeRange[0],
|
||||
timeTo = _timeRange[1];
|
||||
|
||||
var params = {
|
||||
serviceids: serviceids,
|
||||
intervals: [{
|
||||
from: timeFrom,
|
||||
to: timeTo
|
||||
}]
|
||||
};
|
||||
return this.request('service.getsla', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getTriggers',
|
||||
value: function getTriggers(groupids, hostids, applicationids, options) {
|
||||
var showTriggers = options.showTriggers,
|
||||
maintenance = options.maintenance,
|
||||
timeFrom = options.timeFrom,
|
||||
timeTo = options.timeTo;
|
||||
|
||||
|
||||
var params = {
|
||||
output: 'extend',
|
||||
groupids: groupids,
|
||||
hostids: hostids,
|
||||
applicationids: applicationids,
|
||||
expandDescription: true,
|
||||
expandData: true,
|
||||
expandComment: true,
|
||||
monitored: true,
|
||||
skipDependent: true,
|
||||
//only_true: true,
|
||||
filter: {
|
||||
value: 1
|
||||
},
|
||||
selectGroups: ['name'],
|
||||
selectHosts: ['name', 'host', 'maintenance_status'],
|
||||
selectItems: ['name', 'key_', 'lastvalue'],
|
||||
selectLastEvent: 'extend',
|
||||
selectTags: 'extend'
|
||||
};
|
||||
|
||||
if (showTriggers) {
|
||||
params.filter.value = showTriggers;
|
||||
}
|
||||
|
||||
if (maintenance) {
|
||||
params.maintenance = true;
|
||||
}
|
||||
|
||||
if (timeFrom || timeTo) {
|
||||
params.lastChangeSince = timeFrom;
|
||||
params.lastChangeTill = timeTo;
|
||||
}
|
||||
|
||||
return this.request('trigger.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getEvents',
|
||||
value: function getEvents(objectids, timeFrom, timeTo, showEvents) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
time_from: timeFrom,
|
||||
time_till: timeTo,
|
||||
objectids: objectids,
|
||||
select_acknowledges: 'extend',
|
||||
selectHosts: 'extend',
|
||||
value: showEvents
|
||||
};
|
||||
|
||||
return this.request('event.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getAcknowledges',
|
||||
value: function getAcknowledges(eventids) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
eventids: eventids,
|
||||
preservekeys: true,
|
||||
select_acknowledges: 'extend',
|
||||
sortfield: 'clock',
|
||||
sortorder: 'DESC'
|
||||
};
|
||||
|
||||
return this.request('event.get', params).then(function (events) {
|
||||
return _.filter(events, function (event) {
|
||||
return event.acknowledges.length;
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getAlerts',
|
||||
value: function getAlerts(itemids, timeFrom, timeTo) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
itemids: itemids,
|
||||
expandDescription: true,
|
||||
expandData: true,
|
||||
expandComment: true,
|
||||
monitored: true,
|
||||
skipDependent: true,
|
||||
//only_true: true,
|
||||
// filter: {
|
||||
// value: 1
|
||||
// },
|
||||
selectLastEvent: 'extend'
|
||||
};
|
||||
|
||||
if (timeFrom || timeTo) {
|
||||
params.lastChangeSince = timeFrom;
|
||||
params.lastChangeTill = timeTo;
|
||||
}
|
||||
|
||||
return this.request('trigger.get', params);
|
||||
}
|
||||
}, {
|
||||
key: 'getHostAlerts',
|
||||
value: function getHostAlerts(hostids, applicationids, options) {
|
||||
var minSeverity = options.minSeverity,
|
||||
acknowledged = options.acknowledged,
|
||||
count = options.count,
|
||||
timeFrom = options.timeFrom,
|
||||
timeTo = options.timeTo;
|
||||
|
||||
var params = {
|
||||
output: 'extend',
|
||||
hostids: hostids,
|
||||
min_severity: minSeverity,
|
||||
filter: { value: 1 },
|
||||
expandDescription: true,
|
||||
expandData: true,
|
||||
expandComment: true,
|
||||
monitored: true,
|
||||
skipDependent: true,
|
||||
selectLastEvent: 'extend',
|
||||
selectGroups: 'extend',
|
||||
selectHosts: ['host', 'name']
|
||||
};
|
||||
|
||||
if (count && acknowledged !== 0 && acknowledged !== 1) {
|
||||
params.countOutput = true;
|
||||
}
|
||||
|
||||
if (applicationids && applicationids.length) {
|
||||
params.applicationids = applicationids;
|
||||
}
|
||||
|
||||
if (timeFrom || timeTo) {
|
||||
params.lastChangeSince = timeFrom;
|
||||
params.lastChangeTill = timeTo;
|
||||
}
|
||||
|
||||
return this.request('trigger.get', params).then(function (triggers) {
|
||||
if (!count || acknowledged === 0 || acknowledged === 1) {
|
||||
triggers = filterTriggersByAcknowledge(triggers, acknowledged);
|
||||
if (count) {
|
||||
triggers = triggers.length;
|
||||
}
|
||||
}
|
||||
return triggers;
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return ZabbixAPIConnector;
|
||||
}());
|
||||
|
||||
_export('ZabbixAPIConnector', ZabbixAPIConnector);
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=zabbixAPIConnector.js.map
|
||||
1
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
148
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPICore.js
vendored
Normal file
148
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPICore.js
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _createClass, ZabbixAPICoreService, ZabbixAPIError;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
_export("ZabbixAPICoreService", ZabbixAPICoreService = function () {
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixAPICoreService(backendSrv) {
|
||||
_classCallCheck(this, ZabbixAPICoreService);
|
||||
|
||||
this.backendSrv = backendSrv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request data from Zabbix API
|
||||
* @return {object} response.result
|
||||
*/
|
||||
|
||||
|
||||
_createClass(ZabbixAPICoreService, [{
|
||||
key: "request",
|
||||
value: function request(api_url, method, params, options, auth) {
|
||||
var requestData = {
|
||||
jsonrpc: '2.0',
|
||||
method: method,
|
||||
params: params,
|
||||
id: 1
|
||||
};
|
||||
|
||||
if (auth === "") {
|
||||
// Reject immediately if not authenticated
|
||||
return Promise.reject(new ZabbixAPIError({ data: "Not authorised." }));
|
||||
} else if (auth) {
|
||||
// Set auth parameter only if it needed
|
||||
requestData.auth = auth;
|
||||
}
|
||||
|
||||
var requestOptions = {
|
||||
method: 'POST',
|
||||
url: api_url,
|
||||
data: requestData,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
// Set request options for basic auth
|
||||
if (options.basicAuth || options.withCredentials) {
|
||||
requestOptions.withCredentials = true;
|
||||
}
|
||||
if (options.basicAuth) {
|
||||
requestOptions.headers.Authorization = options.basicAuth;
|
||||
}
|
||||
|
||||
return this.datasourceRequest(requestOptions);
|
||||
}
|
||||
}, {
|
||||
key: "datasourceRequest",
|
||||
value: function datasourceRequest(requestOptions) {
|
||||
return this.backendSrv.datasourceRequest(requestOptions).then(function (response) {
|
||||
if (!response.data) {
|
||||
return Promise.reject(new ZabbixAPIError({ data: "General Error, no data" }));
|
||||
} else if (response.data.error) {
|
||||
|
||||
// Handle Zabbix API errors
|
||||
return Promise.reject(new ZabbixAPIError(response.data.error));
|
||||
}
|
||||
|
||||
// Success
|
||||
return response.data.result;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "login",
|
||||
value: function login(api_url, username, password, options) {
|
||||
var params = {
|
||||
user: username,
|
||||
password: password
|
||||
};
|
||||
return this.request(api_url, 'user.login', params, options, null);
|
||||
}
|
||||
}, {
|
||||
key: "getVersion",
|
||||
value: function getVersion(api_url, options) {
|
||||
return this.request(api_url, 'apiinfo.version', [], options);
|
||||
}
|
||||
}]);
|
||||
|
||||
return ZabbixAPICoreService;
|
||||
}());
|
||||
|
||||
_export("ZabbixAPICoreService", ZabbixAPICoreService);
|
||||
|
||||
_export("ZabbixAPIError", ZabbixAPIError = function () {
|
||||
function ZabbixAPIError(error) {
|
||||
_classCallCheck(this, ZabbixAPIError);
|
||||
|
||||
this.code = error.code || null;
|
||||
this.name = error.message || "";
|
||||
this.data = error.data || "";
|
||||
this.message = "Zabbix API Error: " + this.name + " " + this.data;
|
||||
}
|
||||
|
||||
_createClass(ZabbixAPIError, [{
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
return this.name + " " + this.data;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ZabbixAPIError;
|
||||
}());
|
||||
|
||||
_export("ZabbixAPIError", ZabbixAPIError);
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=zabbixAPICore.js.map
|
||||
1
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPICore.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPICore.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPICore.js"],"names":["ZabbixAPICoreService","backendSrv","api_url","method","params","options","auth","requestData","jsonrpc","id","Promise","reject","ZabbixAPIError","data","requestOptions","url","headers","basicAuth","withCredentials","Authorization","datasourceRequest","then","response","error","result","username","password","user","request","code","name","message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sCAIaA,oB;;AAEX;AACA,sCAAYC,UAAZ,EAAwB;AAAA;;AACtB,eAAKA,UAAL,GAAkBA,UAAlB;AACD;;AAED;;;;;;;;kCAIQC,O,EAASC,M,EAAQC,M,EAAQC,O,EAASC,I,EAAM;AAC9C,gBAAIC,cAAc;AAChBC,uBAAS,KADO;AAEhBL,sBAAQA,MAFQ;AAGhBC,sBAAQA,MAHQ;AAIhBK,kBAAI;AAJY,aAAlB;;AAOA,gBAAIH,SAAS,EAAb,EAAiB;AACf;AACA,qBAAOI,QAAQC,MAAR,CAAe,IAAIC,cAAJ,CAAmB,EAACC,MAAM,iBAAP,EAAnB,CAAf,CAAP;AACD,aAHD,MAGO,IAAIP,IAAJ,EAAU;AACf;AACAC,0BAAYD,IAAZ,GAAmBA,IAAnB;AACD;;AAED,gBAAIQ,iBAAiB;AACnBX,sBAAQ,MADW;AAEnBY,mBAAKb,OAFc;AAGnBW,oBAAMN,WAHa;AAInBS,uBAAS;AACP,gCAAgB;AADT;AAJU,aAArB;;AASA;AACA,gBAAIX,QAAQY,SAAR,IAAqBZ,QAAQa,eAAjC,EAAkD;AAChDJ,6BAAeI,eAAf,GAAiC,IAAjC;AACD;AACD,gBAAIb,QAAQY,SAAZ,EAAuB;AACrBH,6BAAeE,OAAf,CAAuBG,aAAvB,GAAuCd,QAAQY,SAA/C;AACD;;AAED,mBAAO,KAAKG,iBAAL,CAAuBN,cAAvB,CAAP;AACD;;;4CAEiBA,c,EAAgB;AAChC,mBAAO,KAAKb,UAAL,CAAgBmB,iBAAhB,CAAkCN,cAAlC,EACNO,IADM,CACD,UAACC,QAAD,EAAc;AAClB,kBAAI,CAACA,SAAST,IAAd,EAAoB;AAClB,uBAAOH,QAAQC,MAAR,CAAe,IAAIC,cAAJ,CAAmB,EAACC,MAAM,wBAAP,EAAnB,CAAf,CAAP;AACD,eAFD,MAEO,IAAIS,SAAST,IAAT,CAAcU,KAAlB,EAAyB;;AAE9B;AACA,uBAAOb,QAAQC,MAAR,CAAe,IAAIC,cAAJ,CAAmBU,SAAST,IAAT,CAAcU,KAAjC,CAAf,CAAP;AACD;;AAED;AACA,qBAAOD,SAAST,IAAT,CAAcW,MAArB;AACD,aAZM,CAAP;AAaD;;;gCAMKtB,O,EAASuB,Q,EAAUC,Q,EAAUrB,O,EAAS;AAC1C,gBAAID,SAAS;AACXuB,oBAAMF,QADK;AAEXC,wBAAUA;AAFC,aAAb;AAIA,mBAAO,KAAKE,OAAL,CAAa1B,OAAb,EAAsB,YAAtB,EAAoCE,MAApC,EAA4CC,OAA5C,EAAqD,IAArD,CAAP;AACD;;;qCAMUH,O,EAASG,O,EAAS;AAC3B,mBAAO,KAAKuB,OAAL,CAAa1B,OAAb,EAAsB,iBAAtB,EAAyC,EAAzC,EAA6CG,OAA7C,CAAP;AACD;;;;;;;;gCAIUO,c;AACX,gCAAYW,KAAZ,EAAmB;AAAA;;AACjB,eAAKM,IAAL,GAAYN,MAAMM,IAAN,IAAc,IAA1B;AACA,eAAKC,IAAL,GAAYP,MAAMQ,OAAN,IAAiB,EAA7B;AACA,eAAKlB,IAAL,GAAYU,MAAMV,IAAN,IAAc,EAA1B;AACA,eAAKkB,OAAL,GAAe,uBAAuB,KAAKD,IAA5B,GAAmC,GAAnC,GAAyC,KAAKjB,IAA7D;AACD;;;;qCAEU;AACT,mBAAO,KAAKiB,IAAL,GAAY,GAAZ,GAAkB,KAAKjB,IAA9B;AACD","file":"zabbixAPICore.js","sourcesContent":["/**\n * General Zabbix API methods\n */\n\nexport class ZabbixAPICoreService {\n\n /** @ngInject */\n constructor(backendSrv) {\n this.backendSrv = backendSrv;\n }\n\n /**\n * Request data from Zabbix API\n * @return {object} response.result\n */\n request(api_url, method, params, options, auth) {\n let requestData = {\n jsonrpc: '2.0',\n method: method,\n params: params,\n id: 1\n };\n\n if (auth === \"\") {\n // Reject immediately if not authenticated\n return Promise.reject(new ZabbixAPIError({data: \"Not authorised.\"}));\n } else if (auth) {\n // Set auth parameter only if it needed\n requestData.auth = auth;\n }\n\n let requestOptions = {\n method: 'POST',\n url: api_url,\n data: requestData,\n headers: {\n 'Content-Type': 'application/json'\n }\n };\n\n // Set request options for basic auth\n if (options.basicAuth || options.withCredentials) {\n requestOptions.withCredentials = true;\n }\n if (options.basicAuth) {\n requestOptions.headers.Authorization = options.basicAuth;\n }\n\n return this.datasourceRequest(requestOptions);\n }\n\n datasourceRequest(requestOptions) {\n return this.backendSrv.datasourceRequest(requestOptions)\n .then((response) => {\n if (!response.data) {\n return Promise.reject(new ZabbixAPIError({data: \"General Error, no data\"}));\n } else if (response.data.error) {\n\n // Handle Zabbix API errors\n return Promise.reject(new ZabbixAPIError(response.data.error));\n }\n\n // Success\n return response.data.result;\n });\n }\n\n /**\n * Get authentication token.\n * @return {string} auth token\n */\n login(api_url, username, password, options) {\n let params = {\n user: username,\n password: password\n };\n return this.request(api_url, 'user.login', params, options, null);\n }\n\n /**\n * Get Zabbix API version\n * Matches the version of Zabbix starting from Zabbix 2.0.4\n */\n getVersion(api_url, options) {\n return this.request(api_url, 'apiinfo.version', [], options);\n }\n}\n\n// Define zabbix API exception type\nexport class ZabbixAPIError {\n constructor(error) {\n this.code = error.code || null;\n this.name = error.message || \"\";\n this.data = error.data || \"\";\n this.message = \"Zabbix API Error: \" + this.name + \" \" + this.data;\n }\n\n toString() {\n return this.name + \" \" + this.data;\n }\n}\n"]}
|
||||
283
dist/datasource-zabbix/zabbix/proxy/zabbixCachingProxy.js
vendored
Normal file
283
dist/datasource-zabbix/zabbix/proxy/zabbixCachingProxy.js
vendored
Normal file
@@ -0,0 +1,283 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['lodash'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _, _createClass, ZabbixCachingProxy;
|
||||
|
||||
function _toConsumableArray(arr) {
|
||||
if (Array.isArray(arr)) {
|
||||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
|
||||
arr2[i] = arr[i];
|
||||
}
|
||||
|
||||
return arr2;
|
||||
} else {
|
||||
return Array.from(arr);
|
||||
}
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap zabbix API request to prevent multiple calls
|
||||
* with same params when waiting for result.
|
||||
*/
|
||||
function callAPIRequestOnce(func, promiseKeeper, argsHashFunc) {
|
||||
return function () {
|
||||
var hash = argsHashFunc(arguments);
|
||||
if (!promiseKeeper[hash]) {
|
||||
promiseKeeper[hash] = Promise.resolve(func.apply(this, arguments).then(function (result) {
|
||||
promiseKeeper[hash] = null;
|
||||
return result;
|
||||
}));
|
||||
}
|
||||
return promiseKeeper[hash];
|
||||
};
|
||||
}
|
||||
|
||||
function getRequestHash(args) {
|
||||
var requestStamp = _.map(args, function (arg) {
|
||||
if (arg === undefined) {
|
||||
return 'undefined';
|
||||
} else {
|
||||
if (_.isArray(arg)) {
|
||||
return arg.sort().toString();
|
||||
} else {
|
||||
return arg.toString();
|
||||
}
|
||||
}
|
||||
}).join();
|
||||
return requestStamp.getHash();
|
||||
}
|
||||
|
||||
function getHistoryRequestHash(args) {
|
||||
var itemids = _.map(args[0], 'itemid');
|
||||
var stamp = itemids.join() + args[1] + args[2];
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
function getDBQueryHash(args) {
|
||||
var itemids = _.map(args[0], 'itemid');
|
||||
var consolidateBy = args[3].consolidateBy;
|
||||
var intervalMs = args[3].intervalMs;
|
||||
var stamp = itemids.join() + args[1] + args[2] + consolidateBy + intervalMs;
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}],
|
||||
execute: function () {
|
||||
_createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
_export('ZabbixCachingProxy', ZabbixCachingProxy = function () {
|
||||
function ZabbixCachingProxy(zabbixAPI, zabbixDBConnector, cacheOptions) {
|
||||
_classCallCheck(this, ZabbixCachingProxy);
|
||||
|
||||
this.zabbixAPI = zabbixAPI;
|
||||
this.dbConnector = zabbixDBConnector;
|
||||
this.cacheEnabled = cacheOptions.enabled;
|
||||
this.ttl = cacheOptions.ttl || 600000; // 10 minutes by default
|
||||
|
||||
// Internal objects for data storing
|
||||
this.cache = {
|
||||
groups: {},
|
||||
hosts: {},
|
||||
applications: {},
|
||||
items: {},
|
||||
history: {},
|
||||
trends: {},
|
||||
macros: {},
|
||||
globalMacros: {},
|
||||
itServices: {}
|
||||
};
|
||||
|
||||
this.historyPromises = {};
|
||||
|
||||
// Don't run duplicated history requests
|
||||
this.getHistory = callAPIRequestOnce(_.bind(this.zabbixAPI.getHistory, this.zabbixAPI), this.historyPromises, getHistoryRequestHash);
|
||||
|
||||
if (this.dbConnector) {
|
||||
this.getHistoryDB = callAPIRequestOnce(_.bind(this.dbConnector.getHistory, this.dbConnector), this.historyPromises, getDBQueryHash);
|
||||
this.getTrendsDB = callAPIRequestOnce(_.bind(this.dbConnector.getTrends, this.dbConnector), this.historyPromises, getDBQueryHash);
|
||||
}
|
||||
|
||||
// Don't run duplicated requests
|
||||
this.groupPromises = {};
|
||||
this.getGroupsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGroups, this.zabbixAPI), this.groupPromises, getRequestHash);
|
||||
|
||||
this.hostPromises = {};
|
||||
this.getHostsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getHosts, this.zabbixAPI), this.hostPromises, getRequestHash);
|
||||
|
||||
this.appPromises = {};
|
||||
this.getAppsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getApps, this.zabbixAPI), this.appPromises, getRequestHash);
|
||||
|
||||
this.itemPromises = {};
|
||||
this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.itemPromises, getRequestHash);
|
||||
|
||||
this.itemByIdPromises = {};
|
||||
this.getItemsByIdOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItemsByIDs, this.zabbixAPI), this.itemPromises, getRequestHash);
|
||||
|
||||
this.itServicesPromises = {};
|
||||
this.getITServicesOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getITService, this.zabbixAPI), this.itServicesPromises, getRequestHash);
|
||||
|
||||
this.macroPromises = {};
|
||||
this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.macroPromises, getRequestHash);
|
||||
|
||||
this.globalMacroPromises = {};
|
||||
this.getGlobalMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGlobalMacros, this.zabbixAPI), this.globalMacroPromises, getRequestHash);
|
||||
}
|
||||
|
||||
_createClass(ZabbixCachingProxy, [{
|
||||
key: 'isExpired',
|
||||
value: function isExpired(cacheObject) {
|
||||
if (cacheObject) {
|
||||
var object_age = Date.now() - cacheObject.timestamp;
|
||||
return !(cacheObject.timestamp && object_age < this.ttl);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'proxyRequest',
|
||||
value: function proxyRequest(request, params, cacheObject) {
|
||||
var hash = getRequestHash(params);
|
||||
if (this.cacheEnabled && !this.isExpired(cacheObject[hash])) {
|
||||
return Promise.resolve(cacheObject[hash].value);
|
||||
} else {
|
||||
return request.apply(undefined, _toConsumableArray(params)).then(function (result) {
|
||||
cacheObject[hash] = {
|
||||
value: result,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'getGroups',
|
||||
value: function getGroups() {
|
||||
return this.proxyRequest(this.getGroupsOnce, [], this.cache.groups);
|
||||
}
|
||||
}, {
|
||||
key: 'getHosts',
|
||||
value: function getHosts(groupids) {
|
||||
return this.proxyRequest(this.getHostsOnce, [groupids], this.cache.hosts);
|
||||
}
|
||||
}, {
|
||||
key: 'getApps',
|
||||
value: function getApps(hostids) {
|
||||
return this.proxyRequest(this.getAppsOnce, [hostids], this.cache.applications);
|
||||
}
|
||||
}, {
|
||||
key: 'getItems',
|
||||
value: function getItems(hostids, appids, itemtype) {
|
||||
var params = [hostids, appids, itemtype];
|
||||
return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
|
||||
}
|
||||
}, {
|
||||
key: 'getItemsByIDs',
|
||||
value: function getItemsByIDs(itemids) {
|
||||
var params = [itemids];
|
||||
return this.proxyRequest(this.getItemsByIdOnce, params, this.cache.items);
|
||||
}
|
||||
}, {
|
||||
key: 'getITServices',
|
||||
value: function getITServices() {
|
||||
return this.proxyRequest(this.getITServicesOnce, [], this.cache.itServices);
|
||||
}
|
||||
}, {
|
||||
key: 'getMacros',
|
||||
value: function getMacros(hostids) {
|
||||
// Merge global macros and host macros
|
||||
var promises = [this.proxyRequest(this.getMacrosOnce, [hostids], this.cache.macros), this.proxyRequest(this.getGlobalMacrosOnce, [], this.cache.globalMacros)];
|
||||
|
||||
return Promise.all(promises).then(_.flatten);
|
||||
}
|
||||
}, {
|
||||
key: 'getHistoryFromCache',
|
||||
value: function getHistoryFromCache(items, time_from, time_till) {
|
||||
var historyStorage = this.cache.history;
|
||||
var full_history;
|
||||
var expired = _.filter(_.keyBy(items, 'itemid'), function (item, itemid) {
|
||||
return !historyStorage[itemid];
|
||||
});
|
||||
if (expired.length) {
|
||||
return this.zabbixAPI.getHistory(expired, time_from, time_till).then(function (history) {
|
||||
var grouped_history = _.groupBy(history, 'itemid');
|
||||
_.forEach(expired, function (item) {
|
||||
var itemid = item.itemid;
|
||||
historyStorage[itemid] = item;
|
||||
historyStorage[itemid].time_from = time_from;
|
||||
historyStorage[itemid].time_till = time_till;
|
||||
historyStorage[itemid].history = grouped_history[itemid];
|
||||
});
|
||||
full_history = _.map(items, function (item) {
|
||||
return historyStorage[item.itemid].history;
|
||||
});
|
||||
return _.flatten(full_history, true);
|
||||
});
|
||||
} else {
|
||||
full_history = _.map(items, function (item) {
|
||||
return historyStorage[item.itemid].history;
|
||||
});
|
||||
return Promise.resolve(_.flatten(full_history, true));
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'getHistoryFromAPI',
|
||||
value: function getHistoryFromAPI(items, time_from, time_till) {
|
||||
return this.zabbixAPI.getHistory(items, time_from, time_till);
|
||||
}
|
||||
}]);
|
||||
|
||||
return ZabbixCachingProxy;
|
||||
}());
|
||||
|
||||
_export('ZabbixCachingProxy', ZabbixCachingProxy);
|
||||
|
||||
String.prototype.getHash = function () {
|
||||
var hash = 0,
|
||||
i,
|
||||
chr,
|
||||
len;
|
||||
if (this.length !== 0) {
|
||||
for (i = 0, len = this.length; i < len; i++) {
|
||||
chr = this.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + chr;
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
};
|
||||
|
||||
// Fix for backward compatibility with lodash 2.4
|
||||
if (!_.keyBy) {
|
||||
_.keyBy = _.indexBy;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=zabbixCachingProxy.js.map
|
||||
1
dist/datasource-zabbix/zabbix/proxy/zabbixCachingProxy.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbix/proxy/zabbixCachingProxy.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
385
dist/datasource-zabbix/zabbix/zabbix.js
vendored
Normal file
385
dist/datasource-zabbix/zabbix/zabbix.js
vendored
Normal file
@@ -0,0 +1,385 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['lodash', '../utils', './connectors/zabbix_api/zabbixAPIConnector', './connectors/sql/zabbixDBConnector', './proxy/zabbixCachingProxy'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _, utils, ZabbixAPIConnector, ZabbixDBConnector, ZabbixCachingProxy, _slicedToArray, _createClass, Zabbix;
|
||||
|
||||
function _toConsumableArray(arr) {
|
||||
if (Array.isArray(arr)) {
|
||||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
|
||||
arr2[i] = arr[i];
|
||||
}
|
||||
|
||||
return arr2;
|
||||
} else {
|
||||
return Array.from(arr);
|
||||
}
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
// angular
|
||||
// .module('grafana.services')
|
||||
// .factory('Zabbix', ZabbixFactory);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Find group, host, app or item by given name.
|
||||
* @param list list of groups, apps or other
|
||||
* @param name visible name
|
||||
* @return array with finded element or empty array
|
||||
*/
|
||||
function findByName(list, name) {
|
||||
var finded = _.find(list, { 'name': name });
|
||||
if (finded) {
|
||||
return [finded];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Different hosts can contains applications and items with same name.
|
||||
* For this reason use _.filter, which return all elements instead _.find,
|
||||
* which return only first finded.
|
||||
* @param {[type]} list list of elements
|
||||
* @param {[type]} name app name
|
||||
* @return {[type]} array with finded element or empty array
|
||||
*/
|
||||
function filterByName(list, name) {
|
||||
var finded = _.filter(list, { 'name': name });
|
||||
if (finded) {
|
||||
return finded;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function filterByRegex(list, regex) {
|
||||
var filterPattern = utils.buildRegex(regex);
|
||||
return _.filter(list, function (zbx_obj) {
|
||||
return filterPattern.test(zbx_obj.name);
|
||||
});
|
||||
}
|
||||
|
||||
function findByFilter(list, filter) {
|
||||
if (utils.isRegex(filter)) {
|
||||
return filterByRegex(list, filter);
|
||||
} else {
|
||||
return findByName(list, filter);
|
||||
}
|
||||
}
|
||||
|
||||
function filterByQuery(list, filter) {
|
||||
if (utils.isRegex(filter)) {
|
||||
return filterByRegex(list, filter);
|
||||
} else {
|
||||
return filterByName(list, filter);
|
||||
}
|
||||
}
|
||||
|
||||
function getHostIds(items) {
|
||||
var hostIds = _.map(items, function (item) {
|
||||
return _.map(item.hosts, 'hostid');
|
||||
});
|
||||
return _.uniq(_.flatten(hostIds));
|
||||
}
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}, function (_utils) {
|
||||
utils = _utils;
|
||||
}, function (_connectorsZabbix_apiZabbixAPIConnector) {
|
||||
ZabbixAPIConnector = _connectorsZabbix_apiZabbixAPIConnector.ZabbixAPIConnector;
|
||||
}, function (_connectorsSqlZabbixDBConnector) {
|
||||
ZabbixDBConnector = _connectorsSqlZabbixDBConnector.ZabbixDBConnector;
|
||||
}, function (_proxyZabbixCachingProxy) {
|
||||
ZabbixCachingProxy = _proxyZabbixCachingProxy.ZabbixCachingProxy;
|
||||
}],
|
||||
execute: function () {
|
||||
_slicedToArray = function () {
|
||||
function sliceIterator(arr, i) {
|
||||
var _arr = [];
|
||||
var _n = true;
|
||||
var _d = false;
|
||||
var _e = undefined;
|
||||
|
||||
try {
|
||||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
||||
_arr.push(_s.value);
|
||||
|
||||
if (i && _arr.length === i) break;
|
||||
}
|
||||
} catch (err) {
|
||||
_d = true;
|
||||
_e = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_n && _i["return"]) _i["return"]();
|
||||
} finally {
|
||||
if (_d) throw _e;
|
||||
}
|
||||
}
|
||||
|
||||
return _arr;
|
||||
}
|
||||
|
||||
return function (arr, i) {
|
||||
if (Array.isArray(arr)) {
|
||||
return arr;
|
||||
} else if (Symbol.iterator in Object(arr)) {
|
||||
return sliceIterator(arr, i);
|
||||
} else {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
_createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
_export('Zabbix', Zabbix = function () {
|
||||
|
||||
/** @ngInject */
|
||||
function Zabbix(url, options, backendSrv, datasourceSrv) {
|
||||
_classCallCheck(this, Zabbix);
|
||||
|
||||
var username = options.username,
|
||||
password = options.password,
|
||||
basicAuth = options.basicAuth,
|
||||
withCredentials = options.withCredentials,
|
||||
cacheTTL = options.cacheTTL,
|
||||
enableDirectDBConnection = options.enableDirectDBConnection,
|
||||
sqlDatasourceId = options.sqlDatasourceId;
|
||||
|
||||
|
||||
// Initialize Zabbix API
|
||||
this.zabbixAPI = new ZabbixAPIConnector(url, username, password, basicAuth, withCredentials, backendSrv);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.dbConnector = new ZabbixDBConnector(sqlDatasourceId, {}, backendSrv, datasourceSrv);
|
||||
}
|
||||
|
||||
// Initialize caching proxy for requests
|
||||
var cacheOptions = {
|
||||
enabled: true,
|
||||
ttl: cacheTTL
|
||||
};
|
||||
this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, this.dbConnector, cacheOptions);
|
||||
|
||||
// Proxy methods
|
||||
this.getHistory = this.cachingProxy.getHistory.bind(this.cachingProxy);
|
||||
this.getMacros = this.cachingProxy.getMacros.bind(this.cachingProxy);
|
||||
this.getItemsByIDs = this.cachingProxy.getItemsByIDs.bind(this.cachingProxy);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.getHistoryDB = this.cachingProxy.getHistoryDB.bind(this.cachingProxy);
|
||||
this.getTrendsDB = this.cachingProxy.getTrendsDB.bind(this.cachingProxy);
|
||||
}
|
||||
|
||||
this.getTrend = this.zabbixAPI.getTrend.bind(this.zabbixAPI);
|
||||
this.getEvents = this.zabbixAPI.getEvents.bind(this.zabbixAPI);
|
||||
this.getAlerts = this.zabbixAPI.getAlerts.bind(this.zabbixAPI);
|
||||
this.getHostAlerts = this.zabbixAPI.getHostAlerts.bind(this.zabbixAPI);
|
||||
this.getAcknowledges = this.zabbixAPI.getAcknowledges.bind(this.zabbixAPI);
|
||||
this.getITService = this.zabbixAPI.getITService.bind(this.zabbixAPI);
|
||||
this.getSLA = this.zabbixAPI.getSLA.bind(this.zabbixAPI);
|
||||
this.getVersion = this.zabbixAPI.getVersion.bind(this.zabbixAPI);
|
||||
this.login = this.zabbixAPI.login.bind(this.zabbixAPI);
|
||||
}
|
||||
|
||||
_createClass(Zabbix, [{
|
||||
key: 'getItemsFromTarget',
|
||||
value: function getItemsFromTarget(target, options) {
|
||||
var parts = ['group', 'host', 'application', 'item'];
|
||||
var filters = _.map(parts, function (p) {
|
||||
return target[p].filter;
|
||||
});
|
||||
return this.getItems.apply(this, _toConsumableArray(filters).concat([options]));
|
||||
}
|
||||
}, {
|
||||
key: 'getHostsFromTarget',
|
||||
value: function getHostsFromTarget(target) {
|
||||
var parts = ['group', 'host', 'application'];
|
||||
var filters = _.map(parts, function (p) {
|
||||
return target[p].filter;
|
||||
});
|
||||
return Promise.all([this.getHosts.apply(this, _toConsumableArray(filters)), this.getApps.apply(this, _toConsumableArray(filters))]).then(function (results) {
|
||||
var _results = _slicedToArray(results, 2),
|
||||
hosts = _results[0],
|
||||
apps = _results[1];
|
||||
|
||||
if (apps.appFilterEmpty) {
|
||||
apps = [];
|
||||
}
|
||||
return [hosts, apps];
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getAllGroups',
|
||||
value: function getAllGroups() {
|
||||
return this.cachingProxy.getGroups();
|
||||
}
|
||||
}, {
|
||||
key: 'getGroups',
|
||||
value: function getGroups(groupFilter) {
|
||||
return this.getAllGroups().then(function (groups) {
|
||||
return findByFilter(groups, groupFilter);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getAllHosts',
|
||||
value: function getAllHosts(groupFilter) {
|
||||
var _this = this;
|
||||
|
||||
return this.getGroups(groupFilter).then(function (groups) {
|
||||
var groupids = _.map(groups, 'groupid');
|
||||
return _this.cachingProxy.getHosts(groupids);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getHosts',
|
||||
value: function getHosts(groupFilter, hostFilter) {
|
||||
return this.getAllHosts(groupFilter).then(function (hosts) {
|
||||
return findByFilter(hosts, hostFilter);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getAllApps',
|
||||
value: function getAllApps(groupFilter, hostFilter) {
|
||||
var _this2 = this;
|
||||
|
||||
return this.getHosts(groupFilter, hostFilter).then(function (hosts) {
|
||||
var hostids = _.map(hosts, 'hostid');
|
||||
return _this2.cachingProxy.getApps(hostids);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getApps',
|
||||
value: function getApps(groupFilter, hostFilter, appFilter) {
|
||||
var _this3 = this;
|
||||
|
||||
return this.getHosts(groupFilter, hostFilter).then(function (hosts) {
|
||||
var hostids = _.map(hosts, 'hostid');
|
||||
if (appFilter) {
|
||||
return _this3.cachingProxy.getApps(hostids).then(function (apps) {
|
||||
return filterByQuery(apps, appFilter);
|
||||
});
|
||||
} else {
|
||||
return {
|
||||
appFilterEmpty: true,
|
||||
hostids: hostids
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getAllItems',
|
||||
value: function getAllItems(groupFilter, hostFilter, appFilter) {
|
||||
var _this4 = this;
|
||||
|
||||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
||||
|
||||
return this.getApps(groupFilter, hostFilter, appFilter).then(function (apps) {
|
||||
if (apps.appFilterEmpty) {
|
||||
return _this4.cachingProxy.getItems(apps.hostids, undefined, options.itemtype);
|
||||
} else {
|
||||
var appids = _.map(apps, 'applicationid');
|
||||
return _this4.cachingProxy.getItems(undefined, appids, options.itemtype);
|
||||
}
|
||||
}).then(function (items) {
|
||||
if (!options.showDisabledItems) {
|
||||
items = _.filter(items, { 'status': '0' });
|
||||
}
|
||||
|
||||
return items;
|
||||
}).then(this.expandUserMacro.bind(this));
|
||||
}
|
||||
}, {
|
||||
key: 'expandUserMacro',
|
||||
value: function expandUserMacro(items) {
|
||||
var hostids = getHostIds(items);
|
||||
return this.getMacros(hostids).then(function (macros) {
|
||||
_.forEach(items, function (item) {
|
||||
if (utils.containsMacro(item.name)) {
|
||||
item.name = utils.replaceMacro(item, macros);
|
||||
}
|
||||
});
|
||||
return items;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getItems',
|
||||
value: function getItems(groupFilter, hostFilter, appFilter, itemFilter) {
|
||||
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
||||
|
||||
return this.getAllItems(groupFilter, hostFilter, appFilter, options).then(function (items) {
|
||||
return filterByQuery(items, itemFilter);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getITServices',
|
||||
value: function getITServices(itServiceFilter) {
|
||||
return this.cachingProxy.getITServices().then(function (itServices) {
|
||||
return findByFilter(itServices, itServiceFilter);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getTriggers',
|
||||
value: function getTriggers(groupFilter, hostFilter, appFilter, options) {
|
||||
var _this5 = this;
|
||||
|
||||
var promises = [this.getGroups(groupFilter), this.getHosts(groupFilter, hostFilter), this.getApps(groupFilter, hostFilter, appFilter)];
|
||||
|
||||
return Promise.all(promises).then(function (results) {
|
||||
var filteredGroups = results[0];
|
||||
var filteredHosts = results[1];
|
||||
var filteredApps = results[2];
|
||||
var query = {};
|
||||
|
||||
if (appFilter) {
|
||||
query.applicationids = _.flatten(_.map(filteredApps, 'applicationid'));
|
||||
}
|
||||
if (hostFilter) {
|
||||
query.hostids = _.map(filteredHosts, 'hostid');
|
||||
}
|
||||
if (groupFilter) {
|
||||
query.groupids = _.map(filteredGroups, 'groupid');
|
||||
}
|
||||
|
||||
return query;
|
||||
}).then(function (query) {
|
||||
return _this5.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, options);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Zabbix;
|
||||
}());
|
||||
|
||||
_export('Zabbix', Zabbix);
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=zabbix.js.map
|
||||
1
dist/datasource-zabbix/zabbix/zabbix.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbix/zabbix.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user