123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
- var App = require('app');
- require('mappers/alert_definition_summary_mapper');
- describe('App.alertDefinitionSummaryMapper', function () {
- describe('#map', function () {
- var testModels = [
- App.AlertDefinition.createRecord({id: 1, enabled: true, type: 'PORT'}),
- App.AlertDefinition.createRecord({id: 2, enabled: true, type: 'METRICS'}),
- App.AlertDefinition.createRecord({id: 3, enabled: true, type: 'WEB'}),
- App.AlertDefinition.createRecord({id: 4, enabled: true, type: 'AGGREGATE'}),
- App.AlertDefinition.createRecord({id: 5, enabled: true, type: 'SCRIPT'}),
- App.AlertDefinition.createRecord({id: 6, enabled: false, type: 'SCRIPT', summary: {OK: 1}})
- ],
- dataToMap = {
- alerts_summary_grouped: [
- {
- definition_id: 1,
- summary: {
- OK: {
- count: 1,
- original_timestamp: 1,
- maintenance_count: 0,
- latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- WARNING: {
- count: 1,
- original_timestamp: 2,
- maintenance_count: 0,
- latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- CRITICAL: {count: 0, original_timestamp: 0, maintenance_count: 1},
- UNKNOWN: {count: 0, original_timestamp: 0, maintenance_count: 0}
- }
- },
- {
- definition_id: 2,
- summary: {
- OK: {
- count: 1,
- original_timestamp: 1,
- maintenance_count: 0,
- latest_text: "HTTP 200 response in 0.000 seconds"
- },
- WARNING: {
- count: 5,
- original_timestamp: 2,
- maintenance_count: 0,
- latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- CRITICAL: {count: 1, original_timestamp: 1, maintenance_count: 0},
- UNKNOWN: {count: 1, original_timestamp: 3, maintenance_count: 0}
- }
- },
- {
- definition_id: 3,
- summary: {
- OK: {
- count: 1,
- original_timestamp: 1,
- maintenance_count: 0,
- latest_text: "HTTP 200 response in 0.000 seconds"
- },
- WARNING: {count: 2, original_timestamp: 2, maintenance_count: 2},
- CRITICAL: {
- count: 3,
- original_timestamp: 4,
- maintenance_count: 0,
- latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- UNKNOWN: {count: 4, original_timestamp: 3, maintenance_count: 0}
- }
- },
- {
- definition_id: 4,
- summary: {
- OK: {
- count: 4,
- original_timestamp: 1,
- maintenance_count: 0,
- latest_text: "HTTP 200 response in 0.000 seconds"
- },
- WARNING: {count: 3, original_timestamp: 2, maintenance_count: 0},
- CRITICAL: {count: 2, original_timestamp: 1, maintenance_count: 0},
- UNKNOWN: {
- count: 1,
- original_timestamp: 2,
- maintenance_count: 0,
- latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- }
- }
- },
- {
- definition_id: 5,
- summary: {
- OK: {
- count: 1,
- original_timestamp: 1,
- maintenance_count: 0,
- latest_text: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- WARNING: {count: 1, original_timestamp: 2, maintenance_count: 0},
- CRITICAL: {count: 1, original_timestamp: 3, maintenance_count: 0},
- UNKNOWN: {count: 1, original_timestamp: 4, maintenance_count: 0}
- }
- }
- ]
- };
- beforeEach(function () {
- sinon.stub(App.AlertDefinition, 'find').returns(testModels);
- App.alertDefinitionSummaryMapper.map(dataToMap);
- });
- afterEach(function () {
- App.AlertDefinition.find.restore();
- });
- it('should map summary info for 1st alert', function () {
- expect(App.AlertDefinition.find().findProperty('id', 1).get('lastTriggered')).to.equal(2);
- expect(App.AlertDefinition.find().findProperty('id', 1).get('summary')).to.eql({
- OK: {
- count: 1,
- maintenanceCount: 0,
- latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- WARNING: {
- count: 1,
- maintenanceCount: 0,
- latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- CRITICAL: {count: 0, maintenanceCount: 1},
- UNKNOWN: {count: 0, maintenanceCount: 0}
- });
- });
- it('should map summary info for 2nd alert', function () {
- expect(App.AlertDefinition.find().findProperty('id', 2).get('lastTriggered')).to.equal(3);
- expect(App.AlertDefinition.find().findProperty('id', 2).get('summary')).to.eql({
- OK: {
- count: 1,
- maintenanceCount: 0,
- latestText: "HTTP 200 response in 0.000 seconds"
- },
- WARNING: {
- count: 5,
- maintenanceCount: 0,
- latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- CRITICAL: {count: 1, maintenanceCount: 0},
- UNKNOWN: {count: 1, maintenanceCount: 0}
- });
- });
- it('should map summary info for 3rd alert', function () {
- expect(App.AlertDefinition.find().findProperty('id', 3).get('lastTriggered')).to.equal(4);
- expect(App.AlertDefinition.find().findProperty('id', 3).get('summary')).to.eql({
- OK: {
- count: 1,
- maintenanceCount: 0,
- latestText: "HTTP 200 response in 0.000 seconds"
- },
- WARNING: {count: 2, maintenanceCount: 2},
- CRITICAL: {
- count: 3,
- maintenanceCount: 0,
- latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- UNKNOWN: {count: 4, maintenanceCount: 0}
- });
- });
- it('should map summary info for 4th alert', function () {
- expect(App.AlertDefinition.find().findProperty('id', 4).get('lastTriggered')).to.equal(2);
- expect(App.AlertDefinition.find().findProperty('id', 4).get('summary')).to.eql({
- OK: {
- count: 4,
- maintenanceCount: 0,
- latestText: "HTTP 200 response in 0.000 seconds"
- },
- WARNING: {count: 3, maintenanceCount: 0},
- CRITICAL: {count: 2, maintenanceCount: 0},
- UNKNOWN: {
- count: 1,
- maintenanceCount: 0,
- latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- }
- });
- });
- it('should map summary info for 5th alert', function () {
- expect(App.AlertDefinition.find().findProperty('id', 5).get('lastTriggered')).to.equal(4);
- expect(App.AlertDefinition.find().findProperty('id', 5).get('summary')).to.eql({
- OK: {
- count: 1,
- maintenanceCount: 0,
- latestText: "Connection failed: [Errno 111] Connection refused to c6407.ambari.apache.org:60000"
- },
- WARNING: {count: 1, maintenanceCount: 0},
- CRITICAL: {count: 1, maintenanceCount: 0},
- UNKNOWN: {count: 1, maintenanceCount: 0}
- });
- });
- it('should clear summary for disabled definitions', function () {
- expect(App.AlertDefinition.find().findProperty('id', 6).get('summary')).to.eql({});
- });
- });
- });
|