private async Task GenerateAndDeployStack(IEnumerable <Alarm> alarms,
                                                  string stackName, bool dryRun)
        {
            var template = new CloudWatchCloudFormationTemplate();

            template.AddAlarms(alarms);
            var json = template.WriteJson();

            await _stack.DeployStack(stackName, json, dryRun);
        }
Example #2
0
        private async Task GenerateAndDeployStack(
            IEnumerable <Alarm> alarms,
            IEnumerable <AlertTarget> targets,
            string groupName,
            string stackName,
            bool dryRun)
        {
            alarms = alarms.Where(a => a.AlarmDefinition.Enabled).ToList();

            var onlyUpdateExisting = !alarms.Any();

            var template = new CloudWatchCloudFormationTemplate(groupName, targets.ToList());

            template.AddAlarms(alarms);
            var json = template.WriteJson();
            await _stack.DeployStack(stackName, json, dryRun, onlyUpdateExisting);
        }
Example #3
0
        private async Task GenerateAndDeployStack(
            IEnumerable <Alarm> alarms,
            IEnumerable <AlertTarget> targets,
            string groupName,
            string stackName,
            bool dryRun)
        {
            alarms = alarms.Where(a => a.AlarmDefinition.Enabled).ToList();

            // if there are no alarms we want to update existing stacks (in case everything has been removed)
            // but we don't want to create a new one which is empty
            var onlyUpdateExisting = !alarms.Any();

            var template = new CloudWatchCloudFormationTemplate(groupName, targets.ToList());

            template.AddAlarms(alarms);
            var json = template.WriteJson();
            await _stack.DeployStack(stackName, json, dryRun, onlyUpdateExisting);
        }
        private async Task GenerateAndDeployStack(IEnumerable <Alarm> alarms, IEnumerable <AlertTarget> targets,
                                                  string groupName,
                                                  string stackName, bool dryRun)
        {
            alarms = alarms.ToList();
            if (!alarms.Any())
            {
                // todo, we should actually continue here but will change in later PR as want to keep behaviour same during refactor
                _logger.Info($"{stackName} would have no alarms, skipping");
                return;
            }

            var template = new CloudWatchCloudFormationTemplate(groupName, targets.ToList());

            template.AddAlarms(alarms);
            var json = template.WriteJson();

            await _stack.DeployStack(stackName, json, dryRun);
        }
        public async Task SaveChanges(bool dryRun)
        {
            var groupedBySuffix = _alarms
                                  .GroupBy(x => x.AlertingGroup.Name,
                                           x => x,
                                           (g, x) => new
            {
                // this is because a lot of the group suffixes are lower(group name)
                // and it reduces the impact of moving stack naming from suffix to name
                Name   = g.ToLowerInvariant(),
                Alarms = x
            });

            foreach (var group in groupedBySuffix)
            {
                var stackName = "Watchman-" + group.Name;
                var template  = new CloudWatchCloudFormationTemplate();
                template.AddAlarms(group.Alarms);
                var json = template.WriteJson();

                await _stack.DeployStack(stackName, json, dryRun);
            }
        }