alert.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 appropriate date in UI
  53. */
  54. dateDisplay: function () {
  55. var d = this.get('date');
  56. if (d) {
  57. var dateString = d.toDateString() + ". " + d.toLocaleTimeString();
  58. dateString = dateString.substr(dateString.indexOf(" ") + 1);
  59. return dateString;
  60. }
  61. return "";
  62. }.property('date'),
  63. /**
  64. * Used to show appropriate service label in UI
  65. */
  66. serviceName: function () {
  67. if (this.get('serviceType')) {
  68. var type = this.get('serviceType').toLowerCase();
  69. switch (type) {
  70. case 'mapreduce':
  71. return 'MapReduce';
  72. case 'hdfs':
  73. return 'HDFS';
  74. case 'hbase':
  75. return "HBase";
  76. case 'zookeeper':
  77. return "Zookeeper";
  78. case 'oozie':
  79. return "Oozie";
  80. case 'hive':
  81. return 'Hive';
  82. }
  83. }
  84. return 'unknown';
  85. }.property('serviceType'),
  86. /**
  87. * Used to provide appropriate service link in UI
  88. */
  89. serviceLink: function () {
  90. if (this.get('serviceType')) {
  91. var type = this.get('serviceType').toLowerCase();
  92. switch (type) {
  93. case 'mapreduce':
  94. return '#/main/services/2';
  95. case 'hdfs':
  96. return '#/main/services/1';
  97. case 'hbase':
  98. return '#/main/services/3';
  99. case 'zookeeper':
  100. return '#/main/services/4';
  101. case 'oozie':
  102. return '#/main/services/5';
  103. case 'hive':
  104. return '#/main/services/6';
  105. }
  106. }
  107. return '';
  108. }.property('serviceType')
  109. });
  110. App.Alert.FIXTURES = [
  111. ];