Пример #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            Consoler.Logger = log;
            Consoler.Information("ExtractLogicAppFunction started");
            var authHeader = req.Headers.Single(x => x.Key == "Authorization");

            if (string.IsNullOrEmpty(authHeader.Value))
            {
                return(new UnauthorizedObjectResult("Invalid Token"));                                        // return HTTP 401 Unauthorized
            }
            var    token       = authHeader.Value.ToString().Replace("Bearer", "").Trim();
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            log.LogInformation(requestBody);

            var data = JsonConvert.DeserializeObject <ExtractLogicAppPayload>(requestBody);

            try
            {
                Extractor = new Extractor();
                Extractor.Authenticate(token);
                await Extractor.ExtractLogicApp(data.ResourceGroup, data.LogicAppName, data.FailedOnly, data.Export, data.StartDateTime, data.EndDateTime);
            }
            catch (Exception e)
            {
                log.LogError("ERROR ExtractLogicAppFunction", e);
                throw;
            }

            return(new OkObjectResult(Extractor.Data));
        }
Пример #2
0
        public static string Dump <T>(this T obj, string description = null, bool indent = false)
        {
            var content = JsonConvert.SerializeObject(obj, indent ? Formatting.Indented : Formatting.None,
                                                      new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            Consoler.Information($"{description} : {content}");
            return(content);
        }
Пример #3
0
        private static async Task Extract(int minutesAgo, int minutesToExtract = 1)
        {
            //  DateTime? startDate = DateTime.UtcNow.AddMinutes(minutesAgo);
            //  DateTime? endDate = DateTime.UtcNow.AddMinutes(minutesAgo+ minutesToExtract);

            DateTime?startDate = DateTime.Parse("16/04/2021  6:13:50 AM");
            DateTime?endDate   = DateTime.Parse("16/04/2021  6:15:03 AM");

            ////if (!startDate.HasValue) startDate = _extractor.Data.Select(x => x.StartTimeUtc).Max();
            Consoler.Information($"start {startDate}");
            Consoler.Information($"end {endDate}");

            //await _extractor.Run(startDate, endDate);

            var list = new List <string>()
            {
            };

            var tasks     = new List <Task>();
            var extractor = new Extractor();
            await extractor.Load();

            foreach (var la in list)
            {
                var item = extractor.LogicApps.SingleOrDefault(x => x.Value == la);
                await extractor.ExtractLogicApp(item.Key, item.Value, false, true, startDate, endDate);

                //var task = Task.Run(async () => {


                //    //while (startDate > endDate && rg.Value!=null)
                //    //{
                //    //    var dt = startDate.Value.AddMinutes(5);

                //    //    startDate = dt;
                //    //}
                //});

                //tasks.Add(task);
            }

            //  await Task.WhenAll(tasks);

            //await _extractor.Run(startDate, endDate);
            await Export(extractor);
        }
Пример #4
0
        public async System.Threading.Tasks.Task <string> ExtractLogicApp(string resourceGroupName, string logicAppName, bool failedOnly = false, bool export = true, DateTime?startDateTime = null, DateTime?endDateTime = null)
        {
            Consoler.Information($"*** Extract {logicAppName} ***");
            var runs = await Client.LogicAppService.WorkflowRunListAsync(AzureEnvVars.SubscriptionId, resourceGroupName, logicAppName, startTimeBegin : startDateTime, startTimeEnd : endDateTime);

            foreach (var r in runs.Value.Take(1000).Select(x => x.Name).Distinct())
            {
                //string runid = "08586013893585485487155006807CU03";
                var target = await Client.LogicAppService.WorkflowRunGetAsync(AzureEnvVars.SubscriptionId, resourceGroupName, logicAppName, r);

                IList <LogicAppWorkflowRunValue> workflowRunValues = target.Value;

                if (failedOnly)
                {
                    workflowRunValues = target.Value
                                        .Where(x => x.Properties.Status == "Failed")
                                        .ToList();
                    Consoler.Information($"filtering {target.Value.Count} for failed {workflowRunValues.Count}");
                }

                foreach (var value in workflowRunValues.Select(x => x.Name).Distinct())
                {
                    var act = await Client.LogicAppService.WorkflowRunGetActionAsync(AzureEnvVars.SubscriptionId, resourceGroupName, logicAppName, r, value);

                    var extract = new LogicAppExtract
                    {
                        LogicAppName  = logicAppName,
                        ResourceGroup = resourceGroupName,
                        Correlation   = act.Correlation,
                        RunId         = act.RunId,
                        ActionName    = act.ActionName,
                        Input         = act.InputContentData,
                        InputLink     = act.InputLink,
                        Output        = act.OutputContentData,
                        OutputLink    = act.OutputLink,
                        Status        = act.Status,
                        StatusCode    = act.StatusCode,
                        StartTimeUtc  = act.StartTimeUtc,
                        EndTimeUtc    = act.EndTimeUtc
                    };

                    var keys = new string[] { "" };

                    if (ContainsAny(keys, extract.Input))
                    {
                        Consoler.Success();
                    }

                    if (ContainsAny(keys, extract.Output))
                    {
                        Consoler.Success();
                    }

                    if (!Data.Any(x => x.RunId == extract.RunId && x.ActionName == extract.ActionName))
                    {
                        Data.Add(extract);
                        if (export)
                        {
                            // send to log analytics
                            await Client.LogAnalyticsDataCollector.Collect(extract);
                        }
                    }
                }
            }

            return(JsonConvert.SerializeObject(Data));
        }