diff --git a/dist/datasource-zabbix/zabbix.js b/dist/datasource-zabbix/zabbix.js index 83e887582..2f20188a2 100644 --- a/dist/datasource-zabbix/zabbix.js +++ b/dist/datasource-zabbix/zabbix.js @@ -154,7 +154,7 @@ System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './za } }, { key: 'getTriggers', - value: function getTriggers(groupFilter, hostFilter, appFilter, showTriggers) { + value: function getTriggers(groupFilter, hostFilter, appFilter, showTriggers, hideHostsInMaintenance) { var _this5 = this; var promises = [this.getGroups(groupFilter), this.getHosts(groupFilter, hostFilter), this.getApps(groupFilter, hostFilter, appFilter)]; @@ -177,7 +177,7 @@ System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './za return query; }).then(function (query) { - return _this5.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers); + return _this5.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers, hideHostsInMaintenance); }); } }]); diff --git a/dist/datasource-zabbix/zabbix.js.map b/dist/datasource-zabbix/zabbix.js.map index 8450b5d63..456ee8f70 100644 --- a/dist/datasource-zabbix/zabbix.js.map +++ b/dist/datasource-zabbix/zabbix.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/datasource-zabbix/zabbix.js"],"names":["ZabbixFactory","zabbixAPIService","ZabbixCachingProxy","Zabbix","url","username","password","basicAuth","withCredentials","cacheTTL","ZabbixAPI","zabbixAPI","cacheOptions","enabled","ttl","cachingProxy","getHistory","bind","getTrend","getEvents","getAcknowledges","getITService","getSLA","getVersion","login","target","options","parts","filters","_","map","p","filter","getItems","getGroups","groupFilter","getAllGroups","then","findByFilter","groups","groupids","getHosts","hostFilter","getAllHosts","hosts","hostids","getApps","appFilter","filterByQuery","apps","appFilterEmpty","undefined","itemtype","appids","showDisabledItems","items","itemFilter","getAllItems","showTriggers","promises","Promise","all","filteredGroups","results","filteredHosts","filteredApps","query","applicationids","flatten","getTriggers","findByName","list","name","finded","find","filterByName","filterByRegex","regex","filterP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AAmB;AACvC,aAAOH,cAAcI,IAAd,CAAmBD,QAAQT,IAA3B,CAAP;AACD,KAFM,CAAP;AAGD;;AAED,WAASlC,YAAT,CAAsBiC,IAAtB,EAA4BvC,MAA5B,EAAoC;AAClC,QAAI+C,MAAMI,OAAN,CAAcnD,MAAd,CAAJ,EAA2B;AACzB,aAAO4C,cAAcL,IAAd,EAAoBvC,MAApB,CAAP;AACD,KAFD,MAEO;AACL,aAAOsC,WAAWC,IAAX,EAAiBvC,MAAjB,CAAP;AACD;AACF;;AAED,WAASgB,aAAT,CAAuBuB,IAAvB,EAA6BvC,MAA7B,EAAqC;AACnC,QAAI+C,MAAMI,OAAN,CAAcnD,MAAd,CAAJ,EAA2B;AACzB,aAAO4C,cAAcL,IAAd,EAAoBvC,MAApB,CAAP;AACD,KAFD,MAEO;AACL,aAAO2C,aAAaJ,IAAb,EAAmBvC,MAAnB,CAAP;AACD;AACF;;;AAxNMoD,a;;AACAvD,O;;AACKkD,W;;;;;;;;;;;;;;;;;;;;;AA2JZK,cACGC,MADH,CACU,kBADV,EAEGC,OAFH,CAEW,QAFX,EAEqBtF,aAFrB","file":"zabbix.js","sourcesContent":["import angular from 'angular';\nimport _ from 'lodash';\nimport * as utils from './utils';\nimport './zabbixAPI.service.js';\nimport './zabbixCachingProxy.service.js';\n\n// Use factory() instead service() for multiple data sources support.\n// Each Zabbix data source instance should initialize its own API instance.\n\n/** @ngInject */\nfunction ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) {\n\n class Zabbix {\n constructor(url, username, password, basicAuth, withCredentials, cacheTTL) {\n\n // Initialize Zabbix API\n var ZabbixAPI = zabbixAPIService;\n this.zabbixAPI = new ZabbixAPI(url, username, password, basicAuth, withCredentials);\n\n // Initialize caching proxy for requests\n let cacheOptions = {\n enabled: true,\n ttl: cacheTTL\n };\n this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, cacheOptions);\n\n // Proxy methods\n this.getHistory = this.cachingProxy.getHistory.bind(this.cachingProxy);\n\n this.getTrend = this.zabbixAPI.getTrend.bind(this.zabbixAPI);\n this.getEvents = this.zabbixAPI.getEvents.bind(this.zabbixAPI);\n this.getAcknowledges = this.zabbixAPI.getAcknowledges.bind(this.zabbixAPI);\n this.getITService = this.zabbixAPI.getITService.bind(this.zabbixAPI);\n this.getSLA = this.zabbixAPI.getSLA.bind(this.zabbixAPI);\n this.getVersion = this.zabbixAPI.getVersion.bind(this.zabbixAPI);\n this.login = this.zabbixAPI.login.bind(this.zabbixAPI);\n }\n\n getItemsFromTarget(target, options) {\n let parts = ['group', 'host', 'application', 'item'];\n let filters = _.map(parts, p => target[p].filter);\n return this.getItems(...filters, options);\n }\n\n getAllGroups() {\n return this.cachingProxy.getGroups();\n }\n\n getGroups(groupFilter) {\n return this.getAllGroups()\n .then(groups => findByFilter(groups, groupFilter));\n }\n\n /**\n * Get list of host belonging to given groups.\n */\n getAllHosts(groupFilter) {\n return this.getGroups(groupFilter)\n .then(groups => {\n let groupids = _.map(groups, 'groupid');\n return this.cachingProxy.getHosts(groupids);\n });\n }\n\n getHosts(groupFilter, hostFilter) {\n return this.getAllHosts(groupFilter)\n .then(hosts => findByFilter(hosts, hostFilter));\n }\n\n /**\n * Get list of applications belonging to given groups and hosts.\n */\n getAllApps(groupFilter, hostFilter) {\n return this.getHosts(groupFilter, hostFilter)\n .then(hosts => {\n let hostids = _.map(hosts, 'hostid');\n return this.cachingProxy.getApps(hostids);\n });\n }\n\n getApps(groupFilter, hostFilter, appFilter) {\n return this.getHosts(groupFilter, hostFilter)\n .then(hosts => {\n let hostids = _.map(hosts, 'hostid');\n if (appFilter) {\n return this.cachingProxy.getApps(hostids)\n .then(apps => filterByQuery(apps, appFilter));\n } else {\n return {\n appFilterEmpty: true,\n hostids: hostids\n };\n }\n });\n }\n\n getAllItems(groupFilter, hostFilter, appFilter, options = {}) {\n return this.getApps(groupFilter, hostFilter, appFilter)\n .then(apps => {\n if (apps.appFilterEmpty) {\n return this.cachingProxy.getItems(apps.hostids, undefined, options.itemtype);\n } else {\n let appids = _.map(apps, 'applicationid');\n return this.cachingProxy.getItems(undefined, appids, options.itemtype);\n }\n })\n .then(items => {\n if (!options.showDisabledItems) {\n items = _.filter(items, {'status': '0'});\n }\n return items;\n });\n }\n\n getItems(groupFilter, hostFilter, appFilter, itemFilter, options = {}) {\n return this.getAllItems(groupFilter, hostFilter, appFilter, options)\n .then(items => filterByQuery(items, itemFilter));\n }\n\n /**\n * Build query - convert target filters to array of Zabbix items\n */\n getTriggers(groupFilter, hostFilter, appFilter, showTriggers) {\n let promises = [\n this.getGroups(groupFilter),\n this.getHosts(groupFilter, hostFilter),\n this.getApps(groupFilter, hostFilter, appFilter)\n ];\n\n return Promise.all(promises)\n .then(results => {\n let filteredGroups = results[0];\n let filteredHosts = results[1];\n let filteredApps = results[2];\n let query = {};\n\n if (appFilter) {\n query.applicationids = _.flatten(_.map(filteredApps, 'applicationid'));\n }\n if (hostFilter) {\n query.hostids = _.map(filteredHosts, 'hostid');\n }\n if (groupFilter) {\n query.groupids = _.map(filteredGroups, 'groupid');\n }\n\n return query;\n }).then(query => {\n return this.zabbixAPI\n .getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers);\n });\n }\n }\n\n return Zabbix;\n}\n\nangular\n .module('grafana.services')\n .factory('Zabbix', ZabbixFactory);\n\n///////////////////////////////////////////////////////////////////////////////\n\n/**\n * Find group, host, app or item by given name.\n * @param list list of groups, apps or other\n * @param name visible name\n * @return array with finded element or undefined\n */\nfunction findByName(list, name) {\n var finded = _.find(list, {'name': name});\n if (finded) {\n return [finded];\n } else {\n return undefined;\n }\n}\n\n/**\n * Different hosts can contains applications and items with same name.\n * For this reason use _.filter, which return all elements instead _.find,\n * which return only first finded.\n * @param {[type]} list list of elements\n * @param {[type]} name app name\n * @return {[type]} array with finded element or undefined\n */\nfunction filterByName(list, name) {\n var finded = _.filter(list, {'name': name});\n if (finded) {\n return finded;\n } else {\n return undefined;\n }\n}\n\nfunction filterByRegex(list, regex) {\n var filterPattern = utils.buildRegex(regex);\n return _.filter(list, function (zbx_obj) {\n return filterPattern.test(zbx_obj.name);\n });\n}\n\nfunction findByFilter(list, filter) {\n if (utils.isRegex(filter)) {\n return filterByRegex(list, filter);\n } else {\n return findByName(list, filter);\n }\n}\n\nfunction filterByQuery(list, filter) {\n if (utils.isRegex(filter)) {\n return filterByRegex(list, filter);\n } else {\n return filterByName(list, filter);\n }\n}\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/datasource-zabbix/zabbix.js"],"names":["ZabbixFactory","zabbixAPIService","ZabbixCachingProxy","Zabbix","url","username","password","basicAuth","withCredentials","cacheTTL","ZabbixAPI","zabbixAPI","cacheOptions","enabled","ttl","cachingProxy","getHistory","bind","getTrend","getEvents","getAcknowledges","getITService","getSLA","getVersion","login","target","options","parts","filters","_","map","p","filter","getItems","getGroups","groupFilter","getAllGroups","then","findByFilter","groups","groupids","getHosts","hostFilter","getAllHosts","hosts","hostids","getApps","appFilter","filterByQuery","apps","appFilterEmpty","undefined","itemtype","appids","showDisabledItems","items","itemFilter","getAllItems","showTriggers","hideHostsInMaintenance","promises","Promise","all","filteredGroups","results","filteredHosts","filteredApps","query","applicationids","flatten","getTriggers","findByName","list","name","finded","find","filterByName","filterByRegex","regex","filterPattern","utils","buildRegex","zbx_obj","test","isRegex","angular","module","factory"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA;AACA;;AAEA;AACA,WAASA,aAAT,CAAuBC,gBAAvB,EAAyCC,kBAAzC,EAA6D;AAAA,QAErDC,MAFqD;AAGzD,sBAAYC,GAAZ,EAAiBC,QAAjB,EAA2BC,QAA3B,EAAqCC,SAArC,EAAgDC,eAAhD,EAAiEC,QAAjE,EAA2E;AAAA;;AAEzE;AACA,YAAIC,YAAYT,gBAAhB;AACA,aAAKU,SAAL,GAAiB,IAAID,SAAJ,CAAcN,GAAd,EAAmBC,QAAnB,EAA6BC,QAA7B,EAAuCC,SAAvC,EAAkDC,eAAlD,CAAjB;;AAEA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pD,MAAd,CAAJ,EAA2B;AACzB,aAAO6C,cAAcL,IAAd,EAAoBxC,MAApB,CAAP;AACD,KAFD,MAEO;AACL,aAAO4C,aAAaJ,IAAb,EAAmBxC,MAAnB,CAAP;AACD;AACF;;;AAxNMqD,a;;AACAxD,O;;AACKmD,W;;;;;;;;;;;;;;;;;;;;;AA2JZK,cACGC,MADH,CACU,kBADV,EAEGC,OAFH,CAEW,QAFX,EAEqBvF,aAFrB","file":"zabbix.js","sourcesContent":["import angular from 'angular';\nimport _ from 'lodash';\nimport * as utils from './utils';\nimport './zabbixAPI.service.js';\nimport './zabbixCachingProxy.service.js';\n\n// Use factory() instead service() for multiple data sources support.\n// Each Zabbix data source instance should initialize its own API instance.\n\n/** @ngInject */\nfunction ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) {\n\n class Zabbix {\n constructor(url, username, password, basicAuth, withCredentials, cacheTTL) {\n\n // Initialize Zabbix API\n var ZabbixAPI = zabbixAPIService;\n this.zabbixAPI = new ZabbixAPI(url, username, password, basicAuth, withCredentials);\n\n // Initialize caching proxy for requests\n let cacheOptions = {\n enabled: true,\n ttl: cacheTTL\n };\n this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, cacheOptions);\n\n // Proxy methods\n this.getHistory = this.cachingProxy.getHistory.bind(this.cachingProxy);\n\n this.getTrend = this.zabbixAPI.getTrend.bind(this.zabbixAPI);\n this.getEvents = this.zabbixAPI.getEvents.bind(this.zabbixAPI);\n this.getAcknowledges = this.zabbixAPI.getAcknowledges.bind(this.zabbixAPI);\n this.getITService = this.zabbixAPI.getITService.bind(this.zabbixAPI);\n this.getSLA = this.zabbixAPI.getSLA.bind(this.zabbixAPI);\n this.getVersion = this.zabbixAPI.getVersion.bind(this.zabbixAPI);\n this.login = this.zabbixAPI.login.bind(this.zabbixAPI);\n }\n\n getItemsFromTarget(target, options) {\n let parts = ['group', 'host', 'application', 'item'];\n let filters = _.map(parts, p => target[p].filter);\n return this.getItems(...filters, options);\n }\n\n getAllGroups() {\n return this.cachingProxy.getGroups();\n }\n\n getGroups(groupFilter) {\n return this.getAllGroups()\n .then(groups => findByFilter(groups, groupFilter));\n }\n\n /**\n * Get list of host belonging to given groups.\n */\n getAllHosts(groupFilter) {\n return this.getGroups(groupFilter)\n .then(groups => {\n let groupids = _.map(groups, 'groupid');\n return this.cachingProxy.getHosts(groupids);\n });\n }\n\n getHosts(groupFilter, hostFilter) {\n return this.getAllHosts(groupFilter)\n .then(hosts => findByFilter(hosts, hostFilter));\n }\n\n /**\n * Get list of applications belonging to given groups and hosts.\n */\n getAllApps(groupFilter, hostFilter) {\n return this.getHosts(groupFilter, hostFilter)\n .then(hosts => {\n let hostids = _.map(hosts, 'hostid');\n return this.cachingProxy.getApps(hostids);\n });\n }\n\n getApps(groupFilter, hostFilter, appFilter) {\n return this.getHosts(groupFilter, hostFilter)\n .then(hosts => {\n let hostids = _.map(hosts, 'hostid');\n if (appFilter) {\n return this.cachingProxy.getApps(hostids)\n .then(apps => filterByQuery(apps, appFilter));\n } else {\n return {\n appFilterEmpty: true,\n hostids: hostids\n };\n }\n });\n }\n\n getAllItems(groupFilter, hostFilter, appFilter, options = {}) {\n return this.getApps(groupFilter, hostFilter, appFilter)\n .then(apps => {\n if (apps.appFilterEmpty) {\n return this.cachingProxy.getItems(apps.hostids, undefined, options.itemtype);\n } else {\n let appids = _.map(apps, 'applicationid');\n return this.cachingProxy.getItems(undefined, appids, options.itemtype);\n }\n })\n .then(items => {\n if (!options.showDisabledItems) {\n items = _.filter(items, {'status': '0'});\n }\n return items;\n });\n }\n\n getItems(groupFilter, hostFilter, appFilter, itemFilter, options = {}) {\n return this.getAllItems(groupFilter, hostFilter, appFilter, options)\n .then(items => filterByQuery(items, itemFilter));\n }\n\n /**\n * Build query - convert target filters to array of Zabbix items\n */\n getTriggers(groupFilter, hostFilter, appFilter, showTriggers, hideHostsInMaintenance) {\n let promises = [\n this.getGroups(groupFilter),\n this.getHosts(groupFilter, hostFilter),\n this.getApps(groupFilter, hostFilter, appFilter)\n ];\n\n return Promise.all(promises)\n .then(results => {\n let filteredGroups = results[0];\n let filteredHosts = results[1];\n let filteredApps = results[2];\n let query = {};\n\n if (appFilter) {\n query.applicationids = _.flatten(_.map(filteredApps, 'applicationid'));\n }\n if (hostFilter) {\n query.hostids = _.map(filteredHosts, 'hostid');\n }\n if (groupFilter) {\n query.groupids = _.map(filteredGroups, 'groupid');\n }\n\n return query;\n }).then(query => {\n return this.zabbixAPI\n .getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers, hideHostsInMaintenance);\n });\n }\n }\n\n return Zabbix;\n}\n\nangular\n .module('grafana.services')\n .factory('Zabbix', ZabbixFactory);\n\n///////////////////////////////////////////////////////////////////////////////\n\n/**\n * Find group, host, app or item by given name.\n * @param list list of groups, apps or other\n * @param name visible name\n * @return array with finded element or undefined\n */\nfunction findByName(list, name) {\n var finded = _.find(list, {'name': name});\n if (finded) {\n return [finded];\n } else {\n return undefined;\n }\n}\n\n/**\n * Different hosts can contains applications and items with same name.\n * For this reason use _.filter, which return all elements instead _.find,\n * which return only first finded.\n * @param {[type]} list list of elements\n * @param {[type]} name app name\n * @return {[type]} array with finded element or undefined\n */\nfunction filterByName(list, name) {\n var finded = _.filter(list, {'name': name});\n if (finded) {\n return finded;\n } else {\n return undefined;\n }\n}\n\nfunction filterByRegex(list, regex) {\n var filterPattern = utils.buildRegex(regex);\n return _.filter(list, function (zbx_obj) {\n return filterPattern.test(zbx_obj.name);\n });\n}\n\nfunction findByFilter(list, filter) {\n if (utils.isRegex(filter)) {\n return filterByRegex(list, filter);\n } else {\n return findByName(list, filter);\n }\n}\n\nfunction filterByQuery(list, filter) {\n if (utils.isRegex(filter)) {\n return filterByRegex(list, filter);\n } else {\n return filterByName(list, filter);\n }\n}\n"]} \ No newline at end of file diff --git a/dist/datasource-zabbix/zabbixAPI.service.js b/dist/datasource-zabbix/zabbixAPI.service.js index 83395c36f..fe8a7667d 100644 --- a/dist/datasource-zabbix/zabbixAPI.service.js +++ b/dist/datasource-zabbix/zabbixAPI.service.js @@ -286,7 +286,7 @@ System.register(['angular', 'lodash', './utils', './zabbixAPICore.service'], fun } }, { key: 'getTriggers', - value: function getTriggers(groupids, hostids, applicationids, showTriggers, timeFrom, timeTo) { + value: function getTriggers(groupids, hostids, applicationids, showTriggers, hideHostsInMaintenance, timeFrom, timeTo) { var params = { output: 'extend', groupids: groupids, @@ -311,6 +311,10 @@ System.register(['angular', 'lodash', './utils', './zabbixAPICore.service'], fun params.filter.value = showTriggers; } + if (hideHostsInMaintenance) { + params.maintenance = false; + } + if (timeFrom || timeTo) { params.lastChangeSince = timeFrom; params.lastChangeTill = timeTo; diff --git a/dist/datasource-zabbix/zabbixAPI.service.js.map b/dist/datasource-zabbix/zabbixAPI.service.js.map index 5d8dfe938..e430416e8 100644 --- a/dist/datasource-zabbix/zabbixAPI.service.js.map +++ b/dist/datasource-zabbix/zabbixAPI.service.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/datasource-zabbix/zabbixAPI.service.js"],"names":["ZabbixAPIServiceFactory","alertSrv","zabbixAPICoreService","ZabbixAPI","api_url","username","password","basicAuth","withCredentials","url","auth","requestOptions","loginPromise","loginErrorCount","maxLoginAttempts","zabbixAPICore","getTrend","getTrend_ZBXNEXT1193","method","params","request","catch","isNotAuthorized","error","data","loginOnce","then","message","statusText","alertAPIError","timeout","set","Promise","resolve","login","getVersion","eventid","eventids","output","sortfield","real_hosts","groupids","hostids","appids","itemtype","webitems","filter","selectHosts","applicationids","value_type","expandItems","items","forEach","item","name","utils","expandItemName","key_","itemid","itemids","length","lastvalue","timeFrom","timeTill","grouped_items","_","groupBy","promises","map","history","sortorder","time_from","time_till","all","flatten","trend","self","serviceids","timeTo","intervals","from","to","showTriggers","expandDescription","expandData","expandComment","monitored","skipDependent","value","selectGroups","selectItems","selectLastEvent","lastChangeSince","lastChangeTill","objectids","showEvents","select_acknowledges","preservekeys","events","event","acknowledges","angular","module","factory"],"mappings":";;;;;;;;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CACU,kBADV,EAEGC,OAFH,CAEW,kBAFX,EAE+BvG,uBAF/B","file":"zabbixAPI.service.js","sourcesContent":["import angular from 'angular';\nimport _ from 'lodash';\nimport * as utils from './utils';\nimport './zabbixAPICore.service';\n\n/** @ngInject */\nfunction ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {\n\n /**\n * Zabbix API Wrapper.\n * Creates Zabbix API instance with given parameters (url, credentials and other).\n * Wraps API calls and provides high-level methods.\n */\n class ZabbixAPI {\n\n constructor(api_url, username, password, basicAuth, withCredentials) {\n this.url = api_url;\n this.username = username;\n this.password = password;\n this.auth = \"\";\n\n this.requestOptions = {\n basicAuth: basicAuth,\n withCredentials: withCredentials\n };\n\n this.loginPromise = null;\n this.loginErrorCount = 0;\n this.maxLoginAttempts = 3;\n\n this.alertSrv = alertSrv;\n this.zabbixAPICore = zabbixAPICoreService;\n\n this.getTrend = this.getTrend_ZBXNEXT1193;\n //getTrend = getTrend_30;\n }\n\n //////////////////////////\n // Core method wrappers //\n //////////////////////////\n\n request(method, params) {\n return this.zabbixAPICore.request(this.url, method, params, this.requestOptions, this.auth)\n .catch(error => {\n if (isNotAuthorized(error.data)) {\n // Handle auth errors\n this.loginErrorCount++;\n if (this.loginErrorCount > this.maxLoginAttempts) {\n this.loginErrorCount = 0;\n return null;\n } else {\n return this.loginOnce()\n .then(() => this.request(method, params));\n }\n } else {\n // Handle API errors\n let message = error.data ? error.data : error.statusText;\n this.alertAPIError(message);\n }\n });\n }\n\n alertAPIError(message, timeout = 5000) {\n this.alertSrv.set(\n \"Zabbix API Error\",\n message,\n 'error',\n timeout\n );\n }\n\n /**\n * When API unauthenticated or auth token expired each request produce login()\n * call. But auth token is common to all requests. This function wraps login() method\n * and call it once. If login() already called just wait for it (return its promise).\n * @return login promise\n */\n loginOnce() {\n if (!this.loginPromise) {\n this.loginPromise = Promise.resolve(\n this.login().then(auth => {\n this.auth = auth;\n this.loginPromise = null;\n return auth;\n })\n );\n }\n return this.loginPromise;\n }\n\n /**\n * Get authentication token.\n */\n login() {\n return this.zabbixAPICore.login(this.url, this.username, this.password, this.requestOptions);\n }\n\n /**\n * Get Zabbix API version\n */\n getVersion() {\n return this.zabbixAPICore.getVersion(this.url, this.requestOptions);\n }\n\n ////////////////////////////////\n // Zabbix API method wrappers //\n ////////////////////////////////\n\n acknowledgeEvent(eventid, message) {\n var params = {\n eventids: eventid,\n message: message\n };\n\n return this.request('event.acknowledge', params);\n }\n\n getGroups() {\n var params = {\n output: ['name'],\n sortfield: 'name',\n real_hosts: true\n };\n\n return this.request('hostgroup.get', params);\n }\n\n getHosts(groupids) {\n var params = {\n output: ['name', 'host'],\n sortfield: 'name'\n };\n if (groupids) {\n params.groupids = groupids;\n }\n\n return this.request('host.get', params);\n }\n\n getApps(hostids) {\n var params = {\n output: ['applicationid', 'name'],\n hostids: hostids\n };\n\n return this.request('application.get', params);\n }\n\n /**\n * Get Zabbix items\n * @param {[type]} hostids host ids\n * @param {[type]} appids application ids\n * @param {String} itemtype 'num' or 'text'\n * @return {[type]} array of items\n */\n getItems(hostids, appids, itemtype) {\n var params = {\n output: [\n 'name', 'key_',\n 'value_type',\n 'hostid',\n 'status',\n 'state'\n ],\n sortfield: 'name',\n webitems: true,\n filter: {},\n selectHosts: [\n 'hostid',\n 'name'\n ]\n };\n if (hostids) {\n params.hostids = hostids;\n }\n if (appids) {\n params.applicationids = appids;\n }\n if (itemtype === 'num') {\n // Return only numeric metrics\n params.filter.value_type = [0, 3];\n }\n if (itemtype === 'text') {\n // Return only text metrics\n params.filter.value_type = [1, 2, 4];\n }\n\n return this.request('item.get', params)\n .then(expandItems);\n\n function expandItems(items) {\n items.forEach(item => {\n item.item = item.name;\n item.name = utils.expandItemName(item.item, item.key_);\n return item;\n });\n return items;\n }\n }\n\n getLastValue(itemid) {\n var params = {\n output: ['lastvalue'],\n itemids: itemid\n };\n return this.request('item.get', params)\n .then(items => items.length ? items[0].lastvalue : null);\n }\n\n /**\n * Perform history query from Zabbix API\n *\n * @param {Array} items Array of Zabbix item objects\n * @param {Number} timeFrom Time in seconds\n * @param {Number} timeTill Time in seconds\n * @return {Array} Array of Zabbix history objects\n */\n getHistory(items, timeFrom, timeTill) {\n\n // Group items by value type and perform request for each value type\n let grouped_items = _.groupBy(items, 'value_type');\n let promises = _.map(grouped_items, (items, value_type) => {\n let itemids = _.map(items, 'itemid');\n let params = {\n output: 'extend',\n history: value_type,\n itemids: itemids,\n sortfield: 'clock',\n sortorder: 'ASC',\n time_from: timeFrom\n };\n\n // Relative queries (e.g. last hour) don't include an end time\n if (timeTill) {\n params.time_till = timeTill;\n }\n\n return this.request('history.get', params);\n });\n\n return Promise.all(promises).then(_.flatten);\n }\n\n /**\n * Perform trends query from Zabbix API\n * Use trends api extension from ZBXNEXT-1193 patch.\n *\n * @param {Array} items Array of Zabbix item objects\n * @param {Number} time_from Time in seconds\n * @param {Number} time_till Time in seconds\n * @return {Array} Array of Zabbix trend objects\n */\n getTrend_ZBXNEXT1193(items, timeFrom, timeTill) {\n\n // Group items by value type and perform request for each value type\n let grouped_items = _.groupBy(items, 'value_type');\n let promises = _.map(grouped_items, (items, value_type) => {\n let itemids = _.map(items, 'itemid');\n let params = {\n output: 'extend',\n trend: value_type,\n itemids: itemids,\n sortfield: 'clock',\n sortorder: 'ASC',\n time_from: timeFrom\n };\n\n // Relative queries (e.g. last hour) don't include an end time\n if (timeTill) {\n params.time_till = timeTill;\n }\n\n return this.request('trend.get', params);\n });\n\n return Promise.all(promises).then(_.flatten);\n }\n\n getTrend_30(items, time_from, time_till, value_type) {\n var self = this;\n var itemids = _.map(items, 'itemid');\n\n var params = {\n output: [\"itemid\",\n \"clock\",\n value_type\n ],\n itemids: itemids,\n time_from: time_from\n };\n\n // Relative queries (e.g. last hour) don't include an end time\n if (time_till) {\n params.time_till = time_till;\n }\n\n return self.request('trend.get', params);\n }\n\n getITService(serviceids) {\n var params = {\n output: 'extend',\n serviceids: serviceids\n };\n return this.request('service.get', params);\n }\n\n getSLA(serviceids, timeFrom, timeTo) {\n var params = {\n serviceids: serviceids,\n intervals: [{\n from: timeFrom,\n to: timeTo\n }]\n };\n return this.request('service.getsla', params);\n }\n\n getTriggers(groupids, hostids, applicationids, showTriggers, timeFrom, timeTo) {\n var params = {\n output: 'extend',\n groupids: groupids,\n hostids: hostids,\n applicationids: applicationids,\n expandDescription: true,\n expandData: true,\n expandComment: true,\n monitored: true,\n skipDependent: true,\n //only_true: true,\n filter: {\n value: 1\n },\n selectGroups: ['name'],\n selectHosts: ['name', 'host'],\n selectItems: ['name', 'key_', 'lastvalue'],\n selectLastEvent: 'extend'\n };\n\n if (showTriggers) {\n params.filter.value = showTriggers;\n }\n\n if (timeFrom || timeTo) {\n params.lastChangeSince = timeFrom;\n params.lastChangeTill = timeTo;\n }\n\n return this.request('trigger.get', params);\n }\n\n getEvents(objectids, timeFrom, timeTo, showEvents) {\n var params = {\n output: 'extend',\n time_from: timeFrom,\n time_till: timeTo,\n objectids: objectids,\n select_acknowledges: 'extend',\n selectHosts: 'extend',\n value: showEvents\n };\n\n return this.request('event.get', params);\n }\n\n getAcknowledges(eventids) {\n var params = {\n output: 'extend',\n eventids: eventids,\n preservekeys: true,\n select_acknowledges: 'extend',\n sortfield: 'clock',\n sortorder: 'DESC'\n };\n\n return this.request('event.get', params)\n .then(events => {\n return _.filter(events, (event) => event.acknowledges.length);\n });\n }\n\n }\n\n return ZabbixAPI;\n}\n\nfunction isNotAuthorized(message) {\n return (\n message === \"Session terminated, re-login, please.\" ||\n message === \"Not authorised.\" ||\n message === \"Not authorized.\"\n );\n}\n\nangular\n .module('grafana.services')\n .factory('zabbixAPIService', ZabbixAPIServiceFactory);\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/datasource-zabbix/zabbixAPI.service.js"],"names":["ZabbixAPIServiceFactory","alertSrv","zabbixAPICoreService","ZabbixAPI","api_url","username","password","basicAuth","withCredentials","url","auth","requestOptions","loginPromise","loginErrorCount","maxLoginAttempts","zabbixAPICore","getTrend","getTrend_ZBXNEXT1193","method","params","request","catch","isNotAuthorized","error","data","loginOnce","then","message","statusText","alertAPIError","timeout","set","Promise","resolve","login","getVersion","eventid","eventids","output","sortfield","real_hosts","groupids","hostids","appids","itemtype","webitems","filter","selectHosts","applicationids","value_type","expandItems","items","forEach","item","name","utils","expandItemName","key_","itemid","itemids","length","lastvalue","timeFrom","timeTill","grouped_items","_","groupBy","promises","map","history","sortorder","time_from","time_till","all","flatten","trend","self","serviceids","timeTo","intervals","from","to","showTriggers","hideHostsInMaintenance","expandDescription","expandData","expandComment","monitored","skipDependent","value","selectGroups","selectItems","selectLastEvent","maintenance","lastChangeSince","lastChangeTill","objectids","showEvents","select_acknowledges","preservekeys","events","event","acknowledges","angular","module","factory"],"mappings":";;;;;;;;;;;;;AAKA;AACA,WAASA,uBAAT,CAAiCC,QAAjC,EAA2CC,oBAA3C,EAAiE;AAAA,QAOzDC,SAPyD;AAS7D,yBAAYC,OAAZ,EAAqBC,QAArB,EAA+BC,QAA/B,EAAyCC,SAAzC,EAAoDC,eAApD,EAAqE;AAAA;;AACnE,aAAKC,GAAL,GAAwBL,OAAxB;AACA,aAAKC,QAAL,GAAwBA,QAAxB;AACA,aAAKC,QAAL,GAAwBA,QAAxB;AACA,aAAKI,IAAL,GAAwB,EAAxB;;AAEA,aAAKC,cAAL,GAAsB;AACpBJ,qBAAWA,SADS;AAEpBC,2BAAiBA;AAFG,SAAtB;;AAKA,aAAKI,YAAL,GAAoB,IAApB;AACA,aAAKC,eAAL,GAAuB,CAAvB;AACA,aAAKC,gBAAL,GAAwB,CAAxB;;AAEA,aAAKb,QAAL,GAAgBA,QAAhB;AACA,aAAKc,aAAL,GAAqBb,oBAArB;;AAEA,aAAKc,QAAL,GAAgB,KAAKC,oBAArB;AACA;AACD;;AAED;AACA;AACA;;AAjC6D;AAAA;AAAA,gCAmCrDC,MAnCqD,EAmC7CC,MAnC6C,EAmCrC;AAAA;;AACtB,iBAAO,KAAKJ,aAAL,CAAmBK,OAAnB,CA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A,QAFC;AAGX8D,0BAAc,IAHH;AAIXD,iCAAqB,QAJV;AAKX3D,uBAAW,OALA;AAMX+B,uBAAW;AANA,WAAb;;AASA,iBAAO,KAAKlD,OAAL,CAAa,WAAb,EAA0BD,MAA1B,EACNO,IADM,CACD,kBAAU;AACd,mBAAOuC,EAAEnB,MAAF,CAASsD,MAAT,EAAiB,UAACC,KAAD;AAAA,qBAAWA,MAAMC,YAAN,CAAmB1C,MAA9B;AAAA,aAAjB,CAAP;AACD,WAHM,CAAP;AAID;AAzX4D;;AAAA;AAAA;;AA6X/D,WAAOzD,SAAP;AACD;;AAED,WAASmB,eAAT,CAAyBK,OAAzB,EAAkC;AAChC,WACEA,YAAY,uCAAZ,IACAA,YAAY,iBADZ,IAEAA,YAAY,iBAHd;AAKD;;;;AA5YM4E,a;;AACAtC,O;;AACKV,W;;;;;;;;;;;;;;;;;;;;;AA4YZgD,cACGC,MADH,CACU,kBADV,EAEGC,OAFH,CAEW,kBAFX,EAE+BzG,uBAF/B","file":"zabbixAPI.service.js","sourcesContent":["import angular from 'angular';\nimport _ from 'lodash';\nimport * as utils from './utils';\nimport './zabbixAPICore.service';\n\n/** @ngInject */\nfunction ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {\n\n /**\n * Zabbix API Wrapper.\n * Creates Zabbix API instance with given parameters (url, credentials and other).\n * Wraps API calls and provides high-level methods.\n */\n class ZabbixAPI {\n\n constructor(api_url, username, password, basicAuth, withCredentials) {\n this.url = api_url;\n this.username = username;\n this.password = password;\n this.auth = \"\";\n\n this.requestOptions = {\n basicAuth: basicAuth,\n withCredentials: withCredentials\n };\n\n this.loginPromise = null;\n this.loginErrorCount = 0;\n this.maxLoginAttempts = 3;\n\n this.alertSrv = alertSrv;\n this.zabbixAPICore = zabbixAPICoreService;\n\n this.getTrend = this.getTrend_ZBXNEXT1193;\n //getTrend = getTrend_30;\n }\n\n //////////////////////////\n // Core method wrappers //\n //////////////////////////\n\n request(method, params) {\n return this.zabbixAPICore.request(this.url, method, params, this.requestOptions, this.auth)\n .catch(error => {\n if (isNotAuthorized(error.data)) {\n // Handle auth errors\n this.loginErrorCount++;\n if (this.loginErrorCount > this.maxLoginAttempts) {\n this.loginErrorCount = 0;\n return null;\n } else {\n return this.loginOnce()\n .then(() => this.request(method, params));\n }\n } else {\n // Handle API errors\n let message = error.data ? error.data : error.statusText;\n this.alertAPIError(message);\n }\n });\n }\n\n alertAPIError(message, timeout = 5000) {\n this.alertSrv.set(\n \"Zabbix API Error\",\n message,\n 'error',\n timeout\n );\n }\n\n /**\n * When API unauthenticated or auth token expired each request produce login()\n * call. But auth token is common to all requests. This function wraps login() method\n * and call it once. If login() already called just wait for it (return its promise).\n * @return login promise\n */\n loginOnce() {\n if (!this.loginPromise) {\n this.loginPromise = Promise.resolve(\n this.login().then(auth => {\n this.auth = auth;\n this.loginPromise = null;\n return auth;\n })\n );\n }\n return this.loginPromise;\n }\n\n /**\n * Get authentication token.\n */\n login() {\n return this.zabbixAPICore.login(this.url, this.username, this.password, this.requestOptions);\n }\n\n /**\n * Get Zabbix API version\n */\n getVersion() {\n return this.zabbixAPICore.getVersion(this.url, this.requestOptions);\n }\n\n ////////////////////////////////\n // Zabbix API method wrappers //\n ////////////////////////////////\n\n acknowledgeEvent(eventid, message) {\n var params = {\n eventids: eventid,\n message: message\n };\n\n return this.request('event.acknowledge', params);\n }\n\n getGroups() {\n var params = {\n output: ['name'],\n sortfield: 'name',\n real_hosts: true\n };\n\n return this.request('hostgroup.get', params);\n }\n\n getHosts(groupids) {\n var params = {\n output: ['name', 'host'],\n sortfield: 'name'\n };\n if (groupids) {\n params.groupids = groupids;\n }\n\n return this.request('host.get', params);\n }\n\n getApps(hostids) {\n var params = {\n output: ['applicationid', 'name'],\n hostids: hostids\n };\n\n return this.request('application.get', params);\n }\n\n /**\n * Get Zabbix items\n * @param {[type]} hostids host ids\n * @param {[type]} appids application ids\n * @param {String} itemtype 'num' or 'text'\n * @return {[type]} array of items\n */\n getItems(hostids, appids, itemtype) {\n var params = {\n output: [\n 'name', 'key_',\n 'value_type',\n 'hostid',\n 'status',\n 'state'\n ],\n sortfield: 'name',\n webitems: true,\n filter: {},\n selectHosts: [\n 'hostid',\n 'name'\n ]\n };\n if (hostids) {\n params.hostids = hostids;\n }\n if (appids) {\n params.applicationids = appids;\n }\n if (itemtype === 'num') {\n // Return only numeric metrics\n params.filter.value_type = [0, 3];\n }\n if (itemtype === 'text') {\n // Return only text metrics\n params.filter.value_type = [1, 2, 4];\n }\n\n return this.request('item.get', params)\n .then(expandItems);\n\n function expandItems(items) {\n items.forEach(item => {\n item.item = item.name;\n item.name = utils.expandItemName(item.item, item.key_);\n return item;\n });\n return items;\n }\n }\n\n getLastValue(itemid) {\n var params = {\n output: ['lastvalue'],\n itemids: itemid\n };\n return this.request('item.get', params)\n .then(items => items.length ? items[0].lastvalue : null);\n }\n\n /**\n * Perform history query from Zabbix API\n *\n * @param {Array} items Array of Zabbix item objects\n * @param {Number} timeFrom Time in seconds\n * @param {Number} timeTill Time in seconds\n * @return {Array} Array of Zabbix history objects\n */\n getHistory(items, timeFrom, timeTill) {\n\n // Group items by value type and perform request for each value type\n let grouped_items = _.groupBy(items, 'value_type');\n let promises = _.map(grouped_items, (items, value_type) => {\n let itemids = _.map(items, 'itemid');\n let params = {\n output: 'extend',\n history: value_type,\n itemids: itemids,\n sortfield: 'clock',\n sortorder: 'ASC',\n time_from: timeFrom\n };\n\n // Relative queries (e.g. last hour) don't include an end time\n if (timeTill) {\n params.time_till = timeTill;\n }\n\n return this.request('history.get', params);\n });\n\n return Promise.all(promises).then(_.flatten);\n }\n\n /**\n * Perform trends query from Zabbix API\n * Use trends api extension from ZBXNEXT-1193 patch.\n *\n * @param {Array} items Array of Zabbix item objects\n * @param {Number} time_from Time in seconds\n * @param {Number} time_till Time in seconds\n * @return {Array} Array of Zabbix trend objects\n */\n getTrend_ZBXNEXT1193(items, timeFrom, timeTill) {\n\n // Group items by value type and perform request for each value type\n let grouped_items = _.groupBy(items, 'value_type');\n let promises = _.map(grouped_items, (items, value_type) => {\n let itemids = _.map(items, 'itemid');\n let params = {\n output: 'extend',\n trend: value_type,\n itemids: itemids,\n sortfield: 'clock',\n sortorder: 'ASC',\n time_from: timeFrom\n };\n\n // Relative queries (e.g. last hour) don't include an end time\n if (timeTill) {\n params.time_till = timeTill;\n }\n\n return this.request('trend.get', params);\n });\n\n return Promise.all(promises).then(_.flatten);\n }\n\n getTrend_30(items, time_from, time_till, value_type) {\n var self = this;\n var itemids = _.map(items, 'itemid');\n\n var params = {\n output: [\"itemid\",\n \"clock\",\n value_type\n ],\n itemids: itemids,\n time_from: time_from\n };\n\n // Relative queries (e.g. last hour) don't include an end time\n if (time_till) {\n params.time_till = time_till;\n }\n\n return self.request('trend.get', params);\n }\n\n getITService(serviceids) {\n var params = {\n output: 'extend',\n serviceids: serviceids\n };\n return this.request('service.get', params);\n }\n\n getSLA(serviceids, timeFrom, timeTo) {\n var params = {\n serviceids: serviceids,\n intervals: [{\n from: timeFrom,\n to: timeTo\n }]\n };\n return this.request('service.getsla', params);\n }\n\n getTriggers(groupids, hostids, applicationids, showTriggers, hideHostsInMaintenance, timeFrom, timeTo) {\n var params = {\n output: 'extend',\n groupids: groupids,\n hostids: hostids,\n applicationids: applicationids,\n expandDescription: true,\n expandData: true,\n expandComment: true,\n monitored: true,\n skipDependent: true,\n //only_true: true,\n filter: {\n value: 1\n },\n selectGroups: ['name'],\n selectHosts: ['name', 'host'],\n selectItems: ['name', 'key_', 'lastvalue'],\n selectLastEvent: 'extend'\n };\n\n if (showTriggers) {\n params.filter.value = showTriggers;\n }\n\n if (hideHostsInMaintenance) {\n params.maintenance = false;\n }\n\n if (timeFrom || timeTo) {\n params.lastChangeSince = timeFrom;\n params.lastChangeTill = timeTo;\n }\n\n return this.request('trigger.get', params);\n }\n\n getEvents(objectids, timeFrom, timeTo, showEvents) {\n var params = {\n output: 'extend',\n time_from: timeFrom,\n time_till: timeTo,\n objectids: objectids,\n select_acknowledges: 'extend',\n selectHosts: 'extend',\n value: showEvents\n };\n\n return this.request('event.get', params);\n }\n\n getAcknowledges(eventids) {\n var params = {\n output: 'extend',\n eventids: eventids,\n preservekeys: true,\n select_acknowledges: 'extend',\n sortfield: 'clock',\n sortorder: 'DESC'\n };\n\n return this.request('event.get', params)\n .then(events => {\n return _.filter(events, (event) => event.acknowledges.length);\n });\n }\n\n }\n\n return ZabbixAPI;\n}\n\nfunction isNotAuthorized(message) {\n return (\n message === \"Session terminated, re-login, please.\" ||\n message === \"Not authorised.\" ||\n message === \"Not authorized.\"\n );\n}\n\nangular\n .module('grafana.services')\n .factory('zabbixAPIService', ZabbixAPIServiceFactory);\n"]} \ No newline at end of file diff --git a/dist/panel-triggers/editor.html b/dist/panel-triggers/editor.html index b0510dbbd..0f3aacee0 100644 --- a/dist/panel-triggers/editor.html +++ b/dist/panel-triggers/editor.html @@ -138,15 +138,21 @@
Options
-
+
-
+
+ +
diff --git a/dist/panel-triggers/module.js b/dist/panel-triggers/module.js index 1742270b6..abceff18c 100644 --- a/dist/panel-triggers/module.js +++ b/dist/panel-triggers/module.js @@ -97,6 +97,7 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap infoField: true, limit: 10, showTriggers: 'all triggers', + hideHostsInMaintenance: false, sortTriggersBy: { text: 'last change', value: 'lastchange' }, showEvents: { text: 'Problems', value: '1' }, triggerSeverity: defaultSeverity, @@ -181,13 +182,14 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap _this3.zabbix = zabbix; var showEvents = _this3.panel.showEvents.value; var triggerFilter = _this3.panel.triggers; + var hideHostsInMaintenance = _this3.panel.hideHostsInMaintenance; // Replace template variables var groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter); var hostFilter = datasource.replaceTemplateVars(triggerFilter.host.filter); var appFilter = datasource.replaceTemplateVars(triggerFilter.application.filter); - var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents); + var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents, hideHostsInMaintenance); return getTriggers.then(function (triggers) { return _.map(triggers, _this3.formatTrigger.bind(_this3)); }); diff --git a/dist/panel-triggers/module.js.map b/dist/panel-triggers/module.js.map index a78c48bdd..a96118af1 100644 --- a/dist/panel-triggers/module.js.map +++ b/dist/panel-triggers/module.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/panel-triggers/module.js"],"names":["filterTriggers","triggers","triggerFilter","utils","isRegex","_","filter","trigger","buildRegex","test","description","$","moment","PanelCtrl","triggerPanelEditor","defaultSeverity","priority","severity","color","show","panelDefaults","datasource","group","host","application","hostField","statusField","severityField","lastChangeField","ageField","infoField","limit","showTriggers","sortTriggersBy","text","value","showEvents","triggerSeverity","okEventColor","ackEventColor","scroll","pageSize","fontSize","triggerStatusMap","defaultTimeFormat","TriggerPanelCtrl","$scope","$injector","$element","datasourceSrv","templateSrv","contextSrv","pageIndex","triggerList","currentTriggersPage","defaults","panel","cloneDeep","events","on","onInitEditMode","bind","onRefresh","addEditorTab","error","loading","refreshData","then","slice","getCurrentTriggersPage","render","getTriggers","getAcknowledges","get","zabbix","groupFilter","replaceTemplateVars","hostFilter","appFilter","map","formatTrigger","eventids","lastEvent","eventid","each","event","find","acknowledges","timestamp","unix","ack","clock","customLastChangeFormat","time","format","lastChangeFormat","user","alias","name","surname","markAckEvents","length","sortBy","reverse","triggerObj","lastchangeUnix","Number","lastchange","age","fromNow","hosts","hostTechName","showComment","message","grafana_user","ack_message","zabbixAPI","acknowledgeEvent","startPos","endPos","Math","min","scope","elem","attrs","ctrl","data","pageCount","getTableHeight","panelHeight","height","switchPage","e","el","currentTarget","parseInt","$apply","renderPanel","appendPaginationControls","footerElem","empty","ceil","startPage","max","endPage","paginationList","i","activeClass","pageLinkElem","append","panelElem","parents","rootElem","css","addClass","unbindDestroy","$on","off","renderData","renderingCompleted","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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/**\n * Grafana-Zabbix\n * Zabbix plugin for Grafana.\n * http://github.com/alexanderzobnin/grafana-zabbix\n *\n * Trigger panel.\n * This feature sponsored by CORE IT\n * http://www.coreit.fr\n *\n * Copyright 2015 Alexander Zobnin alexanderzobnin@gmail.com\n * Licensed under the Apache License, Version 2.0\n */\n\nimport _ from 'lodash';\nimport $ from 'jquery';\nimport moment from 'moment';\nimport * as utils from '../datasource-zabbix/utils';\nimport {PanelCtrl} from 'app/plugins/sdk';\nimport {triggerPanelEditor} from './editor';\nimport './ack-tooltip.directive';\nimport './css/panel_triggers.css!';\n\nvar defaultSeverity = [\n { priority: 0, severity: 'Not classified', color: '#B7DBAB', show: true },\n { priority: 1, severity: 'Information', color: '#82B5D8', show: true },\n { priority: 2, severity: 'Warning', color: '#E5AC0E', show: true },\n { priority: 3, severity: 'Average', color: '#C15C17', show: true },\n { priority: 4, severity: 'High', color: '#BF1B00', show: true },\n { priority: 5, severity: 'Disaster', color: '#890F02', show: true }\n];\n\nvar panelDefaults = {\n datasource: null,\n triggers: {\n group: {filter: \"\"},\n host: {filter: \"\"},\n application: {filter: \"\"},\n trigger: {filter: \"\"}\n },\n hostField: true,\n statusField: false,\n severityField: false,\n lastChangeField: true,\n ageField: true,\n infoField: true,\n limit: 10,\n showTriggers: 'all triggers',\n sortTriggersBy: { text: 'last change', value: 'lastchange' },\n showEvents: { text: 'Problems', value: '1' },\n triggerSeverity: defaultSeverity,\n okEventColor: 'rgba(0, 245, 153, 0.45)',\n ackEventColor: 'rgba(0, 0, 0, 0)',\n scroll: true,\n pageSize: 10,\n fontSize: '100%',\n};\n\nvar triggerStatusMap = {\n '0': 'OK',\n '1': 'Problem'\n};\n\nvar defaultTimeFormat = \"DD MMM YYYY HH:mm:ss\";\n\nclass TriggerPanelCtrl extends PanelCtrl {\n\n /** @ngInject */\n constructor($scope, $injector, $element, datasourceSrv, templateSrv, contextSrv) {\n super($scope, $injector);\n this.datasourceSrv = datasourceSrv;\n this.templateSrv = templateSrv;\n this.contextSrv = contextSrv;\n this.triggerStatusMap = triggerStatusMap;\n this.defaultTimeFormat = defaultTimeFormat;\n this.pageIndex = 0;\n this.triggerList = [];\n this.currentTriggersPage = [];\n\n // Load panel defaults\n // _.cloneDeep() need for prevent changing shared defaultSeverity.\n // Load object \"by value\" istead \"by reference\".\n _.defaults(this.panel, _.cloneDeep(panelDefaults));\n\n this.events.on('init-edit-mode', this.onInitEditMode.bind(this));\n this.events.on('refresh', this.onRefresh.bind(this));\n }\n\n onInitEditMode() {\n this.addEditorTab('Options', triggerPanelEditor, 2);\n }\n\n onRefresh() {\n // clear loading/error state\n delete this.error;\n this.loading = true;\n\n return this.refreshData()\n .then(triggerList => {\n // Limit triggers number\n this.triggerList = triggerList.slice(0, this.panel.limit);\n\n this.getCurrentTriggersPage();\n\n // Notify panel that request is finished\n this.loading = false;\n\n this.render(this.triggerList);\n });\n }\n\n refreshData() {\n return this.getTriggers()\n .then(this.getAcknowledges.bind(this))\n .then(this.filterTriggers.bind(this));\n }\n\n getTriggers() {\n return this.datasourceSrv.get(this.panel.datasource)\n .then(datasource => {\n var zabbix = datasource.zabbix;\n this.zabbix = zabbix;\n var showEvents = this.panel.showEvents.value;\n var triggerFilter = this.panel.triggers;\n\n // Replace template variables\n var groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter);\n var hostFilter = datasource.replaceTemplateVars(triggerFilter.host.filter);\n var appFilter = datasource.replaceTemplateVars(triggerFilter.application.filter);\n\n var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents);\n return getTriggers.then(triggers => {\n return _.map(triggers, this.formatTrigger.bind(this));\n });\n });\n }\n\n getAcknowledges(triggerList) {\n // Request acknowledges for trigger\n var eventids = _.map(triggerList, trigger => {\n return trigger.lastEvent.eventid;\n });\n\n return this.zabbix.getAcknowledges(eventids)\n .then(events => {\n\n // Map events to triggers\n _.each(triggerList, trigger => {\n var event = _.find(events, event => {\n return event.eventid === trigger.lastEvent.eventid;\n });\n\n if (event) {\n trigger.acknowledges = _.map(event.acknowledges, ack => {\n let timestamp = moment.unix(ack.clock);\n if (this.panel.customLastChangeFormat) {\n ack.time = timestamp.format(this.panel.lastChangeFormat);\n } else {\n ack.time = timestamp.format(this.defaultTimeFormat);\n }\n ack.user = ack.alias + ' (' + ack.name + ' ' + ack.surname + ')';\n return ack;\n });\n\n // Mark acknowledged triggers with different color\n if (this.panel.markAckEvents && trigger.acknowledges.length) {\n trigger.color = this.panel.ackEventColor;\n }\n }\n });\n\n return triggerList;\n });\n }\n\n filterTriggers(triggerList) {\n // Filter triggers by description\n var triggerFilter = this.panel.triggers.trigger.filter;\n if (triggerFilter) {\n triggerList = filterTriggers(triggerList, triggerFilter);\n }\n\n // Filter acknowledged triggers\n if (this.panel.showTriggers === 'unacknowledged') {\n triggerList = _.filter(triggerList, trigger => {\n return !trigger.acknowledges;\n });\n } else if (this.panel.showTriggers === 'acknowledged') {\n triggerList = _.filter(triggerList, 'acknowledges');\n } else {\n triggerList = triggerList;\n }\n\n // Filter triggers by severity\n triggerList = _.filter(triggerList, trigger => {\n return this.panel.triggerSeverity[trigger.priority].show;\n });\n\n // Sort triggers\n if (this.panel.sortTriggersBy.value === 'priority') {\n triggerList = _.sortBy(triggerList, 'priority').reverse();\n } else {\n triggerList = _.sortBy(triggerList, 'lastchangeUnix').reverse();\n }\n\n return triggerList;\n }\n\n formatTrigger(trigger) {\n let triggerObj = trigger;\n\n // Format last change and age\n trigger.lastchangeUnix = Number(trigger.lastchange);\n let timestamp = moment.unix(trigger.lastchangeUnix);\n if (this.panel.customLastChangeFormat) {\n // User defined format\n triggerObj.lastchange = timestamp.format(this.panel.lastChangeFormat);\n } else {\n triggerObj.lastchange = timestamp.format(this.defaultTimeFormat);\n }\n triggerObj.age = timestamp.fromNow(true);\n\n // Set host that the trigger belongs\n if (trigger.hosts.length) {\n triggerObj.host = trigger.hosts[0].name;\n triggerObj.hostTechName = trigger.hosts[0].host;\n }\n\n // Set color\n if (trigger.value === '1') {\n // Problem state\n triggerObj.color = this.panel.triggerSeverity[trigger.priority].color;\n } else {\n // OK state\n triggerObj.color = this.panel.okEventColor;\n }\n\n triggerObj.severity = this.panel.triggerSeverity[trigger.priority].severity;\n return triggerObj;\n }\n\n switchComment(trigger) {\n trigger.showComment = !trigger.showComment;\n }\n\n acknowledgeTrigger(trigger, message) {\n let eventid = trigger.lastEvent.eventid;\n let grafana_user = this.contextSrv.user.name;\n let ack_message = grafana_user + ' (Grafana): ' + message;\n return this.datasourceSrv.get(this.panel.datasource)\n .then(datasource => {\n let zabbixAPI = datasource.zabbix.zabbixAPI;\n return zabbixAPI.acknowledgeEvent(eventid, ack_message);\n })\n .then(this.onRefresh.bind(this));\n }\n\n getCurrentTriggersPage() {\n let pageSize = this.panel.pageSize || 10;\n let startPos = this.pageIndex * pageSize;\n let endPos = Math.min(startPos + pageSize, this.triggerList.length);\n this.currentTriggersPage = this.triggerList.slice(startPos, endPos);\n return this.currentTriggersPage;\n }\n\n link(scope, elem, attrs, ctrl) {\n var data;\n var panel = ctrl.panel;\n var pageCount = 0;\n data = ctrl.triggerList;\n\n function getTableHeight() {\n var panelHeight = ctrl.height;\n\n if (pageCount > 1) {\n panelHeight -= 26;\n }\n\n return (panelHeight - 31) + 'px';\n }\n\n function switchPage(e) {\n let el = $(e.currentTarget);\n ctrl.pageIndex = (parseInt(el.text(), 10)-1);\n\n let pageSize = ctrl.panel.pageSize || 10;\n let startPos = ctrl.pageIndex * pageSize;\n let endPos = Math.min(startPos + pageSize, ctrl.triggerList.length);\n ctrl.currentTriggersPage = ctrl.triggerList.slice(startPos, endPos);\n\n scope.$apply();\n renderPanel();\n }\n\n function appendPaginationControls(footerElem) {\n footerElem.empty();\n\n var pageSize = ctrl.panel.pageSize || 5;\n pageCount = Math.ceil(data.length / pageSize);\n if (pageCount === 1) {\n return;\n }\n\n var startPage = Math.max(ctrl.pageIndex - 3, 0);\n var endPage = Math.min(pageCount, startPage + 9);\n\n var paginationList = $('');\n\n for (var i = startPage; i < endPage; i++) {\n var activeClass = i === ctrl.pageIndex ? 'active' : '';\n var pageLinkElem = $('
  • ' + (i+1) + '
  • ');\n paginationList.append(pageLinkElem);\n }\n\n footerElem.append(paginationList);\n }\n\n function renderPanel() {\n var panelElem = elem.parents('.panel');\n var rootElem = elem.find('.triggers-panel-scroll');\n var footerElem = elem.find('.triggers-panel-footer');\n\n elem.css({'font-size': panel.fontSize});\n panelElem.addClass('triggers-panel-wrapper');\n appendPaginationControls(footerElem);\n\n rootElem.css({'max-height': panel.scroll ? getTableHeight() : '' });\n }\n\n elem.on('click', '.triggers-panel-page-link', switchPage);\n\n var unbindDestroy = scope.$on('$destroy', function() {\n elem.off('click', '.triggers-panel-page-link');\n unbindDestroy();\n });\n\n ctrl.events.on('render', (renderData) => {\n data = renderData || data;\n if (data) {\n renderPanel();\n }\n ctrl.renderingCompleted();\n });\n }\n}\n\nTriggerPanelCtrl.templateUrl = 'panel-triggers/module.html';\n\nfunction filterTriggers(triggers, triggerFilter) {\n if (utils.isRegex(triggerFilter)) {\n return _.filter(triggers, function(trigger) {\n return utils.buildRegex(triggerFilter).test(trigger.description);\n });\n } else {\n return _.filter(triggers, function(trigger) {\n return trigger.description === triggerFilter;\n });\n }\n}\n\nexport {\n TriggerPanelCtrl,\n TriggerPanelCtrl as PanelCtrl\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/panel-triggers/module.js"],"names":["filterTriggers","triggers","triggerFilter","utils","isRegex","_","filter","trigger","buildRegex","test","description","$","moment","PanelCtrl","triggerPanelEditor","defaultSeverity","priority","severity","color","show","panelDefaults","datasource","group","host","application","hostField","statusField","severityField","lastChangeField","ageField","infoField","limit","showTriggers","hideHostsInMaintenance","sortTriggersBy","text","value","showEvents","triggerSeverity","okEventColor","ackEventColor","scroll","pageSize","fontSize","triggerStatusMap","defaultTimeFormat","TriggerPanelCtrl","$scope","$injector","$element","datasourceSrv","templateSrv","contextSrv","pageIndex","triggerList","currentTriggersPage","defaults","panel","cloneDeep","events","on","onInitEditMode","bind","onRefresh","addEditorTab","error","loading","refreshData","then","slice","getCurrentTriggersPage","render","getTriggers","getAcknowledges","get","zabbix","groupFilter","replaceTemplateVars","hostFilter","appFilter","map","formatTrigger","eventids","lastEvent","eventid","each","event","find","acknowledges","timestamp","unix","ack","clock","customLastChangeFormat","time","format","lastChangeFormat","user","alias","name","surname","markAckEvents","length","sortBy","reverse","triggerObj","lastchangeUnix","Number","lastchange","age","fromNow","hosts","hostTechName","showComment","message","grafana_user","ack_message","zabbixAPI","acknowledgeEvent","startPos","endPos","Math","min","scope","elem","attrs","ctrl","data","pageCount","getTableHeight","panelHeight","height","switchPage","e","el","currentTarget","parseInt","$apply","renderPanel","appendPaginationControls","footerElem","empty","ceil","startPage","max","endPage","paginationList","i","activeClass","pageLinkElem","append","panelElem","parents","rootElem","css","addClass","unbindDestroy","$on","off","renderData","renderingCompleted","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6VA,WAASA,eAAT,CAAwBC,QAAxB,EAAkCC,aAAlC,EAAiD;AAC/C,QAAIC,MAAMC,OAAN,CAAcF,aAAd,CAAJ,EAAkC;AAChC,aAAOG,EAAEC,MAAF,CAASL,QAAT,EAAmB,UAASM,OAAT,EAAkB;AAC1C,eAAOJ,MAAMK,UAAN,CAAiBN,aAAjB,EAAgCO,IAAhC,CAAqCF,QAAQG,WAA7C,CAAP;AACD,OAFM,CAAP;AAGD,KAJD,MAIO;AACL,aAAOL,EAAEC,MAAF,CAASL,QAAT,EAAmB,UAASM,OAAT,EAAkB;AAC1C,eAAOA,QAAQG,WAAR,KAAwBR,aAA/B;AACD,OAFM,CAAP;AAGD;AACF;;;;AA1VMG,O;;AACAM,O;;AACAC,Y;;AACKT,W;;AACJU,e,kBAAAA,S;;AACAC,wB,WAAAA,kB;;;;;;;;;;;;;;;;;;;;;AAIJC,qB,GAAkB,CACpB,EAAEC,UAAU,CAAZ,EAAeC,UAAU,gBAAz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EAqC,mBAAK8B,GAAL,CAAS,EAAC,aAAajG,MAAMd,QAApB,EAAT;AACA4G,wBAAUI,QAAV,CAAmB,wBAAnB;AACAhB,uCAAyBC,UAAzB;;AAEAa,uBAASC,GAAT,CAAa,EAAC,cAAcjG,MAAMhB,MAAN,GAAewF,gBAAf,GAAkC,EAAjD,EAAb;AACD;;AAEDL,iBAAKhE,EAAL,CAAQ,OAAR,EAAiB,2BAAjB,EAA8CwE,UAA9C;;AAEA,gBAAIwB,gBAAgBjC,MAAMkC,GAAN,CAAU,UAAV,EAAsB,YAAW;AACnDjC,mBAAKkC,GAAL,CAAS,OAAT,EAAkB,2BAAlB;AACAF;AACD,aAHmB,CAApB;;AAKA9B,iBAAKnE,MAAL,CAAYC,EAAZ,CAAe,QAAf,EAAyB,UAACmG,UAAD,EAAgB;AACvChC,qBAAOgC,cAAchC,IAArB;AACA,kBAAIA,IAAJ,EAAU;AACRW;AACD;AACDZ,mBAAKkC,kBAAL;AACD,aAND;AAOD;;;;QAvR4BnJ,S;;AA0R/BiC,uBAAiBmH,WAAjB,GAA+B,4BAA/B;kCAeEnH,gB;;2BACAA,gB","file":"module.js","sourcesContent":["/**\n * Grafana-Zabbix\n * Zabbix plugin for Grafana.\n * http://github.com/alexanderzobnin/grafana-zabbix\n *\n * Trigger panel.\n * This feature sponsored by CORE IT\n * http://www.coreit.fr\n *\n * Copyright 2015 Alexander Zobnin alexanderzobnin@gmail.com\n * Licensed under the Apache License, Version 2.0\n */\n\nimport _ from 'lodash';\nimport $ from 'jquery';\nimport moment from 'moment';\nimport * as utils from '../datasource-zabbix/utils';\nimport {PanelCtrl} from 'app/plugins/sdk';\nimport {triggerPanelEditor} from './editor';\nimport './ack-tooltip.directive';\nimport './css/panel_triggers.css!';\n\nvar defaultSeverity = [\n { priority: 0, severity: 'Not classified', color: '#B7DBAB', show: true },\n { priority: 1, severity: 'Information', color: '#82B5D8', show: true },\n { priority: 2, severity: 'Warning', color: '#E5AC0E', show: true },\n { priority: 3, severity: 'Average', color: '#C15C17', show: true },\n { priority: 4, severity: 'High', color: '#BF1B00', show: true },\n { priority: 5, severity: 'Disaster', color: '#890F02', show: true }\n];\n\nvar panelDefaults = {\n datasource: null,\n triggers: {\n group: {filter: \"\"},\n host: {filter: \"\"},\n application: {filter: \"\"},\n trigger: {filter: \"\"}\n },\n hostField: true,\n statusField: false,\n severityField: false,\n lastChangeField: true,\n ageField: true,\n infoField: true,\n limit: 10,\n showTriggers: 'all triggers',\n hideHostsInMaintenance: false,\n sortTriggersBy: { text: 'last change', value: 'lastchange' },\n showEvents: { text: 'Problems', value: '1' },\n triggerSeverity: defaultSeverity,\n okEventColor: 'rgba(0, 245, 153, 0.45)',\n ackEventColor: 'rgba(0, 0, 0, 0)',\n scroll: true,\n pageSize: 10,\n fontSize: '100%',\n};\n\nvar triggerStatusMap = {\n '0': 'OK',\n '1': 'Problem'\n};\n\nvar defaultTimeFormat = \"DD MMM YYYY HH:mm:ss\";\n\nclass TriggerPanelCtrl extends PanelCtrl {\n\n /** @ngInject */\n constructor($scope, $injector, $element, datasourceSrv, templateSrv, contextSrv) {\n super($scope, $injector);\n this.datasourceSrv = datasourceSrv;\n this.templateSrv = templateSrv;\n this.contextSrv = contextSrv;\n this.triggerStatusMap = triggerStatusMap;\n this.defaultTimeFormat = defaultTimeFormat;\n this.pageIndex = 0;\n this.triggerList = [];\n this.currentTriggersPage = [];\n\n // Load panel defaults\n // _.cloneDeep() need for prevent changing shared defaultSeverity.\n // Load object \"by value\" istead \"by reference\".\n _.defaults(this.panel, _.cloneDeep(panelDefaults));\n\n this.events.on('init-edit-mode', this.onInitEditMode.bind(this));\n this.events.on('refresh', this.onRefresh.bind(this));\n }\n\n onInitEditMode() {\n this.addEditorTab('Options', triggerPanelEditor, 2);\n }\n\n onRefresh() {\n // clear loading/error state\n delete this.error;\n this.loading = true;\n\n return this.refreshData()\n .then(triggerList => {\n // Limit triggers number\n this.triggerList = triggerList.slice(0, this.panel.limit);\n\n this.getCurrentTriggersPage();\n\n // Notify panel that request is finished\n this.loading = false;\n\n this.render(this.triggerList);\n });\n }\n\n refreshData() {\n return this.getTriggers()\n .then(this.getAcknowledges.bind(this))\n .then(this.filterTriggers.bind(this));\n }\n\n getTriggers() {\n return this.datasourceSrv.get(this.panel.datasource)\n .then(datasource => {\n var zabbix = datasource.zabbix;\n this.zabbix = zabbix;\n var showEvents = this.panel.showEvents.value;\n var triggerFilter = this.panel.triggers;\n var hideHostsInMaintenance = this.panel.hideHostsInMaintenance;\n\n // Replace template variables\n var groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter);\n var hostFilter = datasource.replaceTemplateVars(triggerFilter.host.filter);\n var appFilter = datasource.replaceTemplateVars(triggerFilter.application.filter);\n\n var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents, hideHostsInMaintenance);\n return getTriggers.then(triggers => {\n return _.map(triggers, this.formatTrigger.bind(this));\n });\n });\n }\n\n getAcknowledges(triggerList) {\n // Request acknowledges for trigger\n var eventids = _.map(triggerList, trigger => {\n return trigger.lastEvent.eventid;\n });\n\n return this.zabbix.getAcknowledges(eventids)\n .then(events => {\n\n // Map events to triggers\n _.each(triggerList, trigger => {\n var event = _.find(events, event => {\n return event.eventid === trigger.lastEvent.eventid;\n });\n\n if (event) {\n trigger.acknowledges = _.map(event.acknowledges, ack => {\n let timestamp = moment.unix(ack.clock);\n if (this.panel.customLastChangeFormat) {\n ack.time = timestamp.format(this.panel.lastChangeFormat);\n } else {\n ack.time = timestamp.format(this.defaultTimeFormat);\n }\n ack.user = ack.alias + ' (' + ack.name + ' ' + ack.surname + ')';\n return ack;\n });\n\n // Mark acknowledged triggers with different color\n if (this.panel.markAckEvents && trigger.acknowledges.length) {\n trigger.color = this.panel.ackEventColor;\n }\n }\n });\n\n return triggerList;\n });\n }\n\n filterTriggers(triggerList) {\n // Filter triggers by description\n var triggerFilter = this.panel.triggers.trigger.filter;\n if (triggerFilter) {\n triggerList = filterTriggers(triggerList, triggerFilter);\n }\n\n // Filter acknowledged triggers\n if (this.panel.showTriggers === 'unacknowledged') {\n triggerList = _.filter(triggerList, trigger => {\n return !trigger.acknowledges;\n });\n } else if (this.panel.showTriggers === 'acknowledged') {\n triggerList = _.filter(triggerList, 'acknowledges');\n } else {\n triggerList = triggerList;\n }\n\n // Filter triggers by severity\n triggerList = _.filter(triggerList, trigger => {\n return this.panel.triggerSeverity[trigger.priority].show;\n });\n\n // Sort triggers\n if (this.panel.sortTriggersBy.value === 'priority') {\n triggerList = _.sortBy(triggerList, 'priority').reverse();\n } else {\n triggerList = _.sortBy(triggerList, 'lastchangeUnix').reverse();\n }\n\n return triggerList;\n }\n\n formatTrigger(trigger) {\n let triggerObj = trigger;\n\n // Format last change and age\n trigger.lastchangeUnix = Number(trigger.lastchange);\n let timestamp = moment.unix(trigger.lastchangeUnix);\n if (this.panel.customLastChangeFormat) {\n // User defined format\n triggerObj.lastchange = timestamp.format(this.panel.lastChangeFormat);\n } else {\n triggerObj.lastchange = timestamp.format(this.defaultTimeFormat);\n }\n triggerObj.age = timestamp.fromNow(true);\n\n // Set host that the trigger belongs\n if (trigger.hosts.length) {\n triggerObj.host = trigger.hosts[0].name;\n triggerObj.hostTechName = trigger.hosts[0].host;\n }\n\n // Set color\n if (trigger.value === '1') {\n // Problem state\n triggerObj.color = this.panel.triggerSeverity[trigger.priority].color;\n } else {\n // OK state\n triggerObj.color = this.panel.okEventColor;\n }\n\n triggerObj.severity = this.panel.triggerSeverity[trigger.priority].severity;\n return triggerObj;\n }\n\n switchComment(trigger) {\n trigger.showComment = !trigger.showComment;\n }\n\n acknowledgeTrigger(trigger, message) {\n let eventid = trigger.lastEvent.eventid;\n let grafana_user = this.contextSrv.user.name;\n let ack_message = grafana_user + ' (Grafana): ' + message;\n return this.datasourceSrv.get(this.panel.datasource)\n .then(datasource => {\n let zabbixAPI = datasource.zabbix.zabbixAPI;\n return zabbixAPI.acknowledgeEvent(eventid, ack_message);\n })\n .then(this.onRefresh.bind(this));\n }\n\n getCurrentTriggersPage() {\n let pageSize = this.panel.pageSize || 10;\n let startPos = this.pageIndex * pageSize;\n let endPos = Math.min(startPos + pageSize, this.triggerList.length);\n this.currentTriggersPage = this.triggerList.slice(startPos, endPos);\n return this.currentTriggersPage;\n }\n\n link(scope, elem, attrs, ctrl) {\n var data;\n var panel = ctrl.panel;\n var pageCount = 0;\n data = ctrl.triggerList;\n\n function getTableHeight() {\n var panelHeight = ctrl.height;\n\n if (pageCount > 1) {\n panelHeight -= 26;\n }\n\n return (panelHeight - 31) + 'px';\n }\n\n function switchPage(e) {\n let el = $(e.currentTarget);\n ctrl.pageIndex = (parseInt(el.text(), 10)-1);\n\n let pageSize = ctrl.panel.pageSize || 10;\n let startPos = ctrl.pageIndex * pageSize;\n let endPos = Math.min(startPos + pageSize, ctrl.triggerList.length);\n ctrl.currentTriggersPage = ctrl.triggerList.slice(startPos, endPos);\n\n scope.$apply();\n renderPanel();\n }\n\n function appendPaginationControls(footerElem) {\n footerElem.empty();\n\n var pageSize = ctrl.panel.pageSize || 5;\n pageCount = Math.ceil(data.length / pageSize);\n if (pageCount === 1) {\n return;\n }\n\n var startPage = Math.max(ctrl.pageIndex - 3, 0);\n var endPage = Math.min(pageCount, startPage + 9);\n\n var paginationList = $('');\n\n for (var i = startPage; i < endPage; i++) {\n var activeClass = i === ctrl.pageIndex ? 'active' : '';\n var pageLinkElem = $('
  • ' + (i+1) + '
  • ');\n paginationList.append(pageLinkElem);\n }\n\n footerElem.append(paginationList);\n }\n\n function renderPanel() {\n var panelElem = elem.parents('.panel');\n var rootElem = elem.find('.triggers-panel-scroll');\n var footerElem = elem.find('.triggers-panel-footer');\n\n elem.css({'font-size': panel.fontSize});\n panelElem.addClass('triggers-panel-wrapper');\n appendPaginationControls(footerElem);\n\n rootElem.css({'max-height': panel.scroll ? getTableHeight() : '' });\n }\n\n elem.on('click', '.triggers-panel-page-link', switchPage);\n\n var unbindDestroy = scope.$on('$destroy', function() {\n elem.off('click', '.triggers-panel-page-link');\n unbindDestroy();\n });\n\n ctrl.events.on('render', (renderData) => {\n data = renderData || data;\n if (data) {\n renderPanel();\n }\n ctrl.renderingCompleted();\n });\n }\n}\n\nTriggerPanelCtrl.templateUrl = 'panel-triggers/module.html';\n\nfunction filterTriggers(triggers, triggerFilter) {\n if (utils.isRegex(triggerFilter)) {\n return _.filter(triggers, function(trigger) {\n return utils.buildRegex(triggerFilter).test(trigger.description);\n });\n } else {\n return _.filter(triggers, function(trigger) {\n return trigger.description === triggerFilter;\n });\n }\n}\n\nexport {\n TriggerPanelCtrl,\n TriggerPanelCtrl as PanelCtrl\n};\n"]} \ No newline at end of file diff --git a/dist/test/datasource-zabbix/zabbix.js b/dist/test/datasource-zabbix/zabbix.js index 627d1074b..a34593f74 100644 --- a/dist/test/datasource-zabbix/zabbix.js +++ b/dist/test/datasource-zabbix/zabbix.js @@ -172,7 +172,7 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) { }, { key: 'getTriggers', - value: function getTriggers(groupFilter, hostFilter, appFilter, showTriggers) { + value: function getTriggers(groupFilter, hostFilter, appFilter, showTriggers, hideHostsInMaintenance) { var _this5 = this; var promises = [this.getGroups(groupFilter), this.getHosts(groupFilter, hostFilter), this.getApps(groupFilter, hostFilter, appFilter)]; @@ -195,7 +195,7 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) { return query; }).then(function (query) { - return _this5.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers); + return _this5.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers, hideHostsInMaintenance); }); } }]); diff --git a/dist/test/datasource-zabbix/zabbixAPI.service.js b/dist/test/datasource-zabbix/zabbixAPI.service.js index cd82a1314..ac0d3a648 100644 --- a/dist/test/datasource-zabbix/zabbixAPI.service.js +++ b/dist/test/datasource-zabbix/zabbixAPI.service.js @@ -356,7 +356,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) { } }, { key: 'getTriggers', - value: function getTriggers(groupids, hostids, applicationids, showTriggers, timeFrom, timeTo) { + value: function getTriggers(groupids, hostids, applicationids, showTriggers, hideHostsInMaintenance, timeFrom, timeTo) { var params = { output: 'extend', groupids: groupids, @@ -381,6 +381,10 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) { params.filter.value = showTriggers; } + if (hideHostsInMaintenance) { + params.maintenance = false; + } + if (timeFrom || timeTo) { params.lastChangeSince = timeFrom; params.lastChangeTill = timeTo; diff --git a/dist/test/panel-triggers/module.js b/dist/test/panel-triggers/module.js index 201cd1d65..ba6fbe5f6 100644 --- a/dist/test/panel-triggers/module.js +++ b/dist/test/panel-triggers/module.js @@ -70,6 +70,7 @@ var panelDefaults = { infoField: true, limit: 10, showTriggers: 'all triggers', + hideHostsInMaintenance: false, sortTriggersBy: { text: 'last change', value: 'lastchange' }, showEvents: { text: 'Problems', value: '1' }, triggerSeverity: defaultSeverity, @@ -156,13 +157,14 @@ var TriggerPanelCtrl = function (_PanelCtrl) { _this3.zabbix = zabbix; var showEvents = _this3.panel.showEvents.value; var triggerFilter = _this3.panel.triggers; + var hideHostsInMaintenance = _this3.panel.hideHostsInMaintenance; // Replace template variables var groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter); var hostFilter = datasource.replaceTemplateVars(triggerFilter.host.filter); var appFilter = datasource.replaceTemplateVars(triggerFilter.application.filter); - var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents); + var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents, hideHostsInMaintenance); return getTriggers.then(function (triggers) { return _lodash2.default.map(triggers, _this3.formatTrigger.bind(_this3)); }); diff --git a/src/datasource-zabbix/zabbix.js b/src/datasource-zabbix/zabbix.js index 254d79b3c..23e91f2f8 100644 --- a/src/datasource-zabbix/zabbix.js +++ b/src/datasource-zabbix/zabbix.js @@ -120,7 +120,7 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) { /** * Build query - convert target filters to array of Zabbix items */ - getTriggers(groupFilter, hostFilter, appFilter, showTriggers) { + getTriggers(groupFilter, hostFilter, appFilter, showTriggers, hideHostsInMaintenance) { let promises = [ this.getGroups(groupFilter), this.getHosts(groupFilter, hostFilter), @@ -147,7 +147,7 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) { return query; }).then(query => { return this.zabbixAPI - .getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers); + .getTriggers(query.groupids, query.hostids, query.applicationids, showTriggers, hideHostsInMaintenance); }); } } diff --git a/src/datasource-zabbix/zabbixAPI.service.js b/src/datasource-zabbix/zabbixAPI.service.js index 735888b88..3f7d80401 100644 --- a/src/datasource-zabbix/zabbixAPI.service.js +++ b/src/datasource-zabbix/zabbixAPI.service.js @@ -316,7 +316,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) { return this.request('service.getsla', params); } - getTriggers(groupids, hostids, applicationids, showTriggers, timeFrom, timeTo) { + getTriggers(groupids, hostids, applicationids, showTriggers, hideHostsInMaintenance, timeFrom, timeTo) { var params = { output: 'extend', groupids: groupids, @@ -341,6 +341,10 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) { params.filter.value = showTriggers; } + if (hideHostsInMaintenance) { + params.maintenance = false; + } + if (timeFrom || timeTo) { params.lastChangeSince = timeFrom; params.lastChangeTill = timeTo; diff --git a/src/panel-triggers/editor.html b/src/panel-triggers/editor.html index b0510dbbd..0f3aacee0 100644 --- a/src/panel-triggers/editor.html +++ b/src/panel-triggers/editor.html @@ -138,15 +138,21 @@
    Options
    -
    +
    -
    +
    + +
    diff --git a/src/panel-triggers/module.js b/src/panel-triggers/module.js index 1d9eab197..b4a977f22 100644 --- a/src/panel-triggers/module.js +++ b/src/panel-triggers/module.js @@ -45,6 +45,7 @@ var panelDefaults = { infoField: true, limit: 10, showTriggers: 'all triggers', + hideHostsInMaintenance: false, sortTriggersBy: { text: 'last change', value: 'lastchange' }, showEvents: { text: 'Problems', value: '1' }, triggerSeverity: defaultSeverity, @@ -121,13 +122,14 @@ class TriggerPanelCtrl extends PanelCtrl { this.zabbix = zabbix; var showEvents = this.panel.showEvents.value; var triggerFilter = this.panel.triggers; + var hideHostsInMaintenance = this.panel.hideHostsInMaintenance; // Replace template variables var groupFilter = datasource.replaceTemplateVars(triggerFilter.group.filter); var hostFilter = datasource.replaceTemplateVars(triggerFilter.host.filter); var appFilter = datasource.replaceTemplateVars(triggerFilter.application.filter); - var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents); + var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, showEvents, hideHostsInMaintenance); return getTriggers.then(triggers => { return _.map(triggers, this.formatTrigger.bind(this)); });