alert_instance.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.AlertInstance = DS.Model.extend({
  21. id: DS.attr('number'),
  22. label: DS.attr('string'),
  23. definitionName: DS.attr('string'),
  24. definitionId: DS.attr('number'),
  25. service: DS.belongsTo('App.Service'),
  26. serviceName: DS.attr('string'),
  27. componentName: DS.attr('string'),
  28. host: DS.belongsTo('App.Host'),
  29. scope: DS.attr('string'),
  30. originalTimestamp: DS.attr('number'),
  31. latestTimestamp: DS.attr('number'),
  32. maintenanceState: DS.attr('string'),
  33. instance: DS.attr('string'),
  34. state: DS.attr('string'),
  35. text: DS.attr('string'),
  36. notification: DS.hasMany('App.AlertNotification'),
  37. /**
  38. * Status icon markup
  39. * @type {string}
  40. */
  41. status: function () {
  42. var state = this.get('state');
  43. var shortState = this.get('shortState')[state];
  44. return '<span class="label alert-state-single-host alert-state-' + state + '">' + shortState + '</span>';
  45. }.property('state'),
  46. /**
  47. * For alerts we will have processes which are not typical
  48. * cluster services - like Ambari-Server. This method unifies
  49. * cluster services and other services into a common display-name.
  50. * @see App.AlertDefinition#serviceDisplayName()
  51. */
  52. serviceDisplayName: function () {
  53. var serviceName = this.get('service.displayName');
  54. if (!serviceName) {
  55. serviceName = this.get('serviceName');
  56. if (serviceName) {
  57. serviceName = serviceName.toCapital();
  58. }
  59. }
  60. return serviceName;
  61. }.property('serviceName', 'service.displayName'),
  62. /**
  63. * Formatted timestamp for latest instance triggering
  64. * @type {string}
  65. */
  66. lastCheckedFormatted: function () {
  67. return dateUtils.dateFormat(this.get('latestTimestamp'));
  68. }.property('latestTimestamp'),
  69. /**
  70. * Formatted timestamp for latest instance triggering
  71. * @type {string}
  72. */
  73. lastTriggeredFormatted: function () {
  74. return dateUtils.dateFormat(this.get('originalTimestamp'));
  75. }.property('originalTimestamp'),
  76. /**
  77. * Formatted timestamp with <code>$.timeago</code>
  78. * @type {string}
  79. */
  80. lastTriggeredAgoFormatted: function () {
  81. var lastTriggered = this.get('originalTimestamp');
  82. return lastTriggered ? $.timeago(new Date(lastTriggered)) : '';
  83. }.property('originalTimestamp'),
  84. lastTriggeredVerboseDisplay: function () {
  85. var originalTimestamp = this.get('originalTimestamp');
  86. var latestTimestamp = this.get('latestTimestamp');
  87. return Em.I18n.t('models.alert_instance.tiggered.verbose').format(
  88. dateUtils.dateFormat(originalTimestamp),
  89. dateUtils.dateFormat(latestTimestamp));
  90. }.property('originalTimestamp', 'latestTimestamp'),
  91. /**
  92. * Formatted timestamp with <code>$.timeago</code>
  93. * @type {string}
  94. */
  95. lastTriggeredForFormatted: function () {
  96. var lastTriggered = this.get('originalTimestamp');
  97. var previousSuffixAgo = $.timeago.settings.strings.suffixAgo;
  98. var previousPrefixAgo = $.timeago.settings.strings.prefixAgo;
  99. $.timeago.settings.strings.suffixAgo = null;
  100. $.timeago.settings.strings.prefixAgo = 'for';
  101. var triggeredFor = lastTriggered ? $.timeago(new Date(lastTriggered)) : '';
  102. $.timeago.settings.strings.suffixAgo = previousSuffixAgo;
  103. $.timeago.settings.strings.prefixAgo = previousPrefixAgo;
  104. return triggeredFor;
  105. }.property('originalTimestamp'),
  106. /**
  107. * Formatted lastChecked and lastTriggered timestamp
  108. * @returns {string}
  109. */
  110. statusChangedAndLastCheckedFormatted: function () {
  111. var lastCheckedFormatted = this.get('lastCheckedFormatted');
  112. var lastTriggeredFormatted = this.get('lastTriggeredFormatted');
  113. return Em.I18n.t('models.alert_definition.triggered.checked').format(lastCheckedFormatted, lastTriggeredFormatted);
  114. }.property('lastCheckedFormatted', 'lastTriggeredFormatted'),
  115. /**
  116. * List of css-classes for alert instance status
  117. * @type {object}
  118. */
  119. typeIcons: {
  120. 'DISABLED': 'icon-off'
  121. },
  122. /**
  123. * Define if definition serviceName is Ambari
  124. * Used in some logic in templates to distinguish definitions with Ambari serviceName
  125. * @returns {boolean}
  126. */
  127. isAmbariServiceName: function () {
  128. return this.get('serviceName') === 'AMBARI';
  129. }.property('serviceName'),
  130. shortState: {
  131. 'CRITICAL': 'CRIT',
  132. 'WARNING': 'WARN',
  133. 'OK': 'OK',
  134. 'UNKNOWN': 'UNKWN',
  135. 'PENDING': 'NONE'
  136. }
  137. });
  138. App.AlertInstance.FIXTURES = [];