コード例 #1
0
ファイル: ICMStatus.cs プロジェクト: vaishkarthik/SALsA
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "status/{id:int}")] HttpRequestMessage req, int id,
            ILogger log, System.Security.Claims.ClaimsPrincipal claimsPrincipal)
        {
            if (Auth.CheckIdentity(req, log, claimsPrincipal, out HttpResponseMessage err) == false)
            {
                return(err);
            }
            ;

            var icm = TableStorage.ListAllEntity().Where(x => x.RowKey == id.ToString()).ToList();
            HttpResponseMessage response;

            if (icm.Count == 0)
            {
                log.LogInformation("No ICM found, will redirect to /api/status");
                FunctionUtility.AddRunToSALsA(id);
                response = req.CreateResponse(HttpStatusCode.TemporaryRedirect);
                response.Headers.Location = new Uri("/api/status", UriKind.Relative);
            }
            else if (icm.FirstOrDefault().Log == null)
            {
                log.LogInformation("ICM found, but no logs. Will return 404");
                response         = req.CreateResponse(HttpStatusCode.NotFound);
                response.Content = new StringContent(String.Format("<b>SALsA Logs not available.</b><br>Status : <b>{0}</b>",
                                                                   Utility.UrlToHml(icm.FirstOrDefault().SALsAState, icm.FirstOrDefault().SALsALog, 14)), System.Text.Encoding.UTF8, "text/html");
            }
            else
            {
                log.LogInformation("ICM found, logs found. Redirecting to logs");
                response = req.CreateResponse(HttpStatusCode.TemporaryRedirect);
                response.Headers.Location = new Uri(icm.FirstOrDefault().Log, UriKind.Absolute);
            }

            response.Headers.CacheControl = new CacheControlHeaderValue
            {
                NoCache        = true,
                NoStore        = true,
                MustRevalidate = true
            };
            return(response);
        }
コード例 #2
0
ファイル: SALsAStatus.cs プロジェクト: vaishkarthik/SALsA
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "status")] HttpRequestMessage req,
            ILogger log, System.Security.Claims.ClaimsPrincipal claimsPrincipal)
        {
            if (Auth.CheckIdentity(req, log, claimsPrincipal, out HttpResponseMessage err) == false)
            {
                return(err);
            }
            ;
            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();

            var icmsDic = new Dictionary <int, StatusLine>();

            var icms      = SALsA.LivesiteAutomation.TableStorage.ListAllEntity();
            var incidents = ICM.GetIncidentsWithId(icms.Select(x => x.PartitionKey).ToList());
            var lst       = new List <string[]>();

            lst.Add(StatusLine.Headers);
            if (icms != null)
            {
                foreach (var run in icms)
                {
                    if (run.SALsAState == SALsA.General.SALsAState.Ignore.ToString())
                    {
                        continue;
                    }

                    StatusLine tuple;
                    if (icmsDic.ContainsKey(int.Parse(run.PartitionKey)))
                    {
                        tuple = icmsDic[int.Parse(run.PartitionKey)];
                    }
                    else
                    {
                        try
                        {
                            var currentIcm = incidents[run.PartitionKey];
                            tuple = new StatusLine(currentIcm.Id, FunctionUtility.ColorICMStatus(currentIcm.OwningTeamId, currentIcm.Status), DateTime.Parse(currentIcm.CreateDate));
                        }
                        catch
                        {
                            tuple = new StatusLine();
                        }
                    }

                    var status  = run.SALsAState;
                    var logPath = run.Log;
                    if (run.Log != null && run.Log.StartsWith("http"))
                    {
                        if (tuple.IcmStatus == "Unknown" && tuple.IcmCreation.HasValue == false)
                        {
                            run.SALsAState  = SALsAState.ICMNotAccessible.ToString();
                            tuple.IcmStatus = FunctionUtility.ColorICMStatus("Request for assistance", Color.Blue);
                            TableStorage.AppendEntity(tuple.IcmId, SALsAState.ICMNotAccessible);
                        }
                    }
                    else
                    {
                        logPath = run.SALsAState == SALsAState.Running.ToString() || run.SALsAState == SALsAState.Queued.ToString() ? "Wait..." : "Unavailable";
                    }
                    status = Utility.UrlToHml(run.SALsAState, run.SALsALog, 20);
                    tuple.Update(run.PartitionKey, status, logPath, run.Timestamp.UtcDateTime);
                    icmsDic[int.Parse(run.PartitionKey)] = tuple;
                }
            }
            var values = icmsDic.Values.ToList();

            values.Sort((y, x) => {
                int ret = DateTime.Compare(x._SalsaInternalIngestion.HasValue ? x._SalsaInternalIngestion.Value : new DateTime(0),
                                           y._SalsaInternalIngestion.HasValue ? y._SalsaInternalIngestion.Value : new DateTime(0));
                return(ret != 0 ? ret : DateTime.Compare(x.IcmCreation.HasValue ? x.IcmCreation.Value : new DateTime(0),
                                                         y.IcmCreation.HasValue ? y.IcmCreation.Value : new DateTime(0)));
            });
            foreach (var value in values)
            {
                if (value.SalsaLogIngestion == "N/A")
                {
                    try
                    {
                        FunctionUtility.AddRunToSALsA(int.Parse(value._icm));
                    }
                    catch { };
                }
            }
            lst.AddRange(values.Select(x => x.ToArray()).ToList());

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Headers.CacheControl = new CacheControlHeaderValue
            {
                NoCache        = true,
                NoStore        = true,
                MustRevalidate = true
            };
            watch.Stop();
            string result = Utility.List2DToHTML(lst, true) + String.Format("<p style=\"text-align: right\">Page generated at : {0}Z (in {1} seconds)</p>", DateTime.UtcNow.ToString("s"), watch.Elapsed.TotalSeconds);

            response.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/html");

            return(response);
        }