diff --git a/dist/panel-triggers/module.html b/dist/panel-triggers/module.html index 23c3ce064..7b5fefa07 100644 --- a/dist/panel-triggers/module.html +++ b/dist/panel-triggers/module.html @@ -35,7 +35,7 @@ - +
diff --git a/dist/panel-triggers/module.js b/dist/panel-triggers/module.js index fd636c602..319cdee2a 100644 --- a/dist/panel-triggers/module.js +++ b/dist/panel-triggers/module.js @@ -134,13 +134,10 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap _.defaults(_this.panel, _.cloneDeep(panelDefaults)); _this.triggerList = []; - _this.currentPage = []; + _this.currentTriggersPage = []; _this.events.on('init-edit-mode', _this.onInitEditMode.bind(_this)); - _this.events.on('render', _this.onRender.bind(_this)); - _this.events.on('refresh', _this.onRender.bind(_this)); - - _this.refreshData(); + _this.events.on('refresh', _this.onRefresh.bind(_this)); return _this; } @@ -166,8 +163,8 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap this.refreshData(); } }, { - key: 'onRender', - value: function onRender() { + key: 'onRefresh', + value: function onRefresh() { var _this2 = this; // clear loading/error state @@ -178,8 +175,12 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap // Limit triggers number _this2.triggerList = triggerList.slice(0, _this2.panel.limit); + _this2.getCurrentTriggersPage(); + // Notify panel that request is finished _this2.loading = false; + + _this2.render(_this2.triggerList); }); } }, { @@ -327,17 +328,22 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap }, { key: 'acknowledgeTrigger', value: function acknowledgeTrigger(trigger, message) { - var _this6 = this; - var eventid = trigger.lastEvent.eventid; var grafana_user = this.contextSrv.user.name; var ack_message = grafana_user + ' (Grafana): ' + message; return this.datasourceSrv.get(this.panel.datasource).then(function (datasource) { var zabbixAPI = datasource.zabbix.zabbixAPI; - return zabbixAPI.acknowledgeEvent(eventid, ack_message).then(function () { - _this6.refresh(); - }); - }); + return zabbixAPI.acknowledgeEvent(eventid, ack_message); + }).then(this.onRefresh.bind(this)); + } + }, { + key: 'getCurrentTriggersPage', + value: function getCurrentTriggersPage() { + var pageSize = this.panel.pageSize || 10; + var startPos = this.pageIndex * pageSize; + var endPos = Math.min(startPos + pageSize, this.triggerList.length); + this.currentTriggersPage = this.triggerList.slice(startPos, endPos); + return this.currentTriggersPage; } }, { key: 'link', @@ -345,8 +351,7 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap var data; var panel = ctrl.panel; var pageCount = 0; - // var formaters = []; - data = ctrl.panel.triggerList; + data = ctrl.triggerList; function getTableHeight() { var panelHeight = ctrl.height; @@ -365,16 +370,17 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap var pageSize = ctrl.panel.pageSize || 10; var startPos = ctrl.pageIndex * pageSize; var endPos = Math.min(startPos + pageSize, ctrl.triggerList.length); - ctrl.currentPage = ctrl.triggerList.slice(startPos, endPos); - ctrl.render(); - // renderPanel(); + ctrl.currentTriggersPage = ctrl.triggerList.slice(startPos, endPos); + + scope.$apply(); + renderPanel(); } function appendPaginationControls(footerElem) { footerElem.empty(); - var pageSize = panel.pageSize || 5; - pageCount = Math.ceil(ctrl.panel.triggerList.length / pageSize); + var pageSize = ctrl.panel.pageSize || 5; + pageCount = Math.ceil(data.length / pageSize); if (pageCount === 1) { return; } @@ -396,17 +402,13 @@ System.register(['lodash', 'jquery', 'moment', '../datasource-zabbix/utils', 'ap function renderPanel() { var panelElem = elem.parents('.panel'); var rootElem = elem.find('.triggers-panel-scroll'); - // var tbodyElem = elem.find('tbody'); var footerElem = elem.find('.triggers-panel-footer'); elem.css({ 'font-size': panel.fontSize }); panelElem.addClass('triggers-panel-wrapper'); - - // appendTableRows(tbodyElem); appendPaginationControls(footerElem); rootElem.css({ 'max-height': panel.scroll ? getTableHeight() : '' }); - // ctrl.render(); } elem.on('click', '.triggers-panel-page-link', switchPage); diff --git a/dist/panel-triggers/module.js.map b/dist/panel-triggers/module.js.map index d2620d38f..8fa09cf6c 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","triggerStatusMap","defaultTimeFormat","TriggerPanelCtrl","$scope","$injector","$element","datasourceSrv","templateSrv","contextSrv","pageIndex","defaults","panel","cloneDeep","triggerList","currentPage","events","on","onInitEditMode","bind","onRender","refreshData","addEditorTab","otherPanelInFullscreenMode","error","loading","then","slice","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","refresh","scope","elem","attrs","ctrl","data","pageCount","getTableHeight","panelHeight","height","switchPage","e","el","currentTarget","parseInt","startPos","endPos","Math","min","render","appendPaginationControls","footerElem","empty","ceil","startPage","max","endPage","paginationList","i","activeClass","pageLinkElem","append","renderPanel","panelElem","parents","rootElem","css","fontSize","addClass","unbindDestroy","$on","off","renderData","renderingCompleted","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoWA,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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,CAAa,QAAb,CAAhB;AACA,kBAAIC,WAAWjC,KAAKlC,IAAL,CAAU,wBAAV,CAAf;AACA;AACA,kBAAIqD,aAAanB,KAAKlC,IAAL,CAAU,wBAAV,CAAjB;;AAEAkC,mBAAKkC,GAAL,CAAS,EAAC,aAAanG,MAAMoG,QAApB,EAAT;AACAJ,wBAAUK,QAAV,CAAmB,wBAAnB;;AAEA;AACAlB,uCAAyBC,UAAzB;;AAEAc,uBAASC,GAAT,CAAa,EAAC,cAAcnG,MAAMb,MAAN,GAAemF,gBAAf,GAAkC,EAAjD,EAAb;AACA;AACD;;AAEDL,iBAAK5D,EAAL,CAAQ,OAAR,EAAiB,2BAAjB,EAA8CoE,UAA9C;;AAEA,gBAAI6B,gBAAgBtC,MAAMuC,GAAN,CAAU,UAAV,EAAsB,YAAW;AACnDtC,mBAAKuC,GAAL,CAAS,OAAT,EAAkB,2BAAlB;AACAF;AACD,aAHmB,CAApB;;AAKAnC,iBAAK/D,MAAL,CAAYC,EAAZ,CAAe,QAAf,EAAyB,UAACoG,UAAD,EAAgB;AACvCrC,qBAAOqC,cAAcrC,IAArB;AACA,kBAAIA,IAAJ,EAAU;AACR2B;AACD;AACD5B,mBAAKuC,kBAAL;AACD,aAND;AAOD;;;;QAhS4BlJ,S;;AAmS/B+B,uBAAiBoH,WAAjB,GAA+B,4BAA/B;kCAeEpH,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 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};\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\n this.pageIndex = 0;\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.triggerList = [];\n this.currentPage = [];\n\n this.events.on('init-edit-mode', this.onInitEditMode.bind(this));\n this.events.on('render', this.onRender.bind(this));\n this.events.on('refresh', this.onRender.bind(this));\n\n this.refreshData();\n }\n\n /**\n * Override onInitMetricsPanelEditMode() method from MetricsPanelCtrl.\n * We don't need metric editor from Metrics Panel.\n */\n onInitEditMode() {\n this.addEditorTab('Options', triggerPanelEditor, 2);\n }\n\n onMetricsPanelRefresh() {\n // ignore fetching data if another panel is in fullscreen\n if (this.otherPanelInFullscreenMode()) { return; }\n\n this.refreshData();\n }\n\n onRender() {\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 // Notify panel that request is finished\n this.loading = false;\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 .then(() => {\n this.refresh();\n });\n });\n }\n\n link(scope, elem, attrs, ctrl) {\n var data;\n var panel = ctrl.panel;\n var pageCount = 0;\n // var formaters = [];\n data = ctrl.panel.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.currentPage = ctrl.triggerList.slice(startPos, endPos);\n ctrl.render();\n // renderPanel();\n }\n\n function appendPaginationControls(footerElem) {\n footerElem.empty();\n\n var pageSize = panel.pageSize || 5;\n pageCount = Math.ceil(ctrl.panel.triggerList.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 tbodyElem = elem.find('tbody');\n var footerElem = elem.find('.triggers-panel-footer');\n\n elem.css({'font-size': panel.fontSize});\n panelElem.addClass('triggers-panel-wrapper');\n\n // appendTableRows(tbodyElem);\n appendPaginationControls(footerElem);\n\n rootElem.css({'max-height': panel.scroll ? getTableHeight() : '' });\n // ctrl.render();\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","sortTriggersBy","text","value","showEvents","triggerSeverity","okEventColor","ackEventColor","scroll","pageSize","triggerStatusMap","defaultTimeFormat","TriggerPanelCtrl","$scope","$injector","$element","datasourceSrv","templateSrv","contextSrv","pageIndex","defaults","panel","cloneDeep","triggerList","currentTriggersPage","events","on","onInitEditMode","bind","onRefresh","addEditorTab","otherPanelInFullscreenMode","refreshData","error","loading","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","fontSize","addClass","unbindDestroy","$on","off","renderData","renderingCompleted","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuWA,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;;;;AApWMG,O;;AACAM,O;;AACAC,Y;;AACKT,W;;AACJU,e,kBAAAA,S;;AACAC,wB,WAAAA,kB;;;;;;;;;;;;;;;;;;;;;AAIJC,qB,GAAkB,CACpB,EAAEC,UAAU,CAAZ,EAAeC,UAAU,gBAAzB,EAA4CC,OAAO,SAAnD,EAA8DC,MAAM,IAApE,EADoB,EAEpB,EAAEH,UAAU,CAAZ,EAAeC,UAAU,aAAzB,EAA4CC,OAAO,SAAnD,EAA8DC,MAAM,IAApE,EAFoB,EAGpB,EAAEH,UAAU,CAAZ,EAAeC,UAAU,SAAzB,EAA4CC,OAAO,SAAnD,EAA8DC,MAAM,IAApE,EAHoB,EAIpB,EAAEH,UAAU,CAAZ,EAAeC,UAAU,SAA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C,MAAMmC,GAAN,CAAU,UAAV,EAAsB,YAAW;AACnDlC,mBAAKmC,GAAL,CAAS,OAAT,EAAkB,2BAAlB;AACAF;AACD,aAHmB,CAApB;;AAKA/B,iBAAKpE,MAAL,CAAYC,EAAZ,CAAe,QAAf,EAAyB,UAACqG,UAAD,EAAgB;AACvCjC,qBAAOiC,cAAcjC,IAArB;AACA,kBAAIA,IAAJ,EAAU;AACRW;AACD;AACDZ,mBAAKmC,kBAAL;AACD,aAND;AAOD;;;;QAnS4BnJ,S;;AAsS/B+B,uBAAiBqH,WAAjB,GAA+B,4BAA/B;kCAeErH,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 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};\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\n this.pageIndex = 0;\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.triggerList = [];\n this.currentTriggersPage = [];\n\n this.events.on('init-edit-mode', this.onInitEditMode.bind(this));\n this.events.on('refresh', this.onRefresh.bind(this));\n }\n\n /**\n * Override onInitMetricsPanelEditMode() method from MetricsPanelCtrl.\n * We don't need metric editor from Metrics Panel.\n */\n onInitEditMode() {\n this.addEditorTab('Options', triggerPanelEditor, 2);\n }\n\n onMetricsPanelRefresh() {\n // ignore fetching data if another panel is in fullscreen\n if (this.otherPanelInFullscreenMode()) { return; }\n\n this.refreshData();\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 diff --git a/src/panel-triggers/module.html b/src/panel-triggers/module.html index 23c3ce064..7b5fefa07 100644 --- a/src/panel-triggers/module.html +++ b/src/panel-triggers/module.html @@ -35,7 +35,7 @@ - +
    diff --git a/src/panel-triggers/module.js b/src/panel-triggers/module.js index dcc0476e2..46f55fd1d 100644 --- a/src/panel-triggers/module.js +++ b/src/panel-triggers/module.js @@ -80,13 +80,10 @@ class TriggerPanelCtrl extends PanelCtrl { _.defaults(this.panel, _.cloneDeep(panelDefaults)); this.triggerList = []; - this.currentPage = []; + this.currentTriggersPage = []; this.events.on('init-edit-mode', this.onInitEditMode.bind(this)); - this.events.on('render', this.onRender.bind(this)); - this.events.on('refresh', this.onRender.bind(this)); - - this.refreshData(); + this.events.on('refresh', this.onRefresh.bind(this)); } /** @@ -104,7 +101,7 @@ class TriggerPanelCtrl extends PanelCtrl { this.refreshData(); } - onRender() { + onRefresh() { // clear loading/error state delete this.error; this.loading = true; @@ -114,8 +111,12 @@ class TriggerPanelCtrl extends PanelCtrl { // Limit triggers number this.triggerList = triggerList.slice(0, this.panel.limit); + this.getCurrentTriggersPage(); + // Notify panel that request is finished this.loading = false; + + this.render(this.triggerList); }); } @@ -260,19 +261,24 @@ class TriggerPanelCtrl extends PanelCtrl { return this.datasourceSrv.get(this.panel.datasource) .then(datasource => { let zabbixAPI = datasource.zabbix.zabbixAPI; - return zabbixAPI.acknowledgeEvent(eventid, ack_message) - .then(() => { - this.refresh(); - }); - }); + return zabbixAPI.acknowledgeEvent(eventid, ack_message); + }) + .then(this.onRefresh.bind(this)); + } + + getCurrentTriggersPage() { + let pageSize = this.panel.pageSize || 10; + let startPos = this.pageIndex * pageSize; + let endPos = Math.min(startPos + pageSize, this.triggerList.length); + this.currentTriggersPage = this.triggerList.slice(startPos, endPos); + return this.currentTriggersPage; } link(scope, elem, attrs, ctrl) { var data; var panel = ctrl.panel; var pageCount = 0; - // var formaters = []; - data = ctrl.panel.triggerList; + data = ctrl.triggerList; function getTableHeight() { var panelHeight = ctrl.height; @@ -291,16 +297,17 @@ class TriggerPanelCtrl extends PanelCtrl { let pageSize = ctrl.panel.pageSize || 10; let startPos = ctrl.pageIndex * pageSize; let endPos = Math.min(startPos + pageSize, ctrl.triggerList.length); - ctrl.currentPage = ctrl.triggerList.slice(startPos, endPos); - ctrl.render(); - // renderPanel(); + ctrl.currentTriggersPage = ctrl.triggerList.slice(startPos, endPos); + + scope.$apply(); + renderPanel(); } function appendPaginationControls(footerElem) { footerElem.empty(); - var pageSize = panel.pageSize || 5; - pageCount = Math.ceil(ctrl.panel.triggerList.length / pageSize); + var pageSize = ctrl.panel.pageSize || 5; + pageCount = Math.ceil(data.length / pageSize); if (pageCount === 1) { return; } @@ -322,17 +329,13 @@ class TriggerPanelCtrl extends PanelCtrl { function renderPanel() { var panelElem = elem.parents('.panel'); var rootElem = elem.find('.triggers-panel-scroll'); - // var tbodyElem = elem.find('tbody'); var footerElem = elem.find('.triggers-panel-footer'); elem.css({'font-size': panel.fontSize}); panelElem.addClass('triggers-panel-wrapper'); - - // appendTableRows(tbodyElem); appendPaginationControls(footerElem); rootElem.css({'max-height': panel.scroll ? getTableHeight() : '' }); - // ctrl.render(); } elem.on('click', '.triggers-panel-page-link', switchPage);