refactor: move zabbix modules
This commit is contained in:
@@ -1,51 +1,56 @@
|
||||
import _ from 'lodash';
|
||||
import dataProcessor from '../dataProcessor';
|
||||
'use strict';
|
||||
|
||||
describe('dataProcessor', () => {
|
||||
let ctx = {};
|
||||
System.register(['lodash', '../dataProcessor'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.datapoints = [
|
||||
[[10, 1500000000000], [2, 1500000001000], [7, 1500000002000], [1, 1500000003000]],
|
||||
[[9, 1500000000000], [3, 1500000001000], [4, 1500000002000], [8, 1500000003000]],
|
||||
];
|
||||
});
|
||||
var _, dataProcessor;
|
||||
|
||||
describe('When apply groupBy() functions', () => {
|
||||
it('should return series average', () => {
|
||||
let aggregateBy = dataProcessor.metricFunctions['groupBy'];
|
||||
const avg2s = _.map(ctx.datapoints, (dp) => aggregateBy('2s', 'avg', dp));
|
||||
expect(avg2s).toEqual([
|
||||
[[6, 1500000000000], [4, 1500000002000]],
|
||||
[[6, 1500000000000], [6, 1500000002000]],
|
||||
]);
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}, function (_dataProcessor) {
|
||||
dataProcessor = _dataProcessor.default;
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
const avg10s = _.map(ctx.datapoints, (dp) => aggregateBy('10s', 'avg', dp));
|
||||
expect(avg10s).toEqual([
|
||||
[[5, 1500000000000]],
|
||||
[[6, 1500000000000]],
|
||||
]);
|
||||
describe('dataProcessor', function () {
|
||||
var ctx = {};
|
||||
|
||||
// not aligned
|
||||
const dp = [[10, 1500000001000], [2, 1500000002000], [7, 1500000003000], [1, 1500000004000]];
|
||||
expect(aggregateBy('2s', 'avg', dp)).toEqual([
|
||||
[10, 1500000000000], [4.5, 1500000002000], [1, 1500000004000]
|
||||
]);
|
||||
});
|
||||
});
|
||||
beforeEach(function () {
|
||||
ctx.datapoints = [[[10, 1500000000000], [2, 1500000001000], [7, 1500000002000], [1, 1500000003000]], [[9, 1500000000000], [3, 1500000001000], [4, 1500000002000], [8, 1500000003000]]];
|
||||
});
|
||||
|
||||
describe('When apply aggregateBy() functions', () => {
|
||||
it('should return series average', () => {
|
||||
let aggregateBy = dataProcessor.metricFunctions['aggregateBy'];
|
||||
const avg1s = aggregateBy('1s', 'avg', ctx.datapoints);
|
||||
expect(avg1s).toEqual([
|
||||
[9.5, 1500000000000], [2.5, 1500000001000], [5.5, 1500000002000], [4.5, 1500000003000]
|
||||
]);
|
||||
describe('When apply groupBy() functions', function () {
|
||||
it('should return series average', function () {
|
||||
var aggregateBy = dataProcessor.metricFunctions['groupBy'];
|
||||
var avg2s = _.map(ctx.datapoints, function (dp) {
|
||||
return aggregateBy('2s', 'avg', dp);
|
||||
});
|
||||
expect(avg2s).toEqual([[[6, 1500000000000], [4, 1500000002000]], [[6, 1500000000000], [6, 1500000002000]]]);
|
||||
|
||||
const avg10s = aggregateBy('10s', 'avg', ctx.datapoints);
|
||||
expect(avg10s).toEqual([
|
||||
[5.5, 1500000000000]
|
||||
]);
|
||||
});
|
||||
});
|
||||
var avg10s = _.map(ctx.datapoints, function (dp) {
|
||||
return aggregateBy('10s', 'avg', dp);
|
||||
});
|
||||
expect(avg10s).toEqual([[[5, 1500000000000]], [[6, 1500000000000]]]);
|
||||
|
||||
// not aligned
|
||||
var dp = [[10, 1500000001000], [2, 1500000002000], [7, 1500000003000], [1, 1500000004000]];
|
||||
expect(aggregateBy('2s', 'avg', dp)).toEqual([[10, 1500000000000], [4.5, 1500000002000], [1, 1500000004000]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When apply aggregateBy() functions', function () {
|
||||
it('should return series average', function () {
|
||||
var aggregateBy = dataProcessor.metricFunctions['aggregateBy'];
|
||||
var avg1s = aggregateBy('1s', 'avg', ctx.datapoints);
|
||||
expect(avg1s).toEqual([[9.5, 1500000000000], [2.5, 1500000001000], [5.5, 1500000002000], [4.5, 1500000003000]]);
|
||||
|
||||
var avg10s = aggregateBy('10s', 'avg', ctx.datapoints);
|
||||
expect(avg10s).toEqual([[5.5, 1500000000000]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=dataProcessor.spec.js.map
|
||||
|
||||
1
dist/datasource-zabbix/specs/dataProcessor.spec.js.map
vendored
Normal file
1
dist/datasource-zabbix/specs/dataProcessor.spec.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/datasource-zabbix/specs/dataProcessor.spec.js"],"names":["_","dataProcessor","describe","ctx","beforeEach","datapoints","it","aggregateBy","metricFunctions","avg2s","map","dp","expect","toEqual","avg10s","avg1s"],"mappings":";;;;;;;;;AAAOA,O;;AACAC,mB;;;;AAEPC,eAAS,eAAT,EAA0B,YAAM;AAC9B,YAAIC,MAAM,EAAV;;AAEAC,mBAAW,YAAM;AACfD,cAAIE,UAAJ,GAAiB,CACf,CAAC,CAAC,EAAD,EAAK,aAAL,CAAD,EAAsB,CAAC,CAAD,EAAI,aAAJ,CAAtB,EAA0C,CAAC,CAAD,EAAI,aAAJ,CAA1C,EAA8D,CAAC,CAAD,EAAI,aAAJ,CAA9D,CADe,EAEf,CAAC,CAAC,CAAD,EAAI,aAAJ,CAAD,EAAsB,CAAC,CAAD,EAAI,aAAJ,CAAtB,EAA0C,CAAC,CAAD,EAAI,aAAJ,CAA1C,EAA8D,CAAC,CAAD,EAAI,aAAJ,CAA9D,CAFe,CAAjB;AAID,SALD;;AAOAH,iBAAS,gCAAT,EAA2C,YAAM;AAC/CI,aAAG,8BAAH,EAAmC,YAAM;AACvC,gBAAIC,cAAcN,cAAcO,eAAd,CAA8B,SAA9B,CAAlB;AACA,gBAAMC,QAAQT,EAAEU,GAAF,CAAMP,IAAIE,UAAV,EAAsB,UAACM,EAAD;AAAA,qBAAQJ,YAAY,IAAZ,EAAkB,KAAlB,EAAyBI,EAAzB,CAAR;AAAA,aAAtB,CAAd;AACAC,mBAAOH,KAAP,EAAcI,OAAd,CAAsB,CACpB,CAAC,CAAC,CAAD,EAAI,aAAJ,CAAD,EAAqB,CAAC,CAAD,EAAI,aAAJ,CAArB,CADoB,EAEpB,CAAC,CAAC,CAAD,EAAI,aAAJ,CAAD,EAAqB,CAAC,CAAD,EAAI,aAAJ,CAArB,CAFoB,CAAtB;;AAKA,gBAAMC,SAASd,EAAEU,GAAF,CAAMP,IAAIE,UAAV,EAAsB,UAACM,EAAD;AAAA,qBAAQJ,YAAY,KAAZ,EAAmB,KAAnB,EAA0BI,EAA1B,CAAR;AAAA,aAAtB,CAAf;AACAC,mBAAOE,MAAP,EAAeD,OAAf,CAAuB,CACrB,CAAC,CAAC,CAAD,EAAI,aAAJ,CAAD,CADqB,EAErB,CAAC,CAAC,CAAD,EAAI,aAAJ,CAAD,CAFqB,CAAvB;;AAKA;AACA,gBAAMF,KAAK,CAAC,CAAC,EAAD,EAAK,aAAL,CAAD,EAAsB,CAAC,CAAD,EAAI,aAAJ,CAAtB,EAA0C,CAAC,CAAD,EAAI,aAAJ,CAA1C,EAA8D,CAAC,CAAD,EAAI,aAAJ,CAA9D,CAAX;AACAC,mBAAOL,YAAY,IAAZ,EAAkB,KAAlB,EAAyBI,EAAzB,CAAP,EAAqCE,OAArC,CAA6C,CAC3C,CAAC,EAAD,EAAK,aAAL,CAD2C,EACtB,CAAC,GAAD,EAAM,aAAN,CADsB,EACA,CAAC,CAAD,EAAI,aAAJ,CADA,CAA7C;AAGD,WAnBD;AAoBD,SArBD;;AAuBAX,iBAAS,oCAAT,EAA+C,YAAM;AACnDI,aAAG,8BAAH,EAAmC,YAAM;AACvC,gBAAIC,cAAcN,cAAcO,eAAd,CAA8B,aAA9B,CAAlB;AACA,gBAAMO,QAAQR,YAAY,IAAZ,EAAkB,KAAlB,EAAyBJ,IAAIE,UAA7B,CAAd;AACAO,mBAAOG,KAAP,EAAcF,OAAd,CAAsB,CACpB,CAAC,GAAD,EAAM,aAAN,CADoB,EACE,CAAC,GAAD,EAAM,aAAN,CADF,EACwB,CAAC,GAAD,EAAM,aAAN,CADxB,EAC8C,CAAC,GAAD,EAAM,aAAN,CAD9C,CAAtB;;AAIA,gBAAMC,SAASP,YAAY,KAAZ,EAAmB,KAAnB,EAA0BJ,IAAIE,UAA9B,CAAf;AACAO,mBAAOE,MAAP,EAAeD,OAAf,CAAuB,CACrB,CAAC,GAAD,EAAM,aAAN,CADqB,CAAvB;AAGD,WAXD;AAYD,SAbD;AAcD,OA/CD","file":"dataProcessor.spec.js","sourcesContent":["import _ from 'lodash';\nimport dataProcessor from '../dataProcessor';\n\ndescribe('dataProcessor', () => {\n let ctx = {};\n\n beforeEach(() => {\n ctx.datapoints = [\n [[10, 1500000000000], [2, 1500000001000], [7, 1500000002000], [1, 1500000003000]],\n [[9, 1500000000000], [3, 1500000001000], [4, 1500000002000], [8, 1500000003000]],\n ];\n });\n\n describe('When apply groupBy() functions', () => {\n it('should return series average', () => {\n let aggregateBy = dataProcessor.metricFunctions['groupBy'];\n const avg2s = _.map(ctx.datapoints, (dp) => aggregateBy('2s', 'avg', dp));\n expect(avg2s).toEqual([\n [[6, 1500000000000], [4, 1500000002000]],\n [[6, 1500000000000], [6, 1500000002000]],\n ]);\n\n const avg10s = _.map(ctx.datapoints, (dp) => aggregateBy('10s', 'avg', dp));\n expect(avg10s).toEqual([\n [[5, 1500000000000]],\n [[6, 1500000000000]],\n ]);\n\n // not aligned\n const dp = [[10, 1500000001000], [2, 1500000002000], [7, 1500000003000], [1, 1500000004000]];\n expect(aggregateBy('2s', 'avg', dp)).toEqual([\n [10, 1500000000000], [4.5, 1500000002000], [1, 1500000004000]\n ]);\n });\n });\n\n describe('When apply aggregateBy() functions', () => {\n it('should return series average', () => {\n let aggregateBy = dataProcessor.metricFunctions['aggregateBy'];\n const avg1s = aggregateBy('1s', 'avg', ctx.datapoints);\n expect(avg1s).toEqual([\n [9.5, 1500000000000], [2.5, 1500000001000], [5.5, 1500000002000], [4.5, 1500000003000]\n ]);\n\n const avg10s = aggregateBy('10s', 'avg', ctx.datapoints);\n expect(avg10s).toEqual([\n [5.5, 1500000000000]\n ]);\n });\n });\n});\n"]}
|
||||
914
dist/datasource-zabbix/specs/datasource.spec.js
vendored
914
dist/datasource-zabbix/specs/datasource.spec.js
vendored
@@ -1,429 +1,509 @@
|
||||
import _ from 'lodash';
|
||||
import Q, { Promise } from "q";
|
||||
import {Datasource} from "../module";
|
||||
import {zabbixTemplateFormat} from "../datasource";
|
||||
"use strict";
|
||||
|
||||
describe('ZabbixDatasource', () => {
|
||||
let ctx = {};
|
||||
System.register(["lodash", "q", "../module", "../datasource"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: {
|
||||
alerting: true,
|
||||
username: 'zabbix',
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
trendsFrom: '14d',
|
||||
trendsRange: '7d',
|
||||
dbConnection: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
};
|
||||
ctx.templateSrv = {};
|
||||
ctx.alertSrv = {};
|
||||
ctx.dashboardSrv = {};
|
||||
ctx.zabbixAlertingSrv = {
|
||||
setPanelAlertState: jest.fn(),
|
||||
removeZabbixThreshold: jest.fn(),
|
||||
};
|
||||
ctx.zabbix = () => {};
|
||||
var _, Q, Promise, Datasource, zabbixTemplateFormat;
|
||||
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.alertSrv, ctx.dashboardSrv, ctx.zabbixAlertingSrv, ctx.zabbix);
|
||||
});
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}, function (_q) {
|
||||
Q = _q.default;
|
||||
Promise = _q.Promise;
|
||||
}, function (_module) {
|
||||
Datasource = _module.Datasource;
|
||||
}, function (_datasource) {
|
||||
zabbixTemplateFormat = _datasource.zabbixTemplateFormat;
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
describe('When querying data', () => {
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
ctx.ds.alertQuery = () => Q.when([]);
|
||||
});
|
||||
describe('ZabbixDatasource', function () {
|
||||
var ctx = {};
|
||||
|
||||
ctx.options = {
|
||||
targets: [
|
||||
{
|
||||
group: {filter: ""},
|
||||
host: {filter: ""},
|
||||
application: {filter: ""},
|
||||
item: {filter: ""}
|
||||
}
|
||||
],
|
||||
range: {from: 'now-7d', to: 'now'}
|
||||
};
|
||||
|
||||
it('should return an empty array when no targets are set', (done) => {
|
||||
let options = {
|
||||
targets: [],
|
||||
range: {from: 'now-6h', to: 'now'}
|
||||
};
|
||||
ctx.ds.query(options).then(result => {
|
||||
expect(result.data.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should use trends if it enabled and time more than trendsFrom', (done) => {
|
||||
let ranges = ['now-7d', 'now-168h', 'now-1M', 'now-1y'];
|
||||
|
||||
_.forEach(ranges, range => {
|
||||
ctx.options.range.from = range;
|
||||
ctx.ds.queryNumericData = jest.fn();
|
||||
ctx.ds.query(ctx.options);
|
||||
|
||||
// Check that useTrends options is true
|
||||
let callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||
expect(callArgs[2]).toBe(true);
|
||||
ctx.ds.queryNumericData.mockClear();
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('shouldnt use trends if it enabled and time less than trendsFrom', (done) => {
|
||||
let ranges = ['now-6d', 'now-167h', 'now-1h', 'now-30m', 'now-30s'];
|
||||
|
||||
_.forEach(ranges, range => {
|
||||
ctx.options.range.from = range;
|
||||
ctx.ds.queryNumericData = jest.fn();
|
||||
ctx.ds.query(ctx.options);
|
||||
|
||||
// Check that useTrends options is false
|
||||
let callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||
expect(callArgs[2]).toBe(false);
|
||||
ctx.ds.queryNumericData.mockClear();
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('When querying text data', () => {
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
ctx.ds.alertQuery = () => Q.when([]);
|
||||
ctx.ds.zabbix.getHistory = jest.fn().mockReturnValue(Promise.resolve([
|
||||
{clock: "1500010200", itemid:"10100", ns:"900111000", value:"Linux first"},
|
||||
{clock: "1500010300", itemid:"10100", ns:"900111000", value:"Linux 2nd"},
|
||||
{clock: "1500010400", itemid:"10100", ns:"900111000", value:"Linux last"}
|
||||
]));
|
||||
|
||||
ctx.ds.zabbix.getItemsFromTarget = jest.fn().mockReturnValue(Promise.resolve([
|
||||
{
|
||||
hosts: [{hostid: "10001", name: "Zabbix server"}],
|
||||
itemid: "10100",
|
||||
name: "System information",
|
||||
key_: "system.uname",
|
||||
}
|
||||
]));
|
||||
|
||||
ctx.options = {
|
||||
range: {from: 'now-1h', to: 'now'},
|
||||
targets: [
|
||||
{
|
||||
group: {filter: ""},
|
||||
host: {filter: "Zabbix server"},
|
||||
application: {filter: ""},
|
||||
item: {filter: "System information"},
|
||||
textFilter: "",
|
||||
useCaptureGroups: true,
|
||||
mode: 2,
|
||||
resultFormat: "table",
|
||||
options: {
|
||||
skipEmptyValues: false
|
||||
beforeEach(function () {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: {
|
||||
alerting: true,
|
||||
username: 'zabbix',
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
trendsFrom: '14d',
|
||||
trendsRange: '7d',
|
||||
dbConnection: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
};
|
||||
ctx.templateSrv = {};
|
||||
ctx.alertSrv = {};
|
||||
ctx.dashboardSrv = {};
|
||||
ctx.zabbixAlertingSrv = {
|
||||
setPanelAlertState: jest.fn(),
|
||||
removeZabbixThreshold: jest.fn()
|
||||
};
|
||||
ctx.zabbix = function () {};
|
||||
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.alertSrv, ctx.dashboardSrv, ctx.zabbixAlertingSrv, ctx.zabbix);
|
||||
});
|
||||
|
||||
describe('When querying data', function () {
|
||||
beforeEach(function () {
|
||||
ctx.ds.replaceTemplateVars = function (str) {
|
||||
return str;
|
||||
};
|
||||
ctx.ds.alertQuery = function () {
|
||||
return Q.when([]);
|
||||
};
|
||||
});
|
||||
|
||||
ctx.options = {
|
||||
targets: [{
|
||||
group: { filter: "" },
|
||||
host: { filter: "" },
|
||||
application: { filter: "" },
|
||||
item: { filter: "" }
|
||||
}],
|
||||
range: { from: 'now-7d', to: 'now' }
|
||||
};
|
||||
|
||||
it('should return an empty array when no targets are set', function (done) {
|
||||
var options = {
|
||||
targets: [],
|
||||
range: { from: 'now-6h', to: 'now' }
|
||||
};
|
||||
ctx.ds.query(options).then(function (result) {
|
||||
expect(result.data.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should use trends if it enabled and time more than trendsFrom', function (done) {
|
||||
var ranges = ['now-7d', 'now-168h', 'now-1M', 'now-1y'];
|
||||
|
||||
_.forEach(ranges, function (range) {
|
||||
ctx.options.range.from = range;
|
||||
ctx.ds.queryNumericData = jest.fn();
|
||||
ctx.ds.query(ctx.options);
|
||||
|
||||
// Check that useTrends options is true
|
||||
var callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||
expect(callArgs[2]).toBe(true);
|
||||
ctx.ds.queryNumericData.mockClear();
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('shouldnt use trends if it enabled and time less than trendsFrom', function (done) {
|
||||
var ranges = ['now-6d', 'now-167h', 'now-1h', 'now-30m', 'now-30s'];
|
||||
|
||||
_.forEach(ranges, function (range) {
|
||||
ctx.options.range.from = range;
|
||||
ctx.ds.queryNumericData = jest.fn();
|
||||
ctx.ds.query(ctx.options);
|
||||
|
||||
// Check that useTrends options is false
|
||||
var callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||
expect(callArgs[2]).toBe(false);
|
||||
ctx.ds.queryNumericData.mockClear();
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When querying text data', function () {
|
||||
beforeEach(function () {
|
||||
ctx.ds.replaceTemplateVars = function (str) {
|
||||
return str;
|
||||
};
|
||||
ctx.ds.alertQuery = function () {
|
||||
return Q.when([]);
|
||||
};
|
||||
ctx.ds.zabbix.getHistory = jest.fn().mockReturnValue(Promise.resolve([{ clock: "1500010200", itemid: "10100", ns: "900111000", value: "Linux first" }, { clock: "1500010300", itemid: "10100", ns: "900111000", value: "Linux 2nd" }, { clock: "1500010400", itemid: "10100", ns: "900111000", value: "Linux last" }]));
|
||||
|
||||
ctx.ds.zabbix.getItemsFromTarget = jest.fn().mockReturnValue(Promise.resolve([{
|
||||
hosts: [{ hostid: "10001", name: "Zabbix server" }],
|
||||
itemid: "10100",
|
||||
name: "System information",
|
||||
key_: "system.uname"
|
||||
}]));
|
||||
|
||||
ctx.options = {
|
||||
range: { from: 'now-1h', to: 'now' },
|
||||
targets: [{
|
||||
group: { filter: "" },
|
||||
host: { filter: "Zabbix server" },
|
||||
application: { filter: "" },
|
||||
item: { filter: "System information" },
|
||||
textFilter: "",
|
||||
useCaptureGroups: true,
|
||||
mode: 2,
|
||||
resultFormat: "table",
|
||||
options: {
|
||||
skipEmptyValues: false
|
||||
}
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
it('should return data in table format', function (done) {
|
||||
ctx.ds.query(ctx.options).then(function (result) {
|
||||
expect(result.data.length).toBe(1);
|
||||
|
||||
var tableData = result.data[0];
|
||||
expect(tableData.columns).toEqual([{ text: 'Host' }, { text: 'Item' }, { text: 'Key' }, { text: 'Last value' }]);
|
||||
expect(tableData.rows).toEqual([['Zabbix server', 'System information', 'system.uname', 'Linux last']]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should extract value if regex with capture group is used', function (done) {
|
||||
ctx.options.targets[0].textFilter = "Linux (.*)";
|
||||
ctx.ds.query(ctx.options).then(function (result) {
|
||||
var tableData = result.data[0];
|
||||
expect(tableData.rows[0][3]).toEqual('last');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should skip item when last value is empty', function () {
|
||||
ctx.ds.zabbix.getItemsFromTarget = jest.fn().mockReturnValue(Promise.resolve([{
|
||||
hosts: [{ hostid: "10001", name: "Zabbix server" }],
|
||||
itemid: "10100", name: "System information", key_: "system.uname"
|
||||
}, {
|
||||
hosts: [{ hostid: "10002", name: "Server02" }],
|
||||
itemid: "90109", name: "System information", key_: "system.uname"
|
||||
}]));
|
||||
|
||||
ctx.options.targets[0].options.skipEmptyValues = true;
|
||||
ctx.ds.zabbix.getHistory = jest.fn().mockReturnValue(Promise.resolve([{ clock: "1500010200", itemid: "10100", ns: "900111000", value: "Linux first" }, { clock: "1500010300", itemid: "10100", ns: "900111000", value: "Linux 2nd" }, { clock: "1500010400", itemid: "10100", ns: "900111000", value: "Linux last" }, { clock: "1500010200", itemid: "90109", ns: "900111000", value: "Non empty value" }, { clock: "1500010500", itemid: "90109", ns: "900111000", value: "" }]));
|
||||
return ctx.ds.query(ctx.options).then(function (result) {
|
||||
var tableData = result.data[0];
|
||||
expect(tableData.rows.length).toBe(1);
|
||||
expect(tableData.rows[0][3]).toEqual('Linux last');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('When replacing template variables', function () {
|
||||
|
||||
function testReplacingVariable(target, varValue, expectedResult, done) {
|
||||
ctx.ds.templateSrv.replace = function () {
|
||||
return zabbixTemplateFormat(varValue);
|
||||
};
|
||||
|
||||
var result = ctx.ds.replaceTemplateVars(target);
|
||||
expect(result).toBe(expectedResult);
|
||||
done();
|
||||
}
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
it('should return data in table format', (done) => {
|
||||
ctx.ds.query(ctx.options).then(result => {
|
||||
expect(result.data.length).toBe(1);
|
||||
/*
|
||||
* Alphanumerics, spaces, dots, dashes and underscores
|
||||
* are allowed in Zabbix host name.
|
||||
* 'AaBbCc0123 .-_'
|
||||
*/
|
||||
it('should return properly escaped regex', function (done) {
|
||||
var target = '$host';
|
||||
var template_var_value = 'AaBbCc0123 .-_';
|
||||
var expected_result = '/^AaBbCc0123 \\.-_$/';
|
||||
|
||||
let tableData = result.data[0];
|
||||
expect(tableData.columns).toEqual([
|
||||
{text: 'Host'}, {text: 'Item'}, {text: 'Key'}, {text: 'Last value'}
|
||||
]);
|
||||
expect(tableData.rows).toEqual([
|
||||
['Zabbix server', 'System information', 'system.uname', 'Linux last']
|
||||
]);
|
||||
done();
|
||||
testReplacingVariable(target, template_var_value, expected_result, done);
|
||||
});
|
||||
|
||||
/*
|
||||
* Single-value variable
|
||||
* $host = backend01
|
||||
* $host => /^backend01|backend01$/
|
||||
*/
|
||||
it('should return proper regex for single value', function (done) {
|
||||
var target = '$host';
|
||||
var template_var_value = 'backend01';
|
||||
var expected_result = '/^backend01$/';
|
||||
|
||||
testReplacingVariable(target, template_var_value, expected_result, done);
|
||||
});
|
||||
|
||||
/*
|
||||
* Multi-value variable
|
||||
* $host = [backend01, backend02]
|
||||
* $host => /^(backend01|backend01)$/
|
||||
*/
|
||||
it('should return proper regex for multi-value', function (done) {
|
||||
var target = '$host';
|
||||
var template_var_value = ['backend01', 'backend02'];
|
||||
var expected_result = '/^(backend01|backend02)$/';
|
||||
|
||||
testReplacingVariable(target, template_var_value, expected_result, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When invoking metricFindQuery()', function () {
|
||||
beforeEach(function () {
|
||||
ctx.ds.replaceTemplateVars = function (str) {
|
||||
return str;
|
||||
};
|
||||
ctx.ds.zabbix = {
|
||||
getGroups: jest.fn().mockReturnValue(Q.when([])),
|
||||
getHosts: jest.fn().mockReturnValue(Q.when([])),
|
||||
getApps: jest.fn().mockReturnValue(Q.when([])),
|
||||
getItems: jest.fn().mockReturnValue(Q.when([]))
|
||||
};
|
||||
});
|
||||
|
||||
it('should return groups', function (done) {
|
||||
var tests = [{ query: '*', expect: '/.*/' }, { query: '', expect: '' }, { query: 'Backend', expect: 'Backend' }, { query: 'Back*', expect: 'Back*' }];
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = tests[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var test = _step.value;
|
||||
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getGroups).toBeCalledWith(test.expect);
|
||||
ctx.ds.zabbix.getGroups.mockClear();
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return hosts', function (done) {
|
||||
var tests = [{ query: '*.*', expect: ['/.*/', '/.*/'] }, { query: '.', expect: ['', ''] }, { query: 'Backend.*', expect: ['Backend', '/.*/'] }, { query: 'Back*.', expect: ['Back*', ''] }];
|
||||
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = tests[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var test = _step2.value;
|
||||
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getHosts).toBeCalledWith(test.expect[0], test.expect[1]);
|
||||
ctx.ds.zabbix.getHosts.mockClear();
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return applications', function (done) {
|
||||
var tests = [{ query: '*.*.*', expect: ['/.*/', '/.*/', '/.*/'] }, { query: '.*.', expect: ['', '/.*/', ''] }, { query: 'Backend.backend01.*', expect: ['Backend', 'backend01', '/.*/'] }, { query: 'Back*.*.', expect: ['Back*', '/.*/', ''] }];
|
||||
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator3 = tests[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
var test = _step3.value;
|
||||
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getApps).toBeCalledWith(test.expect[0], test.expect[1], test.expect[2]);
|
||||
ctx.ds.zabbix.getApps.mockClear();
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
||||
_iterator3.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return items', function (done) {
|
||||
var tests = [{ query: '*.*.*.*', expect: ['/.*/', '/.*/', '', '/.*/'] }, { query: '.*.*.*', expect: ['', '/.*/', '', '/.*/'] }, { query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', '', '/.*/'] }, { query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu', '/.*/'] }];
|
||||
|
||||
var _iteratorNormalCompletion4 = true;
|
||||
var _didIteratorError4 = false;
|
||||
var _iteratorError4 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator4 = tests[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
||||
var test = _step4.value;
|
||||
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getItems).toBeCalledWith(test.expect[0], test.expect[1], test.expect[2], test.expect[3]);
|
||||
ctx.ds.zabbix.getItems.mockClear();
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError4 = true;
|
||||
_iteratorError4 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
||||
_iterator4.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError4) {
|
||||
throw _iteratorError4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should invoke method with proper arguments', function (done) {
|
||||
var query = '*.*';
|
||||
|
||||
ctx.ds.metricFindQuery(query);
|
||||
expect(ctx.ds.zabbix.getHosts).toBeCalledWith('/.*/', '/.*/');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When querying alerts', function () {
|
||||
var options = {};
|
||||
|
||||
beforeEach(function () {
|
||||
ctx.ds.replaceTemplateVars = function (str) {
|
||||
return str;
|
||||
};
|
||||
|
||||
var targetItems = [{
|
||||
"itemid": "1",
|
||||
"name": "test item",
|
||||
"key_": "test.key",
|
||||
"value_type": "3",
|
||||
"hostid": "10631",
|
||||
"status": "0",
|
||||
"state": "0",
|
||||
"hosts": [{ "hostid": "10631", "name": "Test host" }],
|
||||
"item": "Test item"
|
||||
}];
|
||||
ctx.ds.zabbix.getItemsFromTarget = function () {
|
||||
return Promise.resolve(targetItems);
|
||||
};
|
||||
|
||||
options = {
|
||||
"panelId": 10,
|
||||
"targets": [{
|
||||
"application": { "filter": "" },
|
||||
"group": { "filter": "Test group" },
|
||||
"host": { "filter": "Test host" },
|
||||
"item": { "filter": "Test item" }
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `less than`', function () {
|
||||
|
||||
var itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}<100"
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = function () {
|
||||
return Promise.resolve(itemTriggers);
|
||||
};
|
||||
|
||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||
expect(resp.thresholds).toHaveLength(1);
|
||||
expect(resp.thresholds[0]).toBe(100);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `less than or equal`', function () {
|
||||
|
||||
var itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}<=100"
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = function () {
|
||||
return Promise.resolve(itemTriggers);
|
||||
};
|
||||
|
||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||
expect(resp.thresholds.length).toBe(1);
|
||||
expect(resp.thresholds[0]).toBe(100);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `greater than or equal`', function () {
|
||||
|
||||
var itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}>=30"
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = function () {
|
||||
return Promise.resolve(itemTriggers);
|
||||
};
|
||||
|
||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||
expect(resp.thresholds.length).toBe(1);
|
||||
expect(resp.thresholds[0]).toBe(30);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `equal`', function () {
|
||||
|
||||
var itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}=50"
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = function () {
|
||||
return Promise.resolve(itemTriggers);
|
||||
};
|
||||
|
||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||
expect(resp.thresholds.length).toBe(1);
|
||||
expect(resp.thresholds[0]).toBe(50);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should extract value if regex with capture group is used', (done) => {
|
||||
ctx.options.targets[0].textFilter = "Linux (.*)";
|
||||
ctx.ds.query(ctx.options).then(result => {
|
||||
let tableData = result.data[0];
|
||||
expect(tableData.rows[0][3]).toEqual('last');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should skip item when last value is empty', () => {
|
||||
ctx.ds.zabbix.getItemsFromTarget = jest.fn().mockReturnValue(Promise.resolve([
|
||||
{
|
||||
hosts: [{hostid: "10001", name: "Zabbix server"}],
|
||||
itemid: "10100", name: "System information", key_: "system.uname"
|
||||
},
|
||||
{
|
||||
hosts: [{hostid: "10002", name: "Server02"}],
|
||||
itemid: "90109", name: "System information", key_: "system.uname"
|
||||
}
|
||||
]));
|
||||
|
||||
ctx.options.targets[0].options.skipEmptyValues = true;
|
||||
ctx.ds.zabbix.getHistory = jest.fn().mockReturnValue(Promise.resolve([
|
||||
{clock: "1500010200", itemid:"10100", ns:"900111000", value:"Linux first"},
|
||||
{clock: "1500010300", itemid:"10100", ns:"900111000", value:"Linux 2nd"},
|
||||
{clock: "1500010400", itemid:"10100", ns:"900111000", value:"Linux last"},
|
||||
{clock: "1500010200", itemid:"90109", ns:"900111000", value:"Non empty value"},
|
||||
{clock: "1500010500", itemid:"90109", ns:"900111000", value:""}
|
||||
]));
|
||||
return ctx.ds.query(ctx.options).then(result => {
|
||||
let tableData = result.data[0];
|
||||
expect(tableData.rows.length).toBe(1);
|
||||
expect(tableData.rows[0][3]).toEqual('Linux last');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('When replacing template variables', () => {
|
||||
|
||||
function testReplacingVariable(target, varValue, expectedResult, done) {
|
||||
ctx.ds.templateSrv.replace = () => {
|
||||
return zabbixTemplateFormat(varValue);
|
||||
};
|
||||
|
||||
let result = ctx.ds.replaceTemplateVars(target);
|
||||
expect(result).toBe(expectedResult);
|
||||
done();
|
||||
}
|
||||
|
||||
/*
|
||||
* Alphanumerics, spaces, dots, dashes and underscores
|
||||
* are allowed in Zabbix host name.
|
||||
* 'AaBbCc0123 .-_'
|
||||
*/
|
||||
it('should return properly escaped regex', (done) => {
|
||||
let target = '$host';
|
||||
let template_var_value = 'AaBbCc0123 .-_';
|
||||
let expected_result = '/^AaBbCc0123 \\.-_$/';
|
||||
|
||||
testReplacingVariable(target, template_var_value, expected_result, done);
|
||||
});
|
||||
|
||||
/*
|
||||
* Single-value variable
|
||||
* $host = backend01
|
||||
* $host => /^backend01|backend01$/
|
||||
*/
|
||||
it('should return proper regex for single value', (done) => {
|
||||
let target = '$host';
|
||||
let template_var_value = 'backend01';
|
||||
let expected_result = '/^backend01$/';
|
||||
|
||||
testReplacingVariable(target, template_var_value, expected_result, done);
|
||||
});
|
||||
|
||||
/*
|
||||
* Multi-value variable
|
||||
* $host = [backend01, backend02]
|
||||
* $host => /^(backend01|backend01)$/
|
||||
*/
|
||||
it('should return proper regex for multi-value', (done) => {
|
||||
let target = '$host';
|
||||
let template_var_value = ['backend01', 'backend02'];
|
||||
let expected_result = '/^(backend01|backend02)$/';
|
||||
|
||||
testReplacingVariable(target, template_var_value, expected_result, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When invoking metricFindQuery()', () => {
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
ctx.ds.zabbix = {
|
||||
getGroups: jest.fn().mockReturnValue(Q.when([])),
|
||||
getHosts: jest.fn().mockReturnValue(Q.when([])),
|
||||
getApps: jest.fn().mockReturnValue(Q.when([])),
|
||||
getItems: jest.fn().mockReturnValue(Q.when([]))
|
||||
};
|
||||
});
|
||||
|
||||
it('should return groups', (done) => {
|
||||
const tests = [
|
||||
{query: '*', expect: '/.*/'},
|
||||
{query: '', expect: ''},
|
||||
{query: 'Backend', expect: 'Backend'},
|
||||
{query: 'Back*', expect: 'Back*'},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getGroups).toBeCalledWith(test.expect);
|
||||
ctx.ds.zabbix.getGroups.mockClear();
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return hosts', (done) => {
|
||||
const tests = [
|
||||
{query: '*.*', expect: ['/.*/', '/.*/']},
|
||||
{query: '.', expect: ['', '']},
|
||||
{query: 'Backend.*', expect: ['Backend', '/.*/']},
|
||||
{query: 'Back*.', expect: ['Back*', '']},
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getHosts).toBeCalledWith(test.expect[0], test.expect[1]);
|
||||
ctx.ds.zabbix.getHosts.mockClear();
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return applications', (done) => {
|
||||
const tests = [
|
||||
{query: '*.*.*', expect: ['/.*/', '/.*/', '/.*/']},
|
||||
{query: '.*.', expect: ['', '/.*/', '']},
|
||||
{query: 'Backend.backend01.*', expect: ['Backend', 'backend01', '/.*/']},
|
||||
{query: 'Back*.*.', expect: ['Back*', '/.*/', '']}
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getApps).toBeCalledWith(test.expect[0], test.expect[1], test.expect[2]);
|
||||
ctx.ds.zabbix.getApps.mockClear();
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return items', (done) => {
|
||||
const tests = [
|
||||
{query: '*.*.*.*', expect: ['/.*/', '/.*/', '', '/.*/']},
|
||||
{query: '.*.*.*', expect: ['', '/.*/', '', '/.*/']},
|
||||
{query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', '', '/.*/']},
|
||||
{query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu', '/.*/']}
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
ctx.ds.metricFindQuery(test.query);
|
||||
expect(ctx.ds.zabbix.getItems)
|
||||
.toBeCalledWith(test.expect[0], test.expect[1], test.expect[2], test.expect[3]);
|
||||
ctx.ds.zabbix.getItems.mockClear();
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
it('should invoke method with proper arguments', (done) => {
|
||||
let query = '*.*';
|
||||
|
||||
ctx.ds.metricFindQuery(query);
|
||||
expect(ctx.ds.zabbix.getHosts).toBeCalledWith('/.*/', '/.*/');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When querying alerts', () => {
|
||||
let options = {};
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
|
||||
let targetItems = [{
|
||||
"itemid": "1",
|
||||
"name": "test item",
|
||||
"key_": "test.key",
|
||||
"value_type": "3",
|
||||
"hostid": "10631",
|
||||
"status": "0",
|
||||
"state": "0",
|
||||
"hosts": [{"hostid": "10631", "name": "Test host"}],
|
||||
"item": "Test item"
|
||||
}];
|
||||
ctx.ds.zabbix.getItemsFromTarget = () => Promise.resolve(targetItems);
|
||||
|
||||
options = {
|
||||
"panelId": 10,
|
||||
"targets": [{
|
||||
"application": {"filter": ""},
|
||||
"group": {"filter": "Test group"},
|
||||
"host": {"filter": "Test host"},
|
||||
"item": {"filter": "Test item"},
|
||||
}]
|
||||
};
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `less than`', () => {
|
||||
|
||||
let itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}<100",
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
||||
|
||||
return ctx.ds.alertQuery(options)
|
||||
.then(resp => {
|
||||
expect(resp.thresholds).toHaveLength(1);
|
||||
expect(resp.thresholds[0]).toBe(100);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `less than or equal`', () => {
|
||||
|
||||
let itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}<=100",
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
||||
|
||||
return ctx.ds.alertQuery(options)
|
||||
.then(resp => {
|
||||
expect(resp.thresholds.length).toBe(1);
|
||||
expect(resp.thresholds[0]).toBe(100);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `greater than or equal`', () => {
|
||||
|
||||
let itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}>=30",
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
||||
|
||||
return ctx.ds.alertQuery(options)
|
||||
.then(resp => {
|
||||
expect(resp.thresholds.length).toBe(1);
|
||||
expect(resp.thresholds[0]).toBe(30);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
|
||||
it('should return threshold when comparative symbol is `equal`', () => {
|
||||
|
||||
let itemTriggers = [{
|
||||
"triggerid": "15383",
|
||||
"priority": "4",
|
||||
"expression": "{15915}=50",
|
||||
}];
|
||||
|
||||
ctx.ds.zabbix.getAlerts = () => Promise.resolve(itemTriggers);
|
||||
|
||||
return ctx.ds.alertQuery(options)
|
||||
.then(resp => {
|
||||
expect(resp.thresholds.length).toBe(1);
|
||||
expect(resp.thresholds[0]).toBe(50);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=datasource.spec.js.map
|
||||
|
||||
1
dist/datasource-zabbix/specs/datasource.spec.js.map
vendored
Normal file
1
dist/datasource-zabbix/specs/datasource.spec.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
59
dist/datasource-zabbix/specs/timeseries.spec.js
vendored
59
dist/datasource-zabbix/specs/timeseries.spec.js
vendored
@@ -1,34 +1,41 @@
|
||||
// import _ from 'lodash';
|
||||
import ts from '../timeseries';
|
||||
'use strict';
|
||||
|
||||
describe('timeseries processing functions', () => {
|
||||
System.register(['../timeseries'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
describe('sumSeries()', () => {
|
||||
it('should properly sum series', (done) => {
|
||||
let series = [
|
||||
[[0, 1], [1, 2], [1, 3]],
|
||||
[[2, 1], [3, 2], [4, 3]]
|
||||
];
|
||||
var ts;
|
||||
return {
|
||||
setters: [function (_timeseries) {
|
||||
ts = _timeseries.default;
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
let expected = [[2, 1], [4, 2], [5, 3]];
|
||||
describe('timeseries processing functions', function () {
|
||||
|
||||
let result = ts.sumSeries(series);
|
||||
expect(result).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
describe('sumSeries()', function () {
|
||||
it('should properly sum series', function (done) {
|
||||
var series = [[[0, 1], [1, 2], [1, 3]], [[2, 1], [3, 2], [4, 3]]];
|
||||
|
||||
it('should properly sum series with nulls', (done) => {
|
||||
// issue #286
|
||||
let series = [
|
||||
[[1, 1], [1, 2], [1, 3]],
|
||||
[[3, 2], [4, 3]]
|
||||
];
|
||||
var expected = [[2, 1], [4, 2], [5, 3]];
|
||||
|
||||
let expected = [[1, 1], [4, 2], [5, 3]];
|
||||
var result = ts.sumSeries(series);
|
||||
expect(result).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
|
||||
let result = ts.sumSeries(series);
|
||||
expect(result).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should properly sum series with nulls', function (done) {
|
||||
// issue #286
|
||||
var series = [[[1, 1], [1, 2], [1, 3]], [[3, 2], [4, 3]]];
|
||||
|
||||
var expected = [[1, 1], [4, 2], [5, 3]];
|
||||
|
||||
var result = ts.sumSeries(series);
|
||||
expect(result).toEqual(expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}); // import _ from 'lodash';
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=timeseries.spec.js.map
|
||||
|
||||
1
dist/datasource-zabbix/specs/timeseries.spec.js.map
vendored
Normal file
1
dist/datasource-zabbix/specs/timeseries.spec.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/datasource-zabbix/specs/timeseries.spec.js"],"names":["ts","describe","it","done","series","expected","result","sumSeries","expect","toEqual"],"mappings":";;;;;;;;AACOA,Q;;;;AAEPC,eAAS,iCAAT,EAA4C,YAAM;;AAEhDA,iBAAS,aAAT,EAAwB,YAAM;AAC5BC,aAAG,4BAAH,EAAiC,UAACC,IAAD,EAAU;AACzC,gBAAIC,SAAS,CACX,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,EAAS,CAAC,CAAD,EAAI,CAAJ,CAAT,EAAiB,CAAC,CAAD,EAAI,CAAJ,CAAjB,CADW,EAEX,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,EAAS,CAAC,CAAD,EAAI,CAAJ,CAAT,EAAiB,CAAC,CAAD,EAAI,CAAJ,CAAjB,CAFW,CAAb;;AAKA,gBAAIC,WAAW,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,EAAS,CAAC,CAAD,EAAI,CAAJ,CAAT,EAAiB,CAAC,CAAD,EAAI,CAAJ,CAAjB,CAAf;;AAEA,gBAAIC,SAASN,GAAGO,SAAH,CAAaH,MAAb,CAAb;AACAI,mBAAOF,MAAP,EAAeG,OAAf,CAAuBJ,QAAvB;AACAF;AACD,WAXD;;AAaAD,aAAG,uCAAH,EAA4C,UAACC,IAAD,EAAU;AACpD;AACA,gBAAIC,SAAS,CACX,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,EAAS,CAAC,CAAD,EAAI,CAAJ,CAAT,EAAiB,CAAC,CAAD,EAAI,CAAJ,CAAjB,CADW,EAEX,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,EAAS,CAAC,CAAD,EAAI,CAAJ,CAAT,CAFW,CAAb;;AAKA,gBAAIC,WAAW,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,EAAS,CAAC,CAAD,EAAI,CAAJ,CAAT,EAAiB,CAAC,CAAD,EAAI,CAAJ,CAAjB,CAAf;;AAEA,gBAAIC,SAASN,GAAGO,SAAH,CAAaH,MAAb,CAAb;AACAI,mBAAOF,MAAP,EAAeG,OAAf,CAAuBJ,QAAvB;AACAF;AACD,WAZD;AAaD,SA3BD;AA4BD,OA9BD,E,CAHA","file":"timeseries.spec.js","sourcesContent":["// import _ from 'lodash';\nimport ts from '../timeseries';\n\ndescribe('timeseries processing functions', () => {\n\n describe('sumSeries()', () => {\n it('should properly sum series', (done) => {\n let series = [\n [[0, 1], [1, 2], [1, 3]],\n [[2, 1], [3, 2], [4, 3]]\n ];\n\n let expected = [[2, 1], [4, 2], [5, 3]];\n\n let result = ts.sumSeries(series);\n expect(result).toEqual(expected);\n done();\n });\n\n it('should properly sum series with nulls', (done) => {\n // issue #286\n let series = [\n [[1, 1], [1, 2], [1, 3]],\n [[3, 2], [4, 3]]\n ];\n\n let expected = [[1, 1], [4, 2], [5, 3]];\n\n let result = ts.sumSeries(series);\n expect(result).toEqual(expected);\n done();\n });\n });\n});\n"]}
|
||||
265
dist/datasource-zabbix/specs/utils.spec.js
vendored
265
dist/datasource-zabbix/specs/utils.spec.js
vendored
@@ -1,141 +1,136 @@
|
||||
import _ from 'lodash';
|
||||
import * as utils from '../utils';
|
||||
'use strict';
|
||||
|
||||
describe('Utils', () => {
|
||||
System.register(['lodash', '../utils'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
describe('expandItemName()', () => {
|
||||
var _, utils;
|
||||
|
||||
it('should properly expand unquoted params', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
name: `CPU $2 time`,
|
||||
key: `system.cpu.util[,user,avg1]`,
|
||||
expected: "CPU user time"
|
||||
},
|
||||
{
|
||||
name: `CPU $2 time - $3`,
|
||||
key: `system.cpu.util[,system,avg1]`,
|
||||
expected: "CPU system time - avg1"
|
||||
},
|
||||
{
|
||||
name: `CPU - $1 - $2 - $3`,
|
||||
key: `system.cpu.util[,system,avg1]`,
|
||||
expected: "CPU - - system - avg1"
|
||||
}
|
||||
];
|
||||
return {
|
||||
setters: [function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}, function (_utils) {
|
||||
utils = _utils;
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||
expect(expandedName).toBe(test_case.expected);
|
||||
describe('Utils', function () {
|
||||
|
||||
describe('expandItemName()', function () {
|
||||
|
||||
it('should properly expand unquoted params', function (done) {
|
||||
var test_cases = [{
|
||||
name: 'CPU $2 time',
|
||||
key: 'system.cpu.util[,user,avg1]',
|
||||
expected: "CPU user time"
|
||||
}, {
|
||||
name: 'CPU $2 time - $3',
|
||||
key: 'system.cpu.util[,system,avg1]',
|
||||
expected: "CPU system time - avg1"
|
||||
}, {
|
||||
name: 'CPU - $1 - $2 - $3',
|
||||
key: 'system.cpu.util[,system,avg1]',
|
||||
expected: "CPU - - system - avg1"
|
||||
}];
|
||||
|
||||
_.each(test_cases, function (test_case) {
|
||||
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||
expect(expandedName).toBe(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly expand quoted params with commas', function (done) {
|
||||
var test_cases = [{
|
||||
name: 'CPU $2 time',
|
||||
key: 'system.cpu.util["type=user,value=avg",user]',
|
||||
expected: "CPU user time"
|
||||
}, {
|
||||
name: 'CPU $1 time',
|
||||
key: 'system.cpu.util["type=user,value=avg","user"]',
|
||||
expected: "CPU type=user,value=avg time"
|
||||
}, {
|
||||
name: 'CPU $1 time $3',
|
||||
key: 'system.cpu.util["type=user,value=avg",,"user"]',
|
||||
expected: "CPU type=user,value=avg time user"
|
||||
}, {
|
||||
name: 'CPU $1 $2 $3',
|
||||
key: 'system.cpu.util["type=user,value=avg",time,"user"]',
|
||||
expected: "CPU type=user,value=avg time user"
|
||||
}];
|
||||
|
||||
_.each(test_cases, function (test_case) {
|
||||
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||
expect(expandedName).toBe(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly expand array params', function (done) {
|
||||
var test_cases = [{
|
||||
name: 'CPU $2 - $3 time',
|
||||
key: 'system.cpu.util[,[user,system],avg1]',
|
||||
expected: "CPU user,system - avg1 time"
|
||||
}, {
|
||||
name: 'CPU $2 - $3 time',
|
||||
key: 'system.cpu.util[,["user,system",iowait],avg1]',
|
||||
expected: 'CPU "user,system",iowait - avg1 time'
|
||||
}, {
|
||||
name: 'CPU - $2 - $3 - $4',
|
||||
key: 'system.cpu.util[,[],["user,system",iowait],avg1]',
|
||||
expected: 'CPU - - "user,system",iowait - avg1'
|
||||
}];
|
||||
|
||||
_.each(test_cases, function (test_case) {
|
||||
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||
expect(expandedName).toBe(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('splitTemplateQuery()', function () {
|
||||
|
||||
// Backward compatibility
|
||||
it('should properly split query in old format', function (done) {
|
||||
var test_cases = [{
|
||||
query: '/alu/./tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9{2}/',
|
||||
expected: ['/alu/', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/']
|
||||
}, {
|
||||
query: 'a.b.c.d',
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
}];
|
||||
|
||||
_.each(test_cases, function (test_case) {
|
||||
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).toEqual(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly split query', function (done) {
|
||||
var test_cases = [{
|
||||
query: '{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9]*/}',
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/']
|
||||
}, {
|
||||
query: '{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9]{2}/}',
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/']
|
||||
}, {
|
||||
query: '{a}{b}{c}{d}',
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
}, {
|
||||
query: '{a}{b.c.d}',
|
||||
expected: ['a', 'b.c.d']
|
||||
}];
|
||||
|
||||
_.each(test_cases, function (test_case) {
|
||||
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).toEqual(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly expand quoted params with commas', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
name: `CPU $2 time`,
|
||||
key: `system.cpu.util["type=user,value=avg",user]`,
|
||||
expected: "CPU user time"
|
||||
},
|
||||
{
|
||||
name: `CPU $1 time`,
|
||||
key: `system.cpu.util["type=user,value=avg","user"]`,
|
||||
expected: "CPU type=user,value=avg time"
|
||||
},
|
||||
{
|
||||
name: `CPU $1 time $3`,
|
||||
key: `system.cpu.util["type=user,value=avg",,"user"]`,
|
||||
expected: "CPU type=user,value=avg time user"
|
||||
},
|
||||
{
|
||||
name: `CPU $1 $2 $3`,
|
||||
key: `system.cpu.util["type=user,value=avg",time,"user"]`,
|
||||
expected: "CPU type=user,value=avg time user"
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||
expect(expandedName).toBe(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly expand array params', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
name: `CPU $2 - $3 time`,
|
||||
key: `system.cpu.util[,[user,system],avg1]`,
|
||||
expected: "CPU user,system - avg1 time"
|
||||
},
|
||||
{
|
||||
name: `CPU $2 - $3 time`,
|
||||
key: `system.cpu.util[,["user,system",iowait],avg1]`,
|
||||
expected: `CPU "user,system",iowait - avg1 time`
|
||||
},
|
||||
{
|
||||
name: `CPU - $2 - $3 - $4`,
|
||||
key: `system.cpu.util[,[],["user,system",iowait],avg1]`,
|
||||
expected: `CPU - - "user,system",iowait - avg1`
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||
expect(expandedName).toBe(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('splitTemplateQuery()', () => {
|
||||
|
||||
// Backward compatibility
|
||||
it('should properly split query in old format', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
query: `/alu/./tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/`,
|
||||
expected: ['/alu/', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/']
|
||||
},
|
||||
{
|
||||
query: `a.b.c.d`,
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).toEqual(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly split query', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/}`,
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/']
|
||||
},
|
||||
{
|
||||
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/}`,
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/']
|
||||
},
|
||||
{
|
||||
query: `{a}{b}{c}{d}`,
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
},
|
||||
{
|
||||
query: `{a}{b.c.d}`,
|
||||
expected: ['a', 'b.c.d']
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).toEqual(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=utils.spec.js.map
|
||||
|
||||
1
dist/datasource-zabbix/specs/utils.spec.js.map
vendored
Normal file
1
dist/datasource-zabbix/specs/utils.spec.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user