public void EmailAndUrlTargets_CreatesBothTopics()
        {
            // arrange
            var resource = new AwsResource <FakeResourceType>("name", new FakeResourceType());

            var alarms = new List <Alarm>();

            alarms.Add(CreateExampleAlarm(new List <AlertTarget>()
            {
                new AlertEmail()
                {
                    Email = "*****@*****.**"
                },
                new AlertUrl()
                {
                    Url = "*****@*****.**"
                }
            }, resource));

            // act
            var template = new CloudWatchCloudFormationTemplate();

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

            // assert
            var parsed     = JObject.Parse(result);
            var emailTopic = parsed["Resources"]["EmailTopic"];
            var urlTopic   = parsed["Resources"]["UrlTopic"];

            Assert.That(emailTopic, Is.Not.Null);
            Assert.That(urlTopic, Is.Not.Null);
        }
        public void EmailTargets_CreatedTopicCorrectly()
        {
            // arrange
            var resource = new AwsResource <FakeResourceType>("name", new FakeResourceType());
            var targets  = new List <AlertTarget>()
            {
                new AlertEmail("*****@*****.**"),
                new AlertEmail("*****@*****.**")
            };
            var alarms = new List <Alarm>();

            alarms.Add(CreateExampleAlarm(resource));

            // act
            var template = new CloudWatchCloudFormationTemplate(AlertingGroupName, targets);

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

            // assert
            var parsed     = JObject.Parse(result);
            var emailTopic = parsed["Resources"]["EmailTopic"];

            Assert.That(emailTopic, Is.Not.Null);

            var emailsInTopic = emailTopic["Properties"]["Subscription"].ToList();

            Assert.That(emailsInTopic.All(j => (string)j["Protocol"] == "email"));
            Assert.That(emailsInTopic.Count, Is.EqualTo(2));

            Assert.That(emailsInTopic.Exists(j => (string)j["Endpoint"] == "*****@*****.**"));
            Assert.That(emailsInTopic.Exists(j => (string)j["Endpoint"] == "*****@*****.**"));
        }
Example #3
0
        public async Task <AwsResource <TableDescription> > GetResourceAsync(string name)
        {
            if (_tableNames == null)
            {
                await GetResourceNamesAsync();
            }

            if (!_tableNames.Contains(name))
            {
                return(null);
            }

            if (_cachedTableDescriptions.ContainsKey(name))
            {
                return(_cachedTableDescriptions[name]);
            }

            var tableResponse = await _dynamoDb.DescribeTableAsync(name);

            var dataItem = new AwsResource <TableDescription>(tableResponse.Table.TableName, tableResponse.Table);

            _cachedTableDescriptions.Add(tableResponse.Table.TableName, dataItem);

            return(dataItem);
        }
        public void GivenATableWithIndex(string tableName, string indexName, int indexRead, int indexWrite)
        {
            var tableDesc = new TableDescription
            {
                TableName             = tableName,
                ProvisionedThroughput = new ProvisionedThroughputDescription
                {
                    ReadCapacityUnits  = indexRead,
                    WriteCapacityUnits = indexWrite
                },
                GlobalSecondaryIndexes = new List <GlobalSecondaryIndexDescription>
                {
                    new GlobalSecondaryIndexDescription
                    {
                        IndexName             = indexName,
                        ProvisionedThroughput = new ProvisionedThroughputDescription
                        {
                            ReadCapacityUnits  = indexRead,
                            WriteCapacityUnits = indexWrite
                        }
                    }
                }
            };

            var resource = new AwsResource <TableDescription>(tableName, tableDesc);

            TableLoader
            .Setup(x => x.GetResourceAsync(tableName))
            .ReturnsAsync(resource);
        }
 private static Alarm CreateExampleAlarm(List <AlertTarget> targets, AwsResource <FakeResourceType> resource)
 {
     return(new Alarm()
     {
         AlarmDefinition = new AlarmDefinition()
         {
             ComparisonOperator = ComparisonOperator.GreaterThanOrEqualToThreshold,
             Statistic = Statistic.Average,
             Threshold = new Threshold()
             {
                 ThresholdType = ThresholdType.Absolute
             },
             AlertOnInsufficientData = true,
             AlertOnOk = true
         },
         AlarmName = "",
         AlertingGroup = new ServiceAlertingGroup()
         {
             Name = AlertingGroupName,
             Targets = targets
         },
         Dimensions = new List <Dimension>(),
         Resource = resource
     });
 }
Example #6
0
        private async Task <AlarmDefinition> AlarmWithMergedValues(
            AwsResource <T> entity,
            AlarmDefinition alarm,
            AwsServiceAlarms <TAlarmConfig> serviceConfig,
            ResourceThresholds <TAlarmConfig> resourceConfig)
        {
            var mergedThreshold = MergeValueOverrides(alarm.Name, new [] { resourceConfig.Values, serviceConfig.Values });
            var config          = MergeConfiguration(serviceConfig.Options, resourceConfig.Options);

            var copy = alarm.Copy();

            copy.Threshold = await ExpandThreshold(entity.Resource, config, new Threshold
            {
                SourceAttribute = alarm.Threshold.SourceAttribute,
                ThresholdType   = alarm.Threshold.ThresholdType,
                Value           = mergedThreshold.Threshold ?? alarm.Threshold.Value
            });

            copy.EvaluationPeriods = mergedThreshold.EvaluationPeriods ?? alarm.EvaluationPeriods;

            copy.ExtendedStatistic = !string.IsNullOrEmpty(mergedThreshold.ExtendedStatistic)
                ? mergedThreshold.ExtendedStatistic
                : alarm.ExtendedStatistic;

            return(copy);
        }
Example #7
0
        private static ResourceAndThresholdsPair <TConfig, T> PatternToTable(
            ResourceThresholds <TConfig> pattern, AwsResource <T> resource)
        {
            pattern = pattern.AsNamed(resource.Name);

            var matched = new ResourceAndThresholdsPair <TConfig, T>(pattern, resource);

            return(matched);
        }
Example #8
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        AwsResource.Delete(pathSid: "CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    }
Example #9
0
        private async Task <IList <Alarm> > BuildIndexAlarms(ResourceThresholds <DynamoResourceConfig> resourceConfig,
                                                             AwsServiceAlarms <DynamoResourceConfig> service,
                                                             AlertingGroupParameters groupParameters,
                                                             AwsResource <TableDescription> parentTableEntity)
        {
            // called twice
            var mergedConfig = service.Options.OverrideWith(resourceConfig.Options);

            var result = new List <Alarm>();

            var gsiSet = parentTableEntity.Resource.GlobalSecondaryIndexes;

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

            var defaults = _defaultAlarms.DynamoDbGsiRead;

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

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

                foreach (var alarm in defaults)
                {
                    var values = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();
                    var configuredThreshold = alarm.Threshold.CopyWith(value: values.Threshold);
                    var dimensions          = _gsiProvider.GetDimensions(gsi, parentTableEntity.Resource, alarm.DimensionNames);
                    var threshold           = await ThresholdCalculator.ExpandThreshold(_gsiProvider,
                                                                                        gsiResource.Resource,
                                                                                        mergedConfig,
                                                                                        configuredThreshold);

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

                    var model = new Alarm
                    {
                        AlarmName        = $"{resourceConfig.Name}-{gsi.IndexName}-{alarm.Name}-{groupParameters.AlarmNameSuffix}",
                        AlarmDescription = groupParameters.DefaultAlarmDescription(),
                        // TODO: remove this property in a future PR
                        // passing in the entity shouldn't be necessary and passing in the table entity here
                        // when the alarm is for a GSI is an even worse hack
                        Resource        = parentTableEntity,
                        Dimensions      = dimensions,
                        AlarmDefinition = built
                    };

                    result.Add(model);
                }
            }

            return(result);
        }
Example #10
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        AwsResource.Delete(pathSid: "CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    }
Example #11
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var aws = AwsResource.Fetch(pathSid: "CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

        Console.WriteLine(aws.FriendlyName);
    }
        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);
        }
Example #13
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var aws = AwsResource.Create(
            credentials: "AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
            );

        Console.WriteLine(aws.Sid);
    }
Example #14
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var aws = AwsResource.Read();

        foreach (var record in aws)
        {
            Console.WriteLine(record.Sid);
        }
    }
        private static ResourceAndThresholdsPair <TConfig, T> PatternToTable(
            ResourceThresholds <TConfig> pattern, AwsResource <T> resource)
        {
            var config = new ResourceThresholds <TConfig>
            {
                Name    = resource.Name,
                Pattern = null,
                Values  = pattern.Values,
                Options = pattern.Options
            };

            var matched = new ResourceAndThresholdsPair <TConfig, T>(config, resource);

            return(matched);
        }
        public void TestCreateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.Created,
                         "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"date_created\": \"2015-07-31T04:00:00Z\",\"date_updated\": \"2015-07-31T04:00:00Z\",\"friendly_name\": \"friendly_name\",\"sid\": \"CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"url\": \"https://accounts.twilio.com/v1/Credentials/AWS/CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"
                         ));

            var response = AwsResource.Create("AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestReadFullResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"credentials\": [{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"date_created\": \"2015-07-31T04:00:00Z\",\"date_updated\": \"2015-07-31T04:00:00Z\",\"friendly_name\": \"friendly_name\",\"sid\": \"CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"url\": \"https://accounts.twilio.com/v1/Credentials/AWS/CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}],\"meta\": {\"first_page_url\": \"https://accounts.twilio.com/v1/Credentials/AWS?PageSize=50&Page=0\",\"key\": \"credentials\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://accounts.twilio.com/v1/Credentials/AWS?PageSize=50&Page=0\"}}"
                         ));

            var response = AwsResource.Read(client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestReadEmptyResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"credentials\": [],\"meta\": {\"first_page_url\": \"https://accounts.twilio.com/v1/Credentials/AWS?PageSize=50&Page=0\",\"key\": \"credentials\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://accounts.twilio.com/v1/Credentials/AWS?PageSize=50&Page=0\"}}"
                         ));

            var response = AwsResource.Read(client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestDeleteResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.NoContent,
                         "null"
                         ));

            var response = AwsResource.Delete("CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestUpdateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"date_created\": \"2015-07-31T04:00:00Z\",\"date_updated\": \"2015-07-31T04:00:00Z\",\"friendly_name\": \"friendly_name\",\"sid\": \"CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"url\": \"https://accounts.twilio.com/v1/Credentials/AWS/CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"
                         ));

            var response = AwsResource.Update("CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);

            Assert.NotNull(response);
        }
        private async Task <List <Alarm> > BuildAlarmsForQueue(
            IList <AlarmDefinition> defaults,
            ResourceThresholds <SqsResourceConfig> resource,
            AwsServiceAlarms <SqsResourceConfig> service,
            AlertingGroupParameters groupParameters,
            AwsResource <QueueDataV2> entity)
        {
            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(entity.Resource, alarm.DimensionNames);
                var values     = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();

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

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

                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);
            }

            if (includeErrorQueues && entity.Resource.ErrorQueue != null)
            {
                var errorQueueResource = new AwsResource <QueueDataV2>(entity.Name, entity.Resource.ErrorQueue);
                result.AddRange(await BuildAlarmsForQueue(_errorQueueDefaults, resource, service, groupParameters, errorQueueResource));
            }

            return(result);
        }
Example #22
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var aws = AwsResource.Read(limit: 20);

        foreach (var record in aws)
        {
            Console.WriteLine(record.Sid);
        }
    }
Example #23
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var aws = AwsResource.Update(
            friendlyName: "friendlyName",
            pathSid: "CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );

        Console.WriteLine(aws.FriendlyName);
    }
Example #24
0
        public async Task <IList <AlarmDefinition> > CopyAndUpdateDefaultAlarmsForResource(
            AwsResource <T> entity,
            IList <AlarmDefinition> alerts,
            AwsServiceAlarms <TAlarmConfig> serviceConfig,
            ResourceThresholds <TAlarmConfig> resourceConfig)
        {
            var result = new List <AlarmDefinition>();

            foreach (var defaultAlarm in alerts)
            {
                var alarm = await AlarmWithMergedValues(entity, defaultAlarm, serviceConfig, resourceConfig);

                result.Add(alarm);
            }

            return(result);
        }
        public void UrlTargets_CreatedTopicCorrectly()
        {
            // arrange
            var resource = new AwsResource <FakeResourceType>("name", new FakeResourceType());

            var alarms = new List <Alarm>();

            alarms.Add(CreateExampleAlarm(new List <AlertTarget>()
            {
                new AlertUrl()
                {
                    Url = "http://banana"
                },
                new AlertUrl()
                {
                    Url = "https://banana2"
                },
            }, resource));

            // act
            var template = new CloudWatchCloudFormationTemplate();

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

            // assert
            var parsed     = JObject.Parse(result);
            var emailTopic = parsed["Resources"]["UrlTopic"];

            Assert.That(emailTopic, Is.Not.Null);
            Assert.That((string)emailTopic["Properties"]["TopicName"], Is.EqualTo($"AwsWatchman_Url_{AlertingGroupName}"));

            var emailsInTopic = emailTopic["Properties"]["Subscription"].ToList();

            Assert.That(emailsInTopic.Count, Is.EqualTo(2));

            Assert.That(emailsInTopic.Exists(j =>

                                             (string)j["Endpoint"] == "http://banana" && (string)j["Protocol"] == "http"
                                             ));

            Assert.That(emailsInTopic.Exists(j =>

                                             (string)j["Endpoint"] == "https://banana2" && (string)j["Protocol"] == "https"
                                             ));
        }
        private async Task <IList <Alarm> > CreateAlarmsForResource(
            ResourceThresholds <SqsResourceConfig> resource,
            AwsServiceAlarms <SqsResourceConfig> service,
            AlertingGroupParameters groupParameters)
        {
            var entity = await _queueSource.GetResourceAsync(resource.Name);

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

            var queueResource = new AwsResource <QueueDataV2>(entity.Name, entity.Resource);
            var alarms        = await BuildAlarmsForQueue(_defaultAlarms, resource, service, groupParameters, queueResource);

            return(alarms);
        }
        public void TargetMappingIsCorrect()
        {
            // arrange
            var resource = new AwsResource <FakeResourceType>("name", new FakeResourceType());

            var alarms = new List <Alarm>();

            alarms.Add(CreateExampleAlarm(new List <AlertTarget>()
            {
                new AlertUrl()
                {
                    Url = "http://banana"
                },
                new AlertEmail()
                {
                    Email = "*****@*****.**"
                },
            }, resource));

            // act
            var template = new CloudWatchCloudFormationTemplate();

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

            // assert
            var parsed = JObject.Parse(result);

            var alarm = ((JObject)parsed["Resources"])
                        .Properties()
                        .Single(j => j.Value["Type"].Value <string>() == "AWS::CloudWatch::Alarm")
                        .Value;

            var okTargets           = (JArray)alarm["Properties"]["OKActions"];
            var insufficientTargets = (JArray)alarm["Properties"]["InsufficientDataActions"];
            var alarmTargets        = (JArray)alarm["Properties"]["AlarmActions"];

            // ok alarms only go to urls, everything else goes to email also
            Assert.That((string)okTargets.Single()["Ref"], Is.EqualTo("UrlTopic"));

            Assert.That(insufficientTargets.Any(j => (string)j["Ref"] == "UrlTopic"));
            Assert.That(insufficientTargets.Any(j => (string)j["Ref"] == "EmailTopic"));
            Assert.That(alarmTargets.Any(j => (string)j["Ref"] == "UrlTopic"));
            Assert.That(alarmTargets.Any(j => (string)j["Ref"] == "EmailTopic"));
        }
        public void GivenATable(string tableName, int readCapacity, int writeCapacity)
        {
            var tableDesc = new TableDescription
            {
                TableName             = tableName,
                ProvisionedThroughput = new ProvisionedThroughputDescription
                {
                    ReadCapacityUnits  = readCapacity,
                    WriteCapacityUnits = writeCapacity
                }
            };

            var resource = new AwsResource <TableDescription>(tableName, tableDesc);

            TableLoader
            .Setup(x => x.GetResourceAsync(tableName))
            .ReturnsAsync(resource);
        }
        public void TestReadRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Get,
                Twilio.Rest.Domain.Accounts,
                "/v1/Credentials/AWS",
                ""
                );

            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                AwsResource.Read(client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
 private static Alarm CreateExampleAlarm(AwsResource <FakeResourceType> resource)
 {
     return(new Alarm()
     {
         AlarmDefinition = new AlarmDefinition()
         {
             ComparisonOperator = ComparisonOperator.GreaterThanOrEqualToThreshold,
             Statistic = Statistic.Average,
             Threshold = new Threshold()
             {
                 ThresholdType = ThresholdType.Absolute
             },
             AlertOnInsufficientData = true,
             AlertOnOk = true
         },
         AlarmName = "",
         Dimensions = new List <Dimension>(),
         ResourceIdentifier = resource.Name
     });
 }