Exemple #1
0
        public async Task <List <SupportTopic> > GetSupportTopicsAsync(string productId)
        {
            if (string.IsNullOrWhiteSpace(productId))
            {
                throw new ArgumentNullException("productId");
            }

            string kustoQuery = _supportTopicsQuery
                                .Replace("{PRODUCTID}", productId);

            DataTable dt = await _kustoQueryService.ExecuteQueryAsync("azsupportfollower.westus2", "AzureSupportability", kustoQuery);

            List <SupportTopic> supportTopicsList = new List <SupportTopic>();

            if (dt == null || dt.Rows == null || dt.Rows.Count == 0)
            {
                return(supportTopicsList);
            }

            foreach (DataRow row in dt.Rows)
            {
                SupportTopic supportTopic = new SupportTopic
                {
                    ProductId          = row["ProductId"].ToString(),
                    SupportTopicId     = row["SupportTopicId"].ToString(),
                    ProductName        = row["ProductName"].ToString(),
                    SupportTopicL2Name = row["SupportTopicL2Name"].ToString(),
                    SupportTopicL3Name = row["SupportTopicL3Name"].ToString(),
                    SupportTopicPath   = row["SupportTopicPath"].ToString()
                };

                supportTopicsList.Add(supportTopic);
            }

            return(supportTopicsList);
        }
Exemple #2
0
        public async Task <List <Communication> > GetCommunicationsAsync(string subscription, DateTime startTime, DateTime endTime, string impactedService = "appservice")
        {
            if (string.IsNullOrWhiteSpace(subscription))
            {
                throw new ArgumentNullException("subscription");
            }

            if (string.IsNullOrWhiteSpace(impactedService))
            {
                impactedService = "appservice";
            }

            DateTime currentTimeUTC = DateTime.UtcNow;

            string startTimeStr = DateTimeHelper.GetDateTimeInUtcFormat(startTime).ToString("yyyy-MM-dd HH:mm:ss");
            string endTimeStr   = DateTimeHelper.GetDateTimeInUtcFormat(endTime).ToString("yyyy-MM-dd HH:mm:ss");

            string kustoQuery = _commsQuery
                                .Replace("{START_TIME}", startTimeStr)
                                .Replace("{END_TIME}", endTimeStr)
                                .Replace("{SUBSCRIPTION}", subscription);

            DataTable dt = await _kustoQueryService.ExecuteQueryAsync("Icmcluster", "ACM.Backend", kustoQuery);

            List <Communication> commsList = new List <Communication>();

            if (dt == null || dt.Rows == null || dt.Rows.Count == 0)
            {
                return(commsList);
            }

            foreach (DataRow row in dt.Rows)
            {
                Communication comm = new Communication
                {
                    CommunicationId = row["CommunicationId"].ToString(),
                    PublishedTime   = DateTimeHelper.GetDateTimeInUtcFormat(DateTime.Parse(row["PublishedTime"].ToString())),
                    Title           = row["Title"].ToString(),
                    RichTextMessage = row["RichTextMessage"].ToString(),
                    Status          = row["Status"].ToString().Equals("Active", StringComparison.OrdinalIgnoreCase) ? CommunicationStatus.Active : CommunicationStatus.Resolved,
                    IncidentId      = row["IncidentId"].ToString(),
                    IcmId           = row["ExternalIncidentId"].ToString()
                };

                comm.ImpactedServices = GetImpactedRegions(row["ImpactedServices"].ToString());
                commsList.Add(comm);
            }

            commsList = commsList.OrderByDescending(p => p.PublishedTime).ToList();

            Communication mostRecentComm = null;
            Communication latestCommContainingImpactedService = commsList.FirstOrDefault(p => p.ImpactedServices.Exists(q => q.Name.ToLower().Contains(impactedService.ToLower())));

            if (latestCommContainingImpactedService != null)
            {
                // Sometimes Communications belonging to same IncidentId may have different Impacted Services.
                // To accurately identify the latest update:
                // 1) Figure out the latest communication containing impacted service as your service (object : latestCommContainingImpactedService)
                // 2) Now find out the latest communication with the same Incident Id as the first one (object : mostRecentCommWithSameIncidentId)
                mostRecentComm = commsList.FirstOrDefault(p => p.IncidentId.Equals(latestCommContainingImpactedService.IncidentId, StringComparison.OrdinalIgnoreCase));
            }

            // After finding the most recent communication for the impacted Service, show the alert only:
            // a) If the alert is still active, or
            // b) If the published time of the comm is within the _commAlertWindow
            if (mostRecentComm != null &&
                (mostRecentComm.Status == CommunicationStatus.Active
                 ||
                 (currentTimeUTC - mostRecentComm.PublishedTime) <= _commAlertWindow))
            {
                mostRecentComm.IsAlert    = true;
                mostRecentComm.IsExpanded = mostRecentComm.Status == CommunicationStatus.Active;
            }

            return(commsList);
        }
        public async Task <List <Communication> > GetCommunicationsAsync(string subscription, DateTime startTime, DateTime endTime, string impactedService = "appservice")
        {
            if (string.IsNullOrWhiteSpace(subscription))
            {
                throw new ArgumentNullException("subscription");
            }

            if (string.IsNullOrWhiteSpace(impactedService))
            {
                impactedService = "appservice";
            }

            DateTime currentTimeUTC = DateTime.UtcNow;

            string startTimeStr = DateTimeHelper.GetDateTimeInUtcFormat(startTime).ToString("yyyy-MM-dd HH:mm:ss");
            string endTimeStr   = DateTimeHelper.GetDateTimeInUtcFormat(endTime).ToString("yyyy-MM-dd HH:mm:ss");

            string kustoQuery = _commsQuery
                                .Replace("{START_TIME}", startTimeStr)
                                .Replace("{END_TIME}", endTimeStr)
                                .Replace("{SUBSCRIPTION}", subscription);

            DataTable dt = await _kustoQueryService.ExecuteQueryAsync("Icmcluster", "ACM.Backend", kustoQuery);

            List <Communication> commsList = new List <Communication>();

            if (dt == null || dt.Rows == null || dt.Rows.Count == 0)
            {
                return(commsList);
            }

            foreach (DataRow row in dt.Rows)
            {
                Communication comm = new Communication
                {
                    CommunicationId = row["CommunicationId"].ToString(),
                    PublishedTime   = DateTimeHelper.GetDateTimeInUtcFormat(DateTime.Parse(row["PublishedTime"].ToString())),
                    Title           = row["Title"].ToString(),
                    RichTextMessage = row["RichTextMessage"].ToString(),
                    Status          = row["Status"].ToString().Equals("Active", StringComparison.OrdinalIgnoreCase) ? CommunicationStatus.Active : CommunicationStatus.Resolved,
                    IncidentId      = row["IncidentId"].ToString()
                };

                comm.ImpactedServices = GetImpactedRegions(row["ImpactedServices"].ToString());
                commsList.Add(comm);
            }

            commsList = commsList.OrderByDescending(p => p.PublishedTime).ToList();

            Communication impactedServiceComm           = null;
            Communication mostRecentImpactedServiceComm = commsList.FirstOrDefault(p => p.ImpactedServices.Exists(q => q.Name.ToLower().Contains(impactedService.ToLower())));

            if (mostRecentImpactedServiceComm != null)
            {
                if (mostRecentImpactedServiceComm.Status == CommunicationStatus.Active)
                {
                    mostRecentImpactedServiceComm.IsAlert    = true;
                    mostRecentImpactedServiceComm.IsExpanded = true;
                    impactedServiceComm = mostRecentImpactedServiceComm;
                }
                else if (mostRecentImpactedServiceComm.Status == CommunicationStatus.Resolved)
                {
                    Communication rca = commsList.FirstOrDefault(p => (
                                                                     p.IncidentId == mostRecentImpactedServiceComm.IncidentId &&
                                                                     p.PublishedTime > mostRecentImpactedServiceComm.PublishedTime &&
                                                                     p.CommunicationId != mostRecentImpactedServiceComm.CommunicationId &&
                                                                     p.Title.ToUpper().Contains("RCA")));

                    if (rca != null && ((currentTimeUTC - rca.PublishedTime) <= _commAlertWindow))
                    {
                        rca.IsAlert = true;
                        // NOTE:- For now, resolved incidents will be collapsed by Default.
                        // Uncommenting below line would make resolved incidents expanded by default for certain timespan.
                        //rca.IsExpanded = ((currentTimeUTC - rca.PublishedTime) <= _commExpandedWindow);
                        impactedServiceComm = rca;
                    }
                    else if ((currentTimeUTC - mostRecentImpactedServiceComm.PublishedTime) <= _commAlertWindow)
                    {
                        mostRecentImpactedServiceComm.IsAlert = true;
                        // NOTE:- For now, resolved incidents will be collapsed by Default.
                        // Uncommenting below line would make resolved incidents expanded by default for certain timespan.
                        //mostRecentImpactedServiceComm.IsExpanded = ((currentTimeUTC - mostRecentImpactedServiceComm.PublishedTime) <= _commExpandedWindow);
                        impactedServiceComm = mostRecentImpactedServiceComm;
                    }
                }
            }

            return(commsList);
        }