private async Task <IList <Alarm> > GetAlarms(IList <AlarmDefinition> alarms,
                                                      ResourceThresholds <TAlarmConfig> awsResource,
                                                      TAlarmConfig configuration,
                                                      string groupSuffix)
        {
            var result = new List <Alarm>();

            var entity = await _tableSource.GetResourceAsync(awsResource.Name);

            if (entity == null)
            {
                throw new Exception($"Entity {awsResource.Name} not found");
            }

            // expand dynamic thresholds
            foreach (var alarm in alarms)
            {
                alarm.Threshold = await ExpandThreshold(entity.Resource, configuration, alarm.Threshold);

                var dimensions = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames);

                var model = new Alarm
                {
                    AlarmName       = GetAlarmName(entity, alarm.Name, groupSuffix),
                    Resource        = entity,
                    Dimensions      = dimensions,
                    AlarmDefinition = alarm
                };
                result.Add(model);
            }

            return(result);
        }
Beispiel #2
0
        private async Task <IList <Alarm> > CreateAlarmsForResource(
            IList <AlarmDefinition> defaults,
            ResourceThresholds <TAlarmConfig> resource,
            AwsServiceAlarms <TAlarmConfig> service,
            string groupSuffix)
        {
            var entity = await _tableSource.GetResourceAsync(resource.Name);

            // apply thresholds from resource or alerting group
            var expanded = await _builder.CopyAndUpdateDefaultAlarmsForResource(entity, defaults, service, resource);

            var result = new List <Alarm>();

            if (entity == null)
            {
                throw new Exception($"Entity {resource.Name} not found");
            }

            foreach (var alarm in expanded)
            {
                var dimensions = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames);

                var model = new Alarm
                {
                    AlarmName       = _builder.GetAlarmName(entity, alarm.Name, groupSuffix),
                    Resource        = entity,
                    Dimensions      = dimensions,
                    AlarmDefinition = alarm
                };
                result.Add(model);
            }

            return(result);
        }
Beispiel #3
0
        private async Task <IList <Alarm> > GetAlarms(IList <AlarmDefinition> alarms,
                                                      ResourceThresholds awsResource,
                                                      ServiceAlertingGroup group)
        {
            var result = new List <Alarm>();

            var entity = await _tableSource.GetResourceAsync(awsResource.Name);

            if (entity == null)
            {
                throw new Exception($"Entity {awsResource.Name} not found");
            }

            // expand dynamic thresholds
            foreach (var alarm in alarms)
            {
                alarm.Threshold = ExpandThreshold(entity.Resource, alarm.Threshold);
                var dimensions = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames);

                var model = new Alarm
                {
                    AlarmName       = GetAlarmName(entity, alarm.Name, group.AlarmNameSuffix),
                    Resource        = entity,
                    AlarmDefinition = alarm,
                    AlertingGroup   = group,
                    Dimensions      = dimensions
                };
                result.Add(model);
            }

            return(result);
        }
        private async Task <List <Alarm> > BuildAlarmsForQueue(
            IList <AlarmDefinition> defaults,
            ResourceThresholds <SqsResourceConfig> resource,
            PopulatedServiceAlarms <SqsResourceConfig, QueueDataV2> service,
            AlertingGroupParameters groupParameters,
            QueueDataV2 queue)
        {
            var  mergedConfig       = service.Options.OverrideWith(resource.Options);
            bool includeErrorQueues = mergedConfig.IncludeErrorQueues ?? true;

            var result = new List <Alarm>();

            var mergedValuesByAlarmName = service.Values.OverrideWith(resource.Values);

            foreach (var alarm in defaults)
            {
                var dimensions = _dimensionProvider.GetDimensions(queue, alarm.DimensionNames);
                var values     = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();

                var actualThreshold = alarm.Threshold.CopyWith(value: values.Threshold);

                var threshold = await ThresholdCalculator.ExpandThreshold(_attributeProvider,
                                                                          queue,
                                                                          mergedConfig,
                                                                          actualThreshold);

                var built = alarm.CopyWith(threshold, values);

                var model = new Alarm
                {
                    AlarmName        = $"{resource.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}",
                    AlarmDescription = groupParameters.DefaultAlarmDescription(resource),

                    // error queues currently named as per parent queue
                    ResourceIdentifier = resource.Name,
                    Dimensions         = dimensions,
                    AlarmDefinition    = built
                };

                result.Add(model);
            }

            if (includeErrorQueues && queue.ErrorQueue != null)
            {
                var alarms = await BuildAlarmsForQueue(_errorQueueDefaults, resource, service, groupParameters,
                                                       queue.ErrorQueue);

                result.AddRange(alarms);
            }

            return(result);
        }
        private async Task <List <Alarm> > BuildTableAlarms(ResourceThresholds <DynamoResourceConfig> resourceConfig,
                                                            AwsServiceAlarms <DynamoResourceConfig> service,
                                                            AlertingGroupParameters groupParameters,
                                                            AwsResource <TableDescription> entity)
        {
            var mergedConfig = service.Options.OverrideWith(resourceConfig.Options);

            var result = new List <Alarm>();

            var mergedValuesByAlarmName = service.Values.OverrideWith(resourceConfig.Values);

            var defaults = _defaultAlarms.DynamoDbRead;

            if (mergedConfig.MonitorWrites ?? DynamoResourceConfig.MonitorWritesDefault)
            {
                defaults = defaults.Concat(_defaultAlarms.DynamoDbWrite).ToArray();
            }

            foreach (var alarm in defaults)
            {
                var dimensions          = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames);
                var values              = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();
                var configuredThreshold = alarm.Threshold.CopyWith(value: values.Threshold);

                if (mergedConfig.ThresholdIsAbsolute ?? DynamoResourceConfig.ThresholdIsAbsoluteDefault)
                {
                    configuredThreshold.ThresholdType = ThresholdType.Absolute;
                }

                var threshold = await ThresholdCalculator.ExpandThreshold(_attributeProvider,
                                                                          entity.Resource,
                                                                          mergedConfig,
                                                                          configuredThreshold);

                var built = alarm.CopyWith(threshold, values);

                var model = new Alarm
                {
                    AlarmName        = $"{resourceConfig.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}",
                    AlarmDescription = groupParameters.DefaultAlarmDescription(),
                    Resource         = entity,
                    Dimensions       = dimensions,
                    AlarmDefinition  = built
                };

                result.Add(model);
            }

            return(result);
        }
        private async Task <IList <Alarm> > CreateAlarmsForResource(
            ResourceThresholds <TAlarmConfig> resource,
            AwsServiceAlarms <TAlarmConfig> service,
            AlertingGroupParameters groupParameters)
        {
            var entity = await _tableSource.GetResourceAsync(resource.Name);

            if (entity == null)
            {
                throw new Exception($"Entity {resource.Name} not found");
            }

            var mergedConfig            = service.Options.OverrideWith(resource.Options);
            var mergedValuesByAlarmName = service.Values.OverrideWith(resource.Values);

            var result = new List <Alarm>();

            foreach (var alarm in _defaultAlarms)
            {
                var values = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();
                var configuredThreshold = alarm.Threshold.CopyWith(value: values.Threshold);
                var dimensions          = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames);
                var threshold           = await ThresholdCalculator.ExpandThreshold(_attributeProvider,
                                                                                    entity.Resource,
                                                                                    mergedConfig,
                                                                                    configuredThreshold);

                var built = alarm.CopyWith(threshold, values);

                var model = new Alarm
                {
                    AlarmName        = $"{resource.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}",
                    AlarmDescription = groupParameters.DefaultAlarmDescription(),
                    Resource         = entity,
                    Dimensions       = dimensions,
                    AlarmDefinition  = built
                };

                result.Add(model);
            }

            return(result);
        }
        private async Task <IList <Alarm> > BuildIndexAlarms(ResourceThresholds <ResourceConfig> resource, AwsServiceAlarms <ResourceConfig> service, AlertingGroupParameters groupParameters,
                                                             AwsResource <TableDescription> entity)
        {
            var result = new List <Alarm>();

            var gsiSet = entity.Resource.GlobalSecondaryIndexes;


            foreach (var gsi in gsiSet)
            {
                var gsiResource = new AwsResource <GlobalSecondaryIndexDescription>(gsi.IndexName, gsi);


                var expandedGsi = await _gsiAlarmBuilder.CopyAndUpdateDefaultAlarmsForResource(
                    gsiResource,
                    Defaults.DynamoDbGsi, service, resource);

                foreach (var gsiAlarm in expandedGsi)
                {
                    var dimensions = _gsiDimensionProvider.GetDimensions(gsi, gsiAlarm.DimensionNames);

                    var model = new Alarm
                    {
                        AlarmName        = $"{resource.Name}-{gsi.IndexName}-{gsiAlarm.Name}-{groupParameters.AlarmNameSuffix}",
                        AlarmDescription = _builder.GetAlarmDescription(groupParameters),
                        Resource         = entity,
                        Dimensions       = dimensions,
                        AlarmDefinition  = gsiAlarm
                    };

                    result.Add(model);
                }
            }

            return(result);
        }
        private async Task <List <Alarm> > BuildTableAlarms(IList <AlarmDefinition> defaults, ResourceThresholds <ResourceConfig> resource, AwsServiceAlarms <ResourceConfig> service,
                                                            AlertingGroupParameters groupParameters,
                                                            AwsResource <TableDescription> entity)
        {
            var expanded = await _builder.CopyAndUpdateDefaultAlarmsForResource(entity, defaults, service, resource);

            var result = new List <Alarm>();

            foreach (var alarm in expanded)
            {
                var dimensions = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames);

                var model = new Alarm
                {
                    AlarmName        = $"{resource.Name}-{alarm.Name}-{groupParameters.AlarmNameSuffix}",
                    AlarmDescription = _builder.GetAlarmDescription(groupParameters),
                    Resource         = entity,
                    Dimensions       = dimensions,
                    AlarmDefinition  = alarm
                };
                result.Add(model);
            }
            return(result);
        }