alert_definition_summary_mapper_test.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('mappers/alert_definition_summary_mapper');
  19. describe('App.alertDefinitionSummaryMapper', function () {
  20. describe('#map', function () {
  21. var testModels = [
  22. App.AlertDefinition.createRecord({id: 1, enabled: true, type: 'PORT'}),
  23. App.AlertDefinition.createRecord({id: 2, enabled: true, type: 'METRICS'}),
  24. App.AlertDefinition.createRecord({id: 3, enabled: true, type: 'WEB'}),
  25. App.AlertDefinition.createRecord({id: 4, enabled: true, type: 'AGGREGATE'}),
  26. App.AlertDefinition.createRecord({id: 5, enabled: true, type: 'SCRIPT'}),
  27. App.AlertDefinition.createRecord({id: 6, enabled: false, type: 'SCRIPT', summary: {OK: 1}})
  28. ],
  29. dataToMap = {
  30. alerts_summary_grouped: [
  31. {
  32. definition_id: 1,
  33. summary: {
  34. OK: {
  35. count: 1,
  36. original_timestamp: 1,
  37. maintenance_count: 0,
  38. latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  39. },
  40. WARNING: {
  41. count: 1,
  42. original_timestamp: 2,
  43. maintenance_count: 0,
  44. latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  45. },
  46. CRITICAL: {count: 0, original_timestamp: 0, maintenance_count: 1},
  47. UNKNOWN: {count: 0, original_timestamp: 0, maintenance_count: 0}
  48. }
  49. },
  50. {
  51. definition_id: 2,
  52. summary: {
  53. OK: {
  54. count: 1,
  55. original_timestamp: 1,
  56. maintenance_count: 0,
  57. latest_text: "HTTP 200 response in 0.000 seconds"
  58. },
  59. WARNING: {
  60. count: 5,
  61. original_timestamp: 2,
  62. maintenance_count: 0,
  63. latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  64. },
  65. CRITICAL: {count: 1, original_timestamp: 1, maintenance_count: 0},
  66. UNKNOWN: {count: 1, original_timestamp: 3, maintenance_count: 0}
  67. }
  68. },
  69. {
  70. definition_id: 3,
  71. summary: {
  72. OK: {
  73. count: 1,
  74. original_timestamp: 1,
  75. maintenance_count: 0,
  76. latest_text: "HTTP 200 response in 0.000 seconds"
  77. },
  78. WARNING: {count: 2, original_timestamp: 2, maintenance_count: 2},
  79. CRITICAL: {
  80. count: 3,
  81. original_timestamp: 4,
  82. maintenance_count: 0,
  83. latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  84. },
  85. UNKNOWN: {count: 4, original_timestamp: 3, maintenance_count: 0}
  86. }
  87. },
  88. {
  89. definition_id: 4,
  90. summary: {
  91. OK: {
  92. count: 4,
  93. original_timestamp: 1,
  94. maintenance_count: 0,
  95. latest_text: "HTTP 200 response in 0.000 seconds"
  96. },
  97. WARNING: {count: 3, original_timestamp: 2, maintenance_count: 0},
  98. CRITICAL: {count: 2, original_timestamp: 1, maintenance_count: 0},
  99. UNKNOWN: {
  100. count: 1,
  101. original_timestamp: 2,
  102. maintenance_count: 0,
  103. latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  104. }
  105. }
  106. },
  107. {
  108. definition_id: 5,
  109. summary: {
  110. OK: {
  111. count: 1,
  112. original_timestamp: 1,
  113. maintenance_count: 0,
  114. latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  115. },
  116. WARNING: {count: 1, original_timestamp: 2, maintenance_count: 0},
  117. CRITICAL: {count: 1, original_timestamp: 3, maintenance_count: 0},
  118. UNKNOWN: {count: 1, original_timestamp: 4, maintenance_count: 0}
  119. }
  120. }
  121. ]
  122. };
  123. beforeEach(function () {
  124. sinon.stub(App.AlertDefinition, 'find').returns(testModels);
  125. App.alertDefinitionSummaryMapper.map(dataToMap);
  126. });
  127. afterEach(function () {
  128. App.AlertDefinition.find.restore();
  129. });
  130. it('should map summary info for 1st alert', function () {
  131. expect(App.AlertDefinition.find().findProperty('id', 1).get('lastTriggered')).to.equal(2);
  132. expect(App.AlertDefinition.find().findProperty('id', 1).get('summary')).to.eql({
  133. OK: {
  134. count: 1,
  135. maintenanceCount: 0,
  136. latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  137. },
  138. WARNING: {
  139. count: 1,
  140. maintenanceCount: 0,
  141. latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  142. },
  143. CRITICAL: {count: 0, maintenanceCount: 1},
  144. UNKNOWN: {count: 0, maintenanceCount: 0}
  145. });
  146. });
  147. it('should map summary info for 2nd alert', function () {
  148. expect(App.AlertDefinition.find().findProperty('id', 2).get('lastTriggered')).to.equal(3);
  149. expect(App.AlertDefinition.find().findProperty('id', 2).get('summary')).to.eql({
  150. OK: {
  151. count: 1,
  152. maintenanceCount: 0,
  153. latestText: "HTTP 200 response in 0.000 seconds"
  154. },
  155. WARNING: {
  156. count: 5,
  157. maintenanceCount: 0,
  158. latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  159. },
  160. CRITICAL: {count: 1, maintenanceCount: 0},
  161. UNKNOWN: {count: 1, maintenanceCount: 0}
  162. });
  163. });
  164. it('should map summary info for 3rd alert', function () {
  165. expect(App.AlertDefinition.find().findProperty('id', 3).get('lastTriggered')).to.equal(4);
  166. expect(App.AlertDefinition.find().findProperty('id', 3).get('summary')).to.eql({
  167. OK: {
  168. count: 1,
  169. maintenanceCount: 0,
  170. latestText: "HTTP 200 response in 0.000 seconds"
  171. },
  172. WARNING: {count: 2, maintenanceCount: 2},
  173. CRITICAL: {
  174. count: 3,
  175. maintenanceCount: 0,
  176. latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  177. },
  178. UNKNOWN: {count: 4, maintenanceCount: 0}
  179. });
  180. });
  181. it('should map summary info for 4th alert', function () {
  182. expect(App.AlertDefinition.find().findProperty('id', 4).get('lastTriggered')).to.equal(2);
  183. expect(App.AlertDefinition.find().findProperty('id', 4).get('summary')).to.eql({
  184. OK: {
  185. count: 4,
  186. maintenanceCount: 0,
  187. latestText: "HTTP 200 response in 0.000 seconds"
  188. },
  189. WARNING: {count: 3, maintenanceCount: 0},
  190. CRITICAL: {count: 2, maintenanceCount: 0},
  191. UNKNOWN: {
  192. count: 1,
  193. maintenanceCount: 0,
  194. latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  195. }
  196. });
  197. });
  198. it('should map summary info for 5th alert', function () {
  199. expect(App.AlertDefinition.find().findProperty('id', 5).get('lastTriggered')).to.equal(4);
  200. expect(App.AlertDefinition.find().findProperty('id', 5).get('summary')).to.eql({
  201. OK: {
  202. count: 1,
  203. maintenanceCount: 0,
  204. latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
  205. },
  206. WARNING: {count: 1, maintenanceCount: 0},
  207. CRITICAL: {count: 1, maintenanceCount: 0},
  208. UNKNOWN: {count: 1, maintenanceCount: 0}
  209. });
  210. });
  211. it('should clear summary for disabled definitions', function () {
  212. expect(App.AlertDefinition.find().findProperty('id', 6).get('summary')).to.eql({});
  213. });
  214. });
  215. });