alert_definition.js 5.9 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. var dateUtils = require('utils/date');
  20. App.AlertDefinition = DS.Model.extend({
  21. name: DS.attr('string'),
  22. label: DS.attr('string'),
  23. service: DS.belongsTo('App.Service'),
  24. componentName: DS.attr('string'),
  25. enabled: DS.attr('boolean'),
  26. scope: DS.attr('string'),
  27. interval: DS.attr('number'),
  28. type: DS.attr('string'),
  29. groups: DS.hasMany('App.AlertGroup'),
  30. reporting: DS.hasMany('App.AlertReportDefinition'),
  31. lastTriggered: DS.attr('number'),
  32. /**
  33. * Raw data from AlertDefinition/source
  34. * used to format request content for updating alert definition
  35. * @type {Object}
  36. */
  37. rawSourceData: {},
  38. /**
  39. * Counts of alert grouped by their status
  40. * Format:
  41. * <code>
  42. * {
  43. * "CRITICAL": 1,
  44. * "OK": 1,
  45. * "UNKNOWN": 0,
  46. * "WARN": 0
  47. * }
  48. * </code>
  49. * @type {object}
  50. */
  51. summary: {},
  52. /**
  53. * Formatted timestamp for latest alert triggering for current alertDefinition
  54. * @type {string}
  55. */
  56. lastTriggeredFormatted: function () {
  57. return dateUtils.dateFormat(this.get('lastTriggered'));
  58. }.property('lastTriggered'),
  59. /**
  60. * Formatted timestamp with <code>$.timeago</code>
  61. * @type {string}
  62. */
  63. lastTriggeredAgoFormatted: function () {
  64. var lastTriggered = this.get('lastTriggered');
  65. return lastTriggered ? $.timeago(new Date(lastTriggered)): '';
  66. }.property('lastTriggered'),
  67. /**
  68. * Status generates from child-alerts
  69. * Format: 1 OK / 2 WARN / 1 CRIT / 1 UNKNOWN
  70. * If some there are no alerts with some state, this state isn't shown
  71. * Order is equal to example
  72. * @type {string}
  73. */
  74. status: function () {
  75. var typeIcons = this.get('typeIcons'),
  76. order = this.get('order'),
  77. summary = this.get('summary');
  78. return order.map(function (state) {
  79. if (summary[state]) {
  80. return summary[state] + ' <span class="' + typeIcons[state] + ' alert-state-' + state + '"></span>';
  81. }
  82. return null;
  83. }).compact().join(' / ');
  84. }.property('summary'),
  85. /**
  86. * if this definition is in state: CRIT / WARNING, if true, will show up in alerts fast access popup
  87. * @type {boolean}
  88. */
  89. isCriticalOrWarning: function () {
  90. return this.get('isCritical') || this.get('isWarning');
  91. }.property('isCritical', 'isWarning'),
  92. /**
  93. * if this definition is in state: CRIT
  94. * @type {boolean}
  95. */
  96. isCritical: function () {
  97. var summary = this.get('summary');
  98. var state = 'CRITICAL';
  99. return !!summary[state];
  100. }.property('summary'),
  101. /**
  102. * if this definition is in state: WARNING
  103. * @type {boolean}
  104. */
  105. isWarning: function () {
  106. var summary = this.get('summary');
  107. var state = 'WARNING';
  108. return !!summary[state];
  109. }.property('summary'),
  110. /**
  111. * List of css-classes for alert types
  112. * @type {object}
  113. */
  114. typeIcons: {
  115. 'OK': 'icon-ok-sign',
  116. 'WARNING': 'icon-warning-sign',
  117. 'CRITICAL': 'icon-remove',
  118. 'DISABLED': 'icon-off',
  119. 'UNKNOWN': 'icon-question-sign'
  120. },
  121. /**
  122. * Sort on load definitions by this severity order
  123. */
  124. severityOrder: ['CRITICAL', 'WARNING', 'OK', 'UNKNOWN', 'PENDING'],
  125. order: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN'],
  126. // todo: in future be mapped from server response
  127. description: 'Description for the Alert Definition.',
  128. // todo: in future be mapped from server response
  129. thresholds: '5-10'
  130. });
  131. App.AlertDefinition.reopenClass({
  132. getAllDefinitions: function () {
  133. return Array.prototype.concat.call(
  134. Array.prototype, App.PortAlertDefinition.find().toArray(),
  135. App.MetricsAlertDefinition.find().toArray(),
  136. App.WebAlertDefinition.find().toArray(),
  137. App.AggregateAlertDefinition.find().toArray(),
  138. App.ScriptAlertDefinition.find().toArray()
  139. )
  140. }
  141. });
  142. App.AlertReportDefinition = DS.Model.extend({
  143. type: DS.attr('string'),
  144. text: DS.attr('string'),
  145. value: DS.attr('number')
  146. });
  147. App.AlertMetricsSourceDefinition = DS.Model.extend({
  148. propertyList: [],
  149. value: DS.attr('string')
  150. });
  151. App.AlertMetricsUriDefinition = DS.Model.extend({
  152. http: DS.attr('string'),
  153. https: DS.attr('string'),
  154. httpsProperty: DS.attr('string'),
  155. httpsPropertyValue: DS.attr('string')
  156. });
  157. App.PortAlertDefinition = App.AlertDefinition.extend({
  158. defaultPort: DS.attr('number'),
  159. uri: DS.attr('string')
  160. });
  161. App.MetricsAlertDefinition = App.AlertDefinition.extend({
  162. jmx: DS.belongsTo('App.AlertMetricsSourceDefinition'),
  163. ganglia: DS.belongsTo('App.AlertMetricsSourceDefinition'),
  164. uri: DS.belongsTo('App.AlertMetricsUriDefinition')
  165. });
  166. App.WebAlertDefinition = App.AlertDefinition.extend({
  167. uri: DS.belongsTo('App.AlertMetricsUriDefinition')
  168. });
  169. App.AggregateAlertDefinition = App.AlertDefinition.extend({
  170. alertName: DS.attr('string')
  171. });
  172. App.ScriptAlertDefinition = App.AlertDefinition.extend({
  173. location: DS.attr('string')
  174. });
  175. App.AlertDefinition.FIXTURES = [];
  176. App.AlertReportDefinition.FIXTURES = [];
  177. App.AlertMetricsSourceDefinition.FIXTURES = [];
  178. App.PortAlertDefinition.FIXTURES = [];
  179. App.AlertMetricsUriDefinition.FIXTURES = [];
  180. App.MetricsAlertDefinition.FIXTURES = [];
  181. App.WebAlertDefinition.FIXTURES = [];
  182. App.AggregateAlertDefinition.FIXTURES = [];
  183. App.ScriptAlertDefinition.FIXTURES = [];