public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "internal/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 List <SALsAReport.StatusLine>(); var salsaIncident = SALsA.LivesiteAutomation.TableStorage.ListAllEntity(); var incidents = ICM.GetIncidentsWithId(salsaIncident.Select(x => x.PartitionKey).ToList()); var report = new SALsAReport(); if (salsaIncident != null) { foreach (var run in salsaIncident) { if (run.SALsAState == SALsA.General.SALsAState.Ignore.ToString()) { continue; } SALsAReport.StatusLine line = new SALsAReport.StatusLine { IcmId = int.Parse(run.PartitionKey), SalsaIngestionTime = run.Timestamp.UtcDateTime, SalsaInternalLog = run.Log, SalsaLogLink = run.SALsALog, SalsaStatus = run.SALsAState }; if (incidents.ContainsKey(run.PartitionKey)) { line.IcmCreation = DateTime.Parse(incidents[run.PartitionKey].CreateDate); line.IcmOwningTeam = incidents[run.PartitionKey].OwningTeamId; line.IcmStatus = incidents[run.PartitionKey].Status; } report.Rows.Add(line); } } var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true, MustRevalidate = true }; watch.Stop(); report.Ellapsed = watch.Elapsed; response.Content = new StringContent(Utility.ObjectToJson(report, true), System.Text.Encoding.UTF8, "application/json"); return(response); }
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); }