Пример #1
0
        public static async Task <bool> Run([TimerTrigger(AvailabilityTestInterval.Minute01)] TimerInfo notUsed, ILogger log)
        {
            log.LogInformation($"**Availability func executed at: {DateTime.Now}");

            string responseContent;

            using (HttpClient http = AvailabilityTest.NewHttpClient())
            {
                using (HttpResponseMessage response = await http.GetAsync("https://availabilitymonitoring-extension-monitoredappsample.azurewebsites.net/Home/MonitoredPage"))
                {
                    HttpResponseMessage httpResponseMessage = response.EnsureSuccessStatusCode();

                    log.LogInformation($"**httpResponseMessage:" + httpResponseMessage.Content.ToString());

                    responseContent = await response.Content.ReadAsStringAsync();
                }
            }

            bool hasExpectedContent = responseContent.Contains("<title>Monitored Page</title>", StringComparison.OrdinalIgnoreCase) &&
                                      responseContent.Contains("(App Version Id: 2)", StringComparison.OrdinalIgnoreCase);

            log.LogInformation($"**hasExpectedContent?" + hasExpectedContent.ToString());

            //AvailabilityTelemetry result = testInfo.DefaultAvailabilityResult;

            //result.Properties["UserProperty"] = "User Value";
            //result.Success = hasExpectedContent;
            //return result;

            return(hasExpectedContent);
        }
Пример #2
0
        public static async Task <AvailabilityTelemetry> Run(
            [TimerTrigger(AvailabilityTestInterval.Minute01)] TimerInfo notUsed,
            //[TimerTrigger("*/5 * * * * *")] TimerInfo timerInfo,
            [AvailabilityTestInfo] AvailabilityTestInfo testInfo,
            ILogger log)
        {
            log.LogInformation($"[CatDemo-ExplicitlySpecifyConfig] Run(..): C#  Coded Availability Test Function executed at: {DateTime.Now}."
                               + $" ActivitySpanId = \"{Activity.Current.SpanId.ToHexString() ?? "null"}\";"
                               + $" TestDisplayName = \"{testInfo.TestDisplayName ?? "null"}\";"
                               + $" LocationDisplayName = \"{testInfo.LocationDisplayName ?? "null"}\";"
                               + $" LocationId = \"{testInfo.LocationId ?? "null"}\".");


            string responseContent;

            using (HttpClient http = AvailabilityTest.NewHttpClient())
            {
                using (HttpResponseMessage response = await http.GetAsync("https://availabilitymonitoring-extension-monitoredappsample.azurewebsites.net/Home/MonitoredPage"))
                {
                    response.EnsureSuccessStatusCode();
                    responseContent = await response.Content.ReadAsStringAsync();
                }
            }

            bool hasExpectedContent = responseContent.Contains("<title>Monitored Page</title>", StringComparison.OrdinalIgnoreCase) &&
                                      responseContent.Contains("(App Version Id: 2)", StringComparison.OrdinalIgnoreCase);

            AvailabilityTelemetry result = testInfo.DefaultAvailabilityResult;

            result.Properties["UserProperty"] = "User Value";
            result.Success = hasExpectedContent;
            return(result);
        }
Пример #3
0
        public static async Task <bool> Run(
            [TimerTrigger(AvailabilityTestInterval.Minute01)] TimerInfo notUsed,
            ILogger log)
        {
            // User-specified test parameters:

            string monitoredApiUrl = "http://availabilitymonitoring-extension-monitoredappsample02.azurewebsites.net/api/Time?source=CatMonitoredApiIsAvailable";

            HttpMethod httpMethod = HttpMethod.Get;

            KeyValuePair <string, string>[] headers = new KeyValuePair <string, string>[] {
            };
            string   payload        = null;
            TimeSpan overallTimeout = TimeSpan.FromSeconds(30);

            // Needs to be set for the result:
            bool isAvailabilityTestSuccessful;

            // Initialize an HTTP client and set default headers:
            using (var timeoutController = new CancellationTokenSource(overallTimeout))
                using (HttpClient http = AvailabilityTest.NewHttpClient())
                {
                    CancellationToken timeoutControl = timeoutController.Token;

                    // Run the request and get the response:
                    using (HttpResponseMessage response = await ExecuteRequestAsync(http, monitoredApiUrl, httpMethod, headers, payload, log, timeoutControl))
                    {
                        isAvailabilityTestSuccessful = await ValidateResponseAsync(response, log, timeoutControl);
                    }
                }

            return(isAvailabilityTestSuccessful);
        }
Пример #4
0
        public static async Task <bool> Run(
            [TimerTrigger(AvailabilityTestInterval.Minute01)] TimerInfo notUsed,
            ILogger log)
        {
            log.LogInformation($"[CatDemo-SimpleBinding] Run(..): C# Coded Availability Test Function executed at: {DateTime.Now}."
                               + $" ActivitySpanId = \"{Activity.Current.SpanId.ToHexString() ?? "null"}\".");

            string responseContent;

            using (HttpClient http = AvailabilityTest.NewHttpClient())
            {
                using (HttpResponseMessage response = await http.GetAsync("https://availabilitymonitoring-extension-monitoredappsample.azurewebsites.net/Home/MonitoredPage"))
                {
                    response.EnsureSuccessStatusCode();
                    responseContent = await response.Content.ReadAsStringAsync();
                }
            }

            bool hasExpectedContent = responseContent.Contains("<title>Monitored Page</title>", StringComparison.OrdinalIgnoreCase) &&
                                      responseContent.Contains("(App Version Id: 2)", StringComparison.OrdinalIgnoreCase);

            return(hasExpectedContent);
        }