コード例 #1
0
        private static void Validate(AlertingGroup alertingGroup)
        {
            if (string.IsNullOrWhiteSpace(alertingGroup.Name))
            {
                throw new ConfigException("AlertingGroup must have a name");
            }

            if (!TextIsValidInSnsTopic(alertingGroup.Name))
            {
                throw new ConfigException($"AlertingGroup name '{alertingGroup.Name}' must be valid in SNS topics");
            }

            if (string.IsNullOrWhiteSpace(alertingGroup.AlarmNameSuffix))
            {
                throw new ConfigException($"AlertingGroup '{alertingGroup.Name}' must have an alarm suffix");
            }

            if (!TextIsValidInSnsTopic(alertingGroup.AlarmNameSuffix))
            {
                throw new ConfigException($"AlertingGroup '{alertingGroup.Name}' must have a suffix valid in SNS topics. '{alertingGroup.AlarmNameSuffix}' is not.");
            }

            ValidateTargets(alertingGroup);

            var hasAtLeastOneResource = false;

            if (HasAny(alertingGroup.DynamoDb?.Tables))
            {
                hasAtLeastOneResource = true;
                DynamoDbValidation.Validate(alertingGroup.Name, alertingGroup.DynamoDb);
            }

            if (HasAny(alertingGroup.Sqs?.Queues))
            {
                hasAtLeastOneResource = true;
                SqsValidation.Validate(alertingGroup.Name, alertingGroup.Sqs);
            }

            if (alertingGroup.Services != null)
            {
                foreach (var service in alertingGroup.Services.AllServicesByName)
                {
                    if (service.Value != null)
                    {
                        AwsServiceValidation.Validate(alertingGroup.Name, service.Key, service.Value);

                        if (HasAny(service.Value.Resources))
                        {
                            hasAtLeastOneResource = true;
                        }
                    }
                }
            }

            if (!hasAtLeastOneResource)
            {
                throw new ConfigException($"AlertingGroup '{alertingGroup.Name}' must contain resources to monitor. " +
                                          "Specify one or more of DynamoDb, Sqs or other resources");
            }
        }
コード例 #2
0
        private static void Validate(AlertingGroup alertingGroup)
        {
            if (string.IsNullOrWhiteSpace(alertingGroup.Name))
            {
                throw new ConfigException("AlertingGroup must have a name");
            }

            if (!TextIsValidInSnsTopic(alertingGroup.Name))
            {
                throw new ConfigException($"AlertingGroup name '{alertingGroup.Name}' must be valid in SNS topics");
            }

            if (string.IsNullOrWhiteSpace(alertingGroup.AlarmNameSuffix))
            {
                throw new ConfigException($"AlertingGroup '{alertingGroup.Name}' must have an alarm suffix");
            }

            if (!TextIsValidInSnsTopic(alertingGroup.AlarmNameSuffix))
            {
                throw new ConfigException($"AlertingGroup '{alertingGroup.Name}' must have a suffix valid in SNS topics. '{alertingGroup.AlarmNameSuffix}' is not.");
            }

            ValidateTargets(alertingGroup);

            if (HasAny(alertingGroup.DynamoDb?.Tables))
            {
                DynamoDbValidation.Validate(alertingGroup.Name, alertingGroup.DynamoDb);
            }

            if (HasAny(alertingGroup.Sqs?.Queues))
            {
                SqsValidation.Validate(alertingGroup.Name, alertingGroup.Sqs);
            }

            if (alertingGroup.Services != null)
            {
                foreach (var service in alertingGroup.Services.AllServicesByName)
                {
                    if (service.Value != null)
                    {
                        AwsServiceValidation.Validate(alertingGroup.Name, service.Key, service.Value);
                    }
                }
            }
        }