예제 #1
0
        public static async Task <HealthCheck> UpsertCloudWatchHealthCheckAsync(this Route53Helper r53h,
                                                                                string name,
                                                                                string alarmName,
                                                                                string alarmRegion,
                                                                                bool inverted = false,
                                                                                InsufficientDataHealthStatus insufficientDataHealthStatus = null,
                                                                                bool throwIfNotFound = true,
                                                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            var hc = await r53h.GetHealthCheckAsync(name, throwIfNotFound : throwIfNotFound, cancellationToken : cancellationToken);

            if (hc == null)
            {
                hc = (await r53h.CreateCloudWatchHealthCheckAsync(
                          $"{name}-{Guid.NewGuid().ToString()}",
                          alarmName,
                          alarmRegion,
                          inverted,
                          insufficientDataHealthStatus,
                          cancellationToken)).HealthCheck;

                await r53h.ChangeTagsForHealthCheckAsync(hc.Id, new Tag[] { new Tag()
                                                                            {
                                                                                Key = "Name", Value = name
                                                                            } });

                await Task.Delay(1000); //ensure record was created

                return(hc);
            }

            var response = await r53h.UpdateHealthCheckAsync(new UpdateHealthCheckRequest()
            {
                HealthCheckId   = hc.Id,
                AlarmIdentifier = new AlarmIdentifier()
                {
                    Name   = alarmName,
                    Region = alarmRegion,
                },
                Inverted = inverted,
                InsufficientDataHealthStatus = insufficientDataHealthStatus ?? InsufficientDataHealthStatus.Unhealthy
            }, cancellationToken);

            await Task.Delay(1000); //ensure record was updated

            return(response.HealthCheck);
        }
예제 #2
0
        public static async Task <HealthCheck> UpsertHealthCheckAsync(this Route53Helper r53h,
                                                                      string name,
                                                                      string uri,
                                                                      int port,
                                                                      string path,
                                                                      int failureTreshold,
                                                                      string searchString  = null,
                                                                      bool throwIfNotFound = true,
                                                                      CancellationToken cancellationToken = default(CancellationToken))
        {
            var hc = await r53h.GetHealthCheckAsync(name, throwIfNotFound : throwIfNotFound, cancellationToken : cancellationToken);

            if (hc == null)
            {
                var result = await r53h.CreateHealthCheckAsync(
                    name,
                    uri,
                    port,
                    path,
                    searchString,
                    failureTreshold : failureTreshold);

                return(result.HealthCheck);
            }

            var response = await r53h.UpdateHealthCheckAsync(new UpdateHealthCheckRequest()
            {
                HealthCheckId            = hc.Id,
                FullyQualifiedDomainName = uri,
                Port             = port,
                ResourcePath     = path,
                SearchString     = searchString,
                FailureThreshold = failureTreshold,
                EnableSNI        = hc.HealthCheckConfig.EnableSNI,
            }, cancellationToken);

            return(response.HealthCheck);
        }