alert.js 5.2 KB

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