public static async Task <MetricAlarm> UpsertAELBMetricAlarmAsync( this CloudWatchHelper cwh, ELBHelper elb, string name, string loadBalancer, string targetGroup, ELBMetricName metric, ComparisonOperator comparisonOperator, int treshold, Statistic statistic = null, int dataPointToAlarm = 1, int evaluationPeriod = 1, int requestDelay = 1000, CancellationToken cancellationToken = default(CancellationToken)) { var alb = (await elb.GetLoadBalancersByName(loadBalancer, throwIfNotFound: true)).Single(); var tg = await elb.GetTargetGroupByName(targetGroup, alb, throwIfNotFound : true); var loadBalanceValue = alb.LoadBalancerArn.SplitByLast(':')[1].TrimStartSingle("loadbalancer/"); var targetGroupValue = tg.TargetGroupArn.SplitByLast(':')[1]; var stat = statistic != null ? statistic : (comparisonOperator == ComparisonOperator.GreaterThanOrEqualToThreshold || comparisonOperator == ComparisonOperator.GreaterThanThreshold) ? Statistic.Maximum : Statistic.Minimum; var deleteAlarm = await cwh.DeleteMetricAlarmAsync(name, throwIfNotFound : false); if (deleteAlarm.HttpStatusCode != System.Net.HttpStatusCode.NotFound) { await Task.Delay(requestDelay); //lets ensure metric was removed before we push new request } var mar = await cwh.PutAELBMetricAlarmAsync( name, loadBalanceValue, targetGroupValue, metric : metric, comparisonOperator : comparisonOperator, statistic : stat, treshold : treshold, dataPointToAlarm : dataPointToAlarm, evaluationPeriod : evaluationPeriod, cancellationToken : cancellationToken); await Task.Delay(requestDelay); //lets ensure metric exists before we search for it return(await cwh.GetMetricAlarmAsync(name : name, throwIfNotFound : true, cancellationToken : cancellationToken)); }
public Task <PutMetricAlarmResponse> PutAELBMetricAlarmAsync( string name, string loadBalancer, string targetGroup, ELBMetricName metric, ComparisonOperator comparisonOperator, Statistic statistic, int treshold, int dataPointToAlarm = 1, int evaluationPeriod = 1, CancellationToken cancellationToken = default(CancellationToken)) => _client.PutMetricAlarmAsync(new PutMetricAlarmRequest() { AlarmName = name, Period = 60, Namespace = "AWS/ApplicationELB", Dimensions = new List <Dimension>() { new Dimension() { Name = "LoadBalancer", Value = loadBalancer //app/test-1-ui-1-alb-pub/0d603d7ab786c184 }, new Dimension() { Name = "TargetGroup", Value = targetGroup //"targetgroup/test-1-ui-1-tg-public/a74c4ffa6cb637ab" } }, MetricName = metric.ToString(), EvaluationPeriods = evaluationPeriod, DatapointsToAlarm = dataPointToAlarm, ComparisonOperator = comparisonOperator, ActionsEnabled = true, Statistic = statistic, Threshold = treshold, AlarmDescription = "Auto Generated by Asmodat AWSWrapper Toolkit." }, cancellationToken).EnsureSuccessAsync();