alert.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.AlertStatus = {
  20. negative: 'corrupt',
  21. positive: 'ok'
  22. }
  23. /**
  24. * Defines structure for App.Alert class. Keys mentioned here are for JSON data
  25. * which comes back from NAGIOS server.
  26. */
  27. App.Alert = DS.Model.extend({
  28. alertId: DS.attr('string'),
  29. primaryKey: 'alertId',
  30. title: DS.attr('string'),//service_description in ajax response
  31. serviceType: DS.attr('string'),
  32. date: DS.attr('date'),
  33. status: DS.attr('string'),//current_state in ajax response
  34. message: DS.attr('string'),//plugin_output in ajax response
  35. hostName: DS.attr('string'),
  36. currentAttempt: DS.attr('string'),
  37. lastHardStateChange: DS.attr('number'),
  38. lastHardState: DS.attr('number'),
  39. lastTimeOk: DS.attr('number'),
  40. lastTimeWarning: DS.attr('number'),
  41. lastTimeUnknown: DS.attr('number'),
  42. lastTimeCritical: DS.attr('number'),
  43. isFlapping: DS.attr('number'),
  44. lastCheck: DS.attr('number'),
  45. /**
  46. * Used to show correct icon in UI
  47. */
  48. isOk: function () {
  49. return this.get('status') == "0";
  50. }.property('status'),
  51. /**
  52. * Used to show correct icon in UI
  53. */
  54. isWarning: function () {
  55. return this.get('status') == "1";
  56. }.property('status'),
  57. /**
  58. * Used to show correct icon in UI
  59. */
  60. isCritical: function() {
  61. return this.get('status') == '2';
  62. }.property('status'),
  63. /**
  64. * Used to show only required alerts at the service level
  65. */
  66. ignoredForServices: function() {
  67. return ['TaskTracker process down', 'RegionServer process down', 'DataNode process down', 'DataNode storage full', 'ZooKeeper Server process down'].contains(this.get('title'));
  68. }.property('title'),
  69. /**
  70. * Used to show only required alerts at the host level
  71. */
  72. ignoredForHosts: function() {
  73. return this.get('title').indexOf('Percent') != -1;
  74. }.property('title'),
  75. /**
  76. * Provides how long ago this alert happened.
  77. *
  78. * @type {String}
  79. */
  80. timeSinceAlert: function () {
  81. var d = this.get('date');
  82. if (d) {
  83. var prefix = this.t('services.alerts.OK.timePrefix');
  84. switch (this.get('status')) {
  85. case "1":
  86. prefix = this.t('services.alerts.WARN.timePrefix');
  87. break;
  88. case "2":
  89. prefix = this.t('services.alerts.CRIT.timePrefix');
  90. break;
  91. case "3":
  92. prefix = this.t('services.alerts.UNKNOWN.timePrefix');
  93. break;
  94. }
  95. var prevSuffix = $.timeago.settings.strings.suffixAgo;
  96. $.timeago.settings.strings.suffixAgo = '';
  97. var since = prefix + $.timeago(this.makeTimeAtleastMinuteAgo(d));
  98. $.timeago.settings.strings.suffixAgo = prevSuffix;
  99. return since;
  100. }
  101. return "";
  102. }.property('date', 'status'),
  103. makeTimeAtleastMinuteAgo: function(d){
  104. var diff = new Date().getTime() - d.getTime();
  105. if (diff < 60000) {
  106. diff = 60000 - diff;
  107. var newD = new Date(d.getTime() - diff );
  108. //console.log("Making time more than 1 minute. New time=",newD,", Old time=",d);
  109. return newD;
  110. }
  111. return d;
  112. },
  113. /**
  114. * Provides more details about when this alert happened.
  115. *
  116. * @type {String}
  117. */
  118. timeSinceAlertDetails: function () {
  119. var details = "";
  120. var date = this.get('date');
  121. if (date) {
  122. var dateString = date.toDateString();
  123. dateString = dateString.substr(dateString.indexOf(" ") + 1);
  124. dateString = "Occurred on " + dateString + ", " + date.toLocaleTimeString();
  125. details += dateString;
  126. }
  127. var lastCheck = this.get('lastCheck');
  128. if (lastCheck) {
  129. lastCheck = new Date(lastCheck * 1000);
  130. details = details + "<br>Last checked " + $.timeago(lastCheck);
  131. }
  132. return details;
  133. }.property('lastCheck', 'date'),
  134. /**
  135. * Used to show appropriate service label in UI
  136. */
  137. serviceName: function () {
  138. if (this.get('serviceType')) {
  139. var type = this.get('serviceType').toLowerCase();
  140. switch (type) {
  141. case 'mapreduce':
  142. return 'MapReduce';
  143. case 'hdfs':
  144. return 'HDFS';
  145. case 'hbase':
  146. return "HBase";
  147. case 'zookeeper':
  148. return "Zookeeper";
  149. case 'oozie':
  150. return "Oozie";
  151. case 'hive':
  152. return 'Hive';
  153. }
  154. }
  155. return null;
  156. }.property('serviceType'),
  157. /**
  158. * Used to provide appropriate service link in UI
  159. */
  160. serviceLink: function () {
  161. if (this.get('serviceType')) {
  162. var type = this.get('serviceType').toLowerCase();
  163. switch (type) {
  164. case 'mapreduce':
  165. return '#/main/services/MAPREDUCE/summary';
  166. case 'hdfs':
  167. return '#/main/services/HDFS/summary';
  168. case 'hbase':
  169. return '#/main/services/HBASE/summary';
  170. case 'zookeeper':
  171. return '#/main/services/ZOOKEEPER/summary';
  172. case 'oozie':
  173. return '#/main/services/OOZIE/summary';
  174. case 'hive':
  175. return '#/main/services/HIVE/summary';
  176. }
  177. }
  178. return null;
  179. }.property('serviceType')
  180. });
  181. App.Alert.FIXTURES = [
  182. ];