Merge branch 'akotynski-threshold_regex'
This commit is contained in:
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6"
|
||||
script: npm run build
|
||||
2
dist/datasource-zabbix/datasource.js
vendored
2
dist/datasource-zabbix/datasource.js
vendored
@@ -112,7 +112,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
}
|
||||
|
||||
function getTriggerThreshold(expression) {
|
||||
var thresholdPattern = /.*[<>]([\d\.]+)/;
|
||||
var thresholdPattern = /.*[<>=]{1,2}([\d\.]+)/;
|
||||
var finded_thresholds = expression.match(thresholdPattern);
|
||||
if (finded_thresholds && finded_thresholds.length >= 2) {
|
||||
var threshold = finded_thresholds[1];
|
||||
|
||||
2
dist/datasource-zabbix/datasource.js.map
vendored
2
dist/datasource-zabbix/datasource.js.map
vendored
File diff suppressed because one or more lines are too long
107
dist/datasource-zabbix/specs/datasource_specs.js
vendored
107
dist/datasource-zabbix/specs/datasource_specs.js
vendored
@@ -11,6 +11,7 @@ describe('ZabbixDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: {
|
||||
alerting: true,
|
||||
username: 'zabbix',
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
@@ -28,12 +29,12 @@ describe('ZabbixDatasource', () => {
|
||||
ctx.zabbix = () => {};
|
||||
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.alertSrv, ctx.dashboardSrv, ctx.zabbixAlertingSrv, ctx.zabbix);
|
||||
ctx.ds.alertQuery = () => Q.when([]);
|
||||
});
|
||||
|
||||
describe('When querying data', () => {
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
ctx.ds.alertQuery = () => Q.when([]);
|
||||
});
|
||||
|
||||
ctx.options = {
|
||||
@@ -147,7 +148,7 @@ describe('ZabbixDatasource', () => {
|
||||
describe('When invoking metricFindQuery()', () => {
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
ctx.ds.zabbix = {
|
||||
ctx.ds.zabbix = {
|
||||
getGroups: () => Q.when([]),
|
||||
getHosts: () => Q.when([]),
|
||||
getApps: () => Q.when([]),
|
||||
@@ -234,4 +235,106 @@ describe('ZabbixDatasource', () => {
|
||||
});
|
||||
});
|
||||
|
||||
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.length).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(50);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
10
dist/datasource-zabbix/specs/test-main.js
vendored
10
dist/datasource-zabbix/specs/test-main.js
vendored
@@ -2,7 +2,7 @@
|
||||
/* globals global: false */
|
||||
|
||||
import prunk from 'prunk';
|
||||
import {jsdom} from 'jsdom';
|
||||
import {JSDOM} from 'jsdom';
|
||||
import chai from 'chai';
|
||||
// import sinon from 'sinon';
|
||||
import sinonChai from 'sinon-chai';
|
||||
@@ -36,11 +36,11 @@ prunk.mock('app/core/table_model', {});
|
||||
prunk.mock('angular', angularMocks);
|
||||
prunk.mock('jquery', 'module not found');
|
||||
|
||||
// Setup jsdom
|
||||
// Required for loading angularjs
|
||||
global.document = jsdom('<html><head><script></script></head><body></body></html>');
|
||||
global.window = global.document.parentWindow;
|
||||
global.navigator = window.navigator = {};
|
||||
let dom = new JSDOM('<html><head><script></script></head><body></body></html>');
|
||||
// Setup jsdom
|
||||
global.window = dom.window;
|
||||
global.document = global.window.document;
|
||||
global.Node = window.Node;
|
||||
|
||||
// Setup Chai
|
||||
|
||||
2
dist/test/datasource-zabbix/datasource.js
vendored
2
dist/test/datasource-zabbix/datasource.js
vendored
@@ -840,7 +840,7 @@ function filterEnabledTargets(targets) {
|
||||
}
|
||||
|
||||
function getTriggerThreshold(expression) {
|
||||
var thresholdPattern = /.*[<>]([\d\.]+)/;
|
||||
var thresholdPattern = /.*[<>=]{1,2}([\d\.]+)/;
|
||||
var finded_thresholds = expression.match(thresholdPattern);
|
||||
if (finded_thresholds && finded_thresholds.length >= 2) {
|
||||
var threshold = finded_thresholds[1];
|
||||
|
||||
@@ -25,6 +25,7 @@ describe('ZabbixDatasource', function () {
|
||||
beforeEach(function () {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: {
|
||||
alerting: true,
|
||||
username: 'zabbix',
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
@@ -42,9 +43,6 @@ describe('ZabbixDatasource', function () {
|
||||
ctx.zabbix = function () {};
|
||||
|
||||
ctx.ds = new _module.Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.alertSrv, ctx.dashboardSrv, ctx.zabbixAlertingSrv, ctx.zabbix);
|
||||
ctx.ds.alertQuery = function () {
|
||||
return _q2.default.when([]);
|
||||
};
|
||||
});
|
||||
|
||||
describe('When querying data', function () {
|
||||
@@ -52,6 +50,9 @@ describe('ZabbixDatasource', function () {
|
||||
ctx.ds.replaceTemplateVars = function (str) {
|
||||
return str;
|
||||
};
|
||||
ctx.ds.alertQuery = function () {
|
||||
return _q2.default.when([]);
|
||||
};
|
||||
});
|
||||
|
||||
ctx.options = {
|
||||
@@ -323,4 +324,115 @@ describe('ZabbixDatasource', function () {
|
||||
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.length).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(50);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,11 +53,11 @@ _prunk2.default.mock('app/core/table_model', {});
|
||||
_prunk2.default.mock('angular', angularMocks);
|
||||
_prunk2.default.mock('jquery', 'module not found');
|
||||
|
||||
// Setup jsdom
|
||||
// Required for loading angularjs
|
||||
global.document = (0, _jsdom.jsdom)('<html><head><script></script></head><body></body></html>');
|
||||
global.window = global.document.parentWindow;
|
||||
global.navigator = window.navigator = {};
|
||||
var dom = new _jsdom.JSDOM('<html><head><script></script></head><body></body></html>');
|
||||
// Setup jsdom
|
||||
global.window = dom.window;
|
||||
global.document = global.window.document;
|
||||
global.Node = window.Node;
|
||||
|
||||
// Setup Chai
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"grunt-sass": "^1.1.0",
|
||||
"grunt-systemjs-builder": "^0.2.5",
|
||||
"grunt": "~0.4.5",
|
||||
"jsdom": "~3.1.2",
|
||||
"jsdom": "~11.3.0",
|
||||
"jshint-stylish": "^2.1.0",
|
||||
"load-grunt-tasks": "~3.2.0",
|
||||
"mocha": "^2.4.5",
|
||||
|
||||
@@ -730,7 +730,7 @@ function filterEnabledTargets(targets) {
|
||||
}
|
||||
|
||||
function getTriggerThreshold(expression) {
|
||||
let thresholdPattern = /.*[<>]([\d\.]+)/;
|
||||
let thresholdPattern = /.*[<>=]{1,2}([\d\.]+)/;
|
||||
let finded_thresholds = expression.match(thresholdPattern);
|
||||
if (finded_thresholds && finded_thresholds.length >= 2) {
|
||||
let threshold = finded_thresholds[1];
|
||||
|
||||
@@ -11,6 +11,7 @@ describe('ZabbixDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: {
|
||||
alerting: true,
|
||||
username: 'zabbix',
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
@@ -28,12 +29,12 @@ describe('ZabbixDatasource', () => {
|
||||
ctx.zabbix = () => {};
|
||||
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.alertSrv, ctx.dashboardSrv, ctx.zabbixAlertingSrv, ctx.zabbix);
|
||||
ctx.ds.alertQuery = () => Q.when([]);
|
||||
});
|
||||
|
||||
describe('When querying data', () => {
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
ctx.ds.alertQuery = () => Q.when([]);
|
||||
});
|
||||
|
||||
ctx.options = {
|
||||
@@ -147,7 +148,7 @@ describe('ZabbixDatasource', () => {
|
||||
describe('When invoking metricFindQuery()', () => {
|
||||
beforeEach(() => {
|
||||
ctx.ds.replaceTemplateVars = (str) => str;
|
||||
ctx.ds.zabbix = {
|
||||
ctx.ds.zabbix = {
|
||||
getGroups: () => Q.when([]),
|
||||
getHosts: () => Q.when([]),
|
||||
getApps: () => Q.when([]),
|
||||
@@ -234,4 +235,106 @@ describe('ZabbixDatasource', () => {
|
||||
});
|
||||
});
|
||||
|
||||
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.length).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(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).to.equal(1);
|
||||
expect(resp.thresholds[0]).to.equal(50);
|
||||
return resp;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* globals global: false */
|
||||
|
||||
import prunk from 'prunk';
|
||||
import {jsdom} from 'jsdom';
|
||||
import {JSDOM} from 'jsdom';
|
||||
import chai from 'chai';
|
||||
// import sinon from 'sinon';
|
||||
import sinonChai from 'sinon-chai';
|
||||
@@ -36,11 +36,11 @@ prunk.mock('app/core/table_model', {});
|
||||
prunk.mock('angular', angularMocks);
|
||||
prunk.mock('jquery', 'module not found');
|
||||
|
||||
// Setup jsdom
|
||||
// Required for loading angularjs
|
||||
global.document = jsdom('<html><head><script></script></head><body></body></html>');
|
||||
global.window = global.document.parentWindow;
|
||||
global.navigator = window.navigator = {};
|
||||
let dom = new JSDOM('<html><head><script></script></head><body></body></html>');
|
||||
// Setup jsdom
|
||||
global.window = dom.window;
|
||||
global.document = global.window.document;
|
||||
global.Node = window.Node;
|
||||
|
||||
// Setup Chai
|
||||
|
||||
Reference in New Issue
Block a user