public static async Task UpsertEcsAliveMetricAlarmAsync( this CloudWatchHelper cwh, string name, string clusterName, string serviceName, CancellationToken cancellationToken = default(CancellationToken)) { await cwh.DeleteMetricAlarmAsync(name, throwIfNotFound : false); await cwh.PutEcsAliveMetricAlarmAsync(name, clusterName, serviceName, cancellationToken); }
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)); }