alert_definitions_controller.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. * List of all <code>App.AlertDefinition</code>
  29. * Consists of:
  30. * <ul>
  31. * <li>App.PortAlertDefinition</li>
  32. * <li>App.MetricsAlertDefinition</li>
  33. * <li>App.WebAlertDefinition</li>
  34. * <li>App.AggregateAlertDefinition</li>
  35. * <li>App.ScriptAlertDefinition</li>
  36. * </ul>
  37. * @type {App.AlertDefinition[]}
  38. */
  39. content: function() {
  40. return App.AlertDefinition.getAllDefinitions();
  41. }.property('mapperTimestamp'),
  42. /**
  43. * Enable/disable alertDefinition confirmation popup
  44. * @param {object} event
  45. * @method toggleState
  46. * @return {App.ModalPopup}
  47. */
  48. toggleState: function(event) {
  49. var alertDefinition = event.context;
  50. var self = this;
  51. var bodyMessage = Em.Object.create({
  52. confirmMsg: alertDefinition.get('enabled') ? Em.I18n.t('alerts.table.state.enabled.confirm.msg') : Em.I18n.t('alerts.table.state.disabled.confirm.msg'),
  53. confirmButton: alertDefinition.get('enabled') ? Em.I18n.t('alerts.table.state.enabled.confirm.btn') : Em.I18n.t('alerts.table.state.disabled.confirm.btn')
  54. });
  55. return App.showConfirmationFeedBackPopup(function (query) {
  56. self.toggleDefinitionState (alertDefinition);
  57. }, bodyMessage);
  58. },
  59. /**
  60. * Enable/disable alertDefinition
  61. * @param {object} alertDefinition
  62. * @returns {$.ajax}
  63. * @method toggleDefinitionState
  64. */
  65. toggleDefinitionState: function(alertDefinition) {
  66. return App.ajax.send({
  67. name: 'alerts.update_alert_definition',
  68. sender: this,
  69. data: {
  70. id: alertDefinition.get('id'),
  71. data: {
  72. "AlertDefinition/enabled": !alertDefinition.get('enabled')
  73. }
  74. }
  75. });
  76. },
  77. /**
  78. * Calculate critical/warning count for each service, to show up the label on services menu
  79. * @method getCriticalAlertsCountForService
  80. * @return {number}
  81. */
  82. getCriticalAlertsCountForService: function(service) {
  83. var alertsForService = this.get('content').filterProperty('service', service);
  84. return alertsForService.filterProperty('isCriticalOrWarning').get('length');
  85. },
  86. /**
  87. * ========================== alerts popup dialog =========================
  88. */
  89. /**
  90. * Alerts number to show up on top-nav bar: number of critical/warning alerts
  91. * @type {number}
  92. */
  93. allAlertsCount: function () {
  94. return this.get('unhealthyAlertInstances').get('length');
  95. }.property('unhealthyAlertInstances.length'),
  96. unhealthyAlertInstances: function() {
  97. return App.AlertInstance.find().toArray().filterProperty('state', 'CRITICAL').concat(
  98. App.AlertInstance.find().toArray().filterProperty('state', 'WARNING')
  99. );
  100. }.property('mapperTimestamp'),
  101. /**
  102. * if critical alerts exist, if true, the alert badge should be red.
  103. */
  104. isCriticalAlerts: function () {
  105. return this.get('unhealthyAlertInstances').someProperty('state', 'CRITICAL');
  106. }.property('unhealthyAlertInstances.@each.state'),
  107. /**
  108. * Onclick handler for alerts number located right to bg ops number (see application.hbs)
  109. * @method showPopup
  110. * @return {App.ModalPopup}
  111. */
  112. showPopup: function() {
  113. var self = this;
  114. return App.ModalPopup.show({
  115. header: Em.I18n.t('alerts.fastAccess.popup.header').format(self.get('allAlertsCount')),
  116. classNames: ['sixty-percent-width-modal', 'alerts-popup'],
  117. secondary: null,
  118. isHideBodyScroll: true,
  119. bodyClass: Em.View.extend({
  120. templateName: require('templates/common/alerts_popup'),
  121. controller: self,
  122. contents: function () {
  123. return this.get('controller.unhealthyAlertInstances');
  124. }.property('controller.unhealthyAlertInstances.length', 'controller.unhealthyAlertInstances.@each.state'),
  125. isLoaded: function () {
  126. return !!this.get('controller.unhealthyAlertInstances');
  127. }.property('controller.unhealthyAlertInstances'),
  128. isAlertEmptyList: function () {
  129. return !this.get('contents.length');
  130. }.property('contents.length'),
  131. /**
  132. * Router transition to alert definition details page
  133. * @param event
  134. */
  135. gotoAlertDetails: function (event) {
  136. if (event && event.context) {
  137. this.get('parentView').hide();
  138. var definition = this.get('controller.content').findProperty('id', event.context.get('definitionId'));
  139. App.router.transitionTo('main.alerts.alertDetails', definition);
  140. }
  141. },
  142. /**
  143. * Router transition to service summary page
  144. * @param event
  145. */
  146. gotoService: function (event) {
  147. if (event && event.context) {
  148. this.get('parentView').hide();
  149. App.router.transitionTo('main.services.service', event.context);
  150. }
  151. },
  152. /**
  153. * Router transition to host level alerts page
  154. * @param event
  155. */
  156. goToHostAlerts: function (event) {
  157. if (event && event.context) {
  158. this.get('parentView').hide();
  159. App.router.transitionTo('main.hosts.hostDetails.alerts', event.context);
  160. }
  161. },
  162. didInsertElement: function () {
  163. Em.run.next(this, function () {
  164. App.tooltip($(".timeago"));
  165. });
  166. },
  167. /**
  168. * Router transition to alert summary page
  169. */
  170. showMore: function () {
  171. this.get('parentView').hide();
  172. App.router.transitionTo('main.alerts.index');
  173. }
  174. })
  175. })
  176. }
  177. });