alert_definitions_controller.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.MainAlertDefinitionsController = Em.ArrayController.extend({
  20. name: 'mainAlertDefinitionsController',
  21. /**
  22. * Timestamp when <code>App.alertDefinitionsMapper</code> run last time
  23. * Current <code>content</code> is updated on when it changed
  24. * @type {number|null}
  25. */
  26. mapperTimestamp: null,
  27. /**
  28. * Define whether restore filter conditions from local db
  29. * @type {Boolean}
  30. */
  31. showFilterConditionsFirstLoad: false,
  32. /**
  33. * List of all <code>App.AlertDefinition</code>
  34. * Consists of:
  35. * <ul>
  36. * <li>App.PortAlertDefinition</li>
  37. * <li>App.MetricsAlertDefinition</li>
  38. * <li>App.WebAlertDefinition</li>
  39. * <li>App.AggregateAlertDefinition</li>
  40. * <li>App.ScriptAlertDefinition</li>
  41. * </ul>
  42. * @type {App.AlertDefinition[]}
  43. */
  44. content: App.AlertDefinition.find(),
  45. /**
  46. * Enable/disable alertDefinition confirmation popup
  47. * @param {object} event
  48. * @method toggleState
  49. * @return {App.ModalPopup}
  50. */
  51. toggleState: function (event) {
  52. var alertDefinition = event.context;
  53. var self = this;
  54. var bodyMessage = Em.Object.create({
  55. confirmMsg: alertDefinition.get('enabled') ? Em.I18n.t('alerts.table.state.enabled.confirm.msg') : Em.I18n.t('alerts.table.state.disabled.confirm.msg'),
  56. confirmButton: alertDefinition.get('enabled') ? Em.I18n.t('alerts.table.state.enabled.confirm.btn') : Em.I18n.t('alerts.table.state.disabled.confirm.btn')
  57. });
  58. return App.showConfirmationFeedBackPopup(function (query) {
  59. self.toggleDefinitionState(alertDefinition);
  60. }, bodyMessage);
  61. },
  62. /**
  63. * Enable/disable alertDefinition
  64. * @param {object} alertDefinition
  65. * @returns {$.ajax}
  66. * @method toggleDefinitionState
  67. */
  68. toggleDefinitionState: function (alertDefinition) {
  69. var newState = !alertDefinition.get('enabled');
  70. alertDefinition.set('enabled', newState);
  71. return App.ajax.send({
  72. name: 'alerts.update_alert_definition',
  73. sender: this,
  74. data: {
  75. id: alertDefinition.get('id'),
  76. data: {
  77. "AlertDefinition/enabled": newState
  78. }
  79. }
  80. });
  81. },
  82. /**
  83. * Calculate critical count for each service, to show up the label on services menu
  84. * @method getCriticalAlertsCountForService
  85. * @return {number}
  86. */
  87. getCriticalAlertsCountForService: function (service) {
  88. var alertsForService = this.get('content').filterProperty('service', service);
  89. return alertsForService.filterProperty('isCritical').get('length');
  90. },
  91. /**
  92. * Calculate critical/warning count for each service, to show up the label on services menu
  93. * @method getCriticalOrWarningAlertsCountForService
  94. * @return {number}
  95. */
  96. getCriticalOrWarningAlertsCountForService: function (service) {
  97. var alertsForService = this.get('content').filterProperty('service', service);
  98. return alertsForService.filterProperty('isCriticalOrWarning').get('length');
  99. },
  100. /**
  101. * ========================== alerts popup dialog =========================
  102. */
  103. /**
  104. * Alerts number to show up on top-nav bar: number of critical/warning alerts
  105. * @type {number}
  106. */
  107. allAlertsCount: function () {
  108. return this.get('unhealthyAlertInstances.length');
  109. }.property('unhealthyAlertInstances.length'),
  110. unhealthyAlertInstances: function () {
  111. return App.AlertInstance.find().toArray().filterProperty('state', 'CRITICAL').concat(
  112. App.AlertInstance.find().toArray().filterProperty('state', 'WARNING')
  113. );
  114. }.property('mapperTimestamp'),
  115. /**
  116. * if critical alerts exist, if true, the alert badge should be red.
  117. */
  118. isCriticalAlerts: function () {
  119. return this.get('unhealthyAlertInstances').someProperty('state', 'CRITICAL');
  120. }.property('unhealthyAlertInstances.@each.state'),
  121. /**
  122. * Onclick handler for alerts number located right to bg ops number (see application.hbs)
  123. * @method showPopup
  124. * @return {App.ModalPopup}
  125. */
  126. showPopup: function () {
  127. var self = this;
  128. return App.ModalPopup.show({
  129. header: function () {
  130. return Em.I18n.t('alerts.fastAccess.popup.header').format(this.get('definitionsController.allAlertsCount'));
  131. }.property('definitionsController.allAlertsCount'),
  132. definitionsController: this,
  133. classNames: ['sixty-percent-width-modal', 'alerts-popup'],
  134. secondary: Em.I18n.t('alerts.fastAccess.popup.body.showmore'),
  135. isHideBodyScroll: true,
  136. onSecondary: function () {
  137. this.hide();
  138. App.router.transitionTo('main.alerts.index');
  139. },
  140. bodyClass: Em.View.extend({
  141. templateName: require('templates/common/modal_popups/alerts_popup'),
  142. controller: self,
  143. contents: function () {
  144. return this.get('controller.unhealthyAlertInstances');
  145. }.property('controller.unhealthyAlertInstances.length', 'controller.unhealthyAlertInstances.@each.state'),
  146. isLoaded: function () {
  147. return !!this.get('controller.unhealthyAlertInstances');
  148. }.property('controller.unhealthyAlertInstances'),
  149. isAlertEmptyList: function () {
  150. return !this.get('contents.length');
  151. }.property('contents.length'),
  152. /**
  153. * Router transition to alert definition details page
  154. * @param event
  155. */
  156. gotoAlertDetails: function (event) {
  157. if (event && event.context) {
  158. this.get('parentView').hide();
  159. var definition = this.get('controller.content').findProperty('id', event.context.get('definitionId'));
  160. App.router.transitionTo('main.alerts.alertDetails', definition);
  161. }
  162. },
  163. /**
  164. * Router transition to service summary page
  165. * @param event
  166. */
  167. gotoService: function (event) {
  168. if (event && event.context) {
  169. this.get('parentView').hide();
  170. App.router.transitionTo('main.services.service', event.context);
  171. }
  172. },
  173. /**
  174. * Router transition to host level alerts page
  175. * @param event
  176. */
  177. goToHostAlerts: function (event) {
  178. if (event && event.context) {
  179. this.get('parentView').hide();
  180. App.router.transitionTo('main.hosts.hostDetails.alerts', event.context);
  181. }
  182. },
  183. didInsertElement: function () {
  184. Em.run.next(this, function () {
  185. App.tooltip($(".timeago"));
  186. });
  187. }
  188. })
  189. });
  190. }
  191. });