public async Task <object> GetInsights(string subscriptionId, string resourceGroupName, string provider, string resourceType, string resourceName, string pesId = null, string supportTopicId = null, string supportTopic = null, string startTime = null, string endTime = null)
        {
            Task <ObserverResponse> getResourceTask = null;
            var appServiceResources = new string[] { InsightsConstants.SiteResourceTypeName, InsightsConstants.HostingEnvironmentResourceTypeName };

            if (appServiceResources.Contains(resourceType))
            {
                switch (resourceType)
                {
                case InsightsConstants.SiteResourceTypeName:
                    getResourceTask = observerService.GetSite(resourceName);
                    break;

                case InsightsConstants.HostingEnvironmentResourceTypeName:
                    getResourceTask = observerService.GetHostingEnvironmentDetails(resourceName);
                    break;
                }

                var resource = await getResourceTask;
                if (resource.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(new NotFoundResult());

                    throw new Exception($"Could not find resource with resource path {resourceName}");
                }
            }

            if (string.IsNullOrWhiteSpace(supportTopicId) && !string.IsNullOrWhiteSpace(supportTopic))
            {
                if (SupportCenterMapping.Mapping.TryGetValue(supportTopic, out Tuple <string, string> info))
                {
                    pesId          = info.Item1;
                    supportTopicId = info.Item2;
                }
                else
                {
                    pesId          = "xxx";
                    supportTopicId = "xxx";
                }
            }

            var diagnosticPath = $"subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{provider}/{resourceType}/{resourceName}/insights?pesId={pesId}&supportTopicId={supportTopicId}&startTime={startTime}&endTime={endTime}";
            var insights       = await diagnosticClientService.Execute(HttpMethod.Post.Method, diagnosticPath, null, true, false);

            if (insights.IsSuccessStatusCode)
            {
                var content = await insights.Content.ReadAsStringAsync();

                var jsonContent = JsonConvert.DeserializeObject <JToken>(content);
                return(jsonContent);
            }

            return(null);
        }
Exemple #2
0
        /// <inheritdoc/>
        public async Task <bool> LogToKusto(InternalEventBody logMessage)
        {
            try
            {
                string body     = JsonConvert.SerializeObject(logMessage);
                var    response = await _diagnosticClient.Execute("POST", "/internal/logger", body);

                response.EnsureSuccessStatusCode();
                return(true);
            }
            catch (JsonSerializationException jsException)
            {
                throw new JsonSerializationException("FreshChatException. Failed to serialize data while sending a request to log in Kusto.", jsException);
            }
            catch (HttpRequestException hException)
            {
                throw new HttpRequestException("FreshChatException. Failed to send a log in Kusto.", hException);
            }
            catch (Exception ex)
            {
                throw new Exception("FreshChatException. Unknown exception. Review for more details.", ex);
            }
        }
        private async Task <HttpResponseMessage> ExecuteDiagCall(string path)
        {
            var response = await _diagnosticClientService.Execute(HttpMethod.Get.Method, "observer/" + path);

            return(response);
        }