Beispiel #1
0
        public void Execute()
        {
            var authManager = new AuthManager();
            var credential  = authManager.GetAzureCredentials(ErrorReportArgs.TenantId, ErrorReportArgs.WebApiApplicationId, ErrorReportArgs.Secret);

            var logicAppManager = new LogicAppManager();

            logicAppManager.Credentials = credential;
            logicAppManager.Connect(ErrorReportArgs.SubscriptionId);

            var model = new Model();

            DownloadLogieAppsToModel(ErrorReportArgs, logicAppManager, model);

            //Download Logic App Runs for each Logic App
            foreach (var resourceGroupModel in model.ResourceGroups)
            {
                var options = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 1
                };
                Parallel.ForEach(resourceGroupModel.LogicApps, options, x => {
                    Console.WriteLine($"Downloading runs for Logic App: {x.Name}");
                    DownloadLogicAppRunToModel(ErrorReportArgs.StartDate, ErrorReportArgs.EndDate, logicAppManager, resourceGroupModel, x);

                    x.NoFailedRuns = x.FailedRuns.Count;
                });
            }

            ConvertToExcel(model, ErrorReportArgs.OutputExcelPath);
        }
Beispiel #2
0
        private void DownloadLogieAppsToModel(ErrorReportArgs errorReportArgs, LogicAppManager logicAppManager, Model model)
        {
            //Get all logic apps into model
            Console.WriteLine("Downloading logic app list");
            foreach (var resourceGroup in errorReportArgs.ResourceGroups)
            {
                var resourceGroupModel = new ResourceGroupModel();
                resourceGroupModel.Name = resourceGroup;
                model.ResourceGroups.Add(resourceGroupModel);

                var logicApps = logicAppManager.GetLogicAppList(resourceGroup);
                foreach (var logicApp in logicApps)
                {
                    var logicAppModel = new LogicAppModel();
                    logicAppModel.Id = logicApp.Id;
                    logicAppModel.LogicAppManagementObject = logicApp;
                    logicAppModel.Name = logicApp.Name;
                    logicAppModel.ResourceGroupName = resourceGroupModel.Name;

                    resourceGroupModel.LogicApps.Add(logicAppModel);
                }

                Console.WriteLine($"Completed downloading logic app list for resource group: {resourceGroup}");
            }
        }
Beispiel #3
0
        private void DownloadLogicAppRunToModel(DateTime startDate, DateTime endDate, LogicAppManager logicAppManager, ResourceGroupModel resourceGroupModel, LogicAppModel logicAppModel)
        {
            var runList = logicAppManager.GetLogicAppRuns(resourceGroupModel.Name, logicAppModel.LogicAppManagementObject, startDate, endDate);

            if (runList.Count > 0)
            {
                Console.WriteLine($"\t\tLogic app has failed runs.  Checking for actions");
            }

            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = 3
            };

            Parallel.ForEach(runList, options, run => {
                var runModel         = new LogicAppRunModel();
                runModel.Id          = run.Name;
                runModel.IsError     = false;
                runModel.Result      = run.Status;
                runModel.WorkflowRun = run;

                if (run.Status.ToLower() == "failed")
                {
                    Console.WriteLine($"\tLogic App Failed: {run.Name} : {run.StartTime.Value.ToString()}");

                    runModel.IsError = true;
                    logicAppModel.FailedRuns.Add(runModel);
                    logicAppModel.NoFailedRuns++;

                    var actionList = logicAppManager.GetLogicAppRunActionList(resourceGroupModel.Name, logicAppModel.LogicAppManagementObject, run);
                    Console.WriteLine($"\t\tChecking for actions {run.Name}");
                    foreach (var action in actionList)
                    {
                        if (action.Status.ToLower() == "failed")
                        {
                            var actionModel  = new FailedRunActionsModel();
                            actionModel.Name = action.Name;

                            var errorMessageJson = JsonConvert.SerializeObject(action.Error);
                            try
                            {
                                var errorDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(errorMessageJson);

                                if (errorDictionary != null)
                                {
                                    if (errorDictionary.ContainsKey("message"))
                                    {
                                        actionModel.Error = errorDictionary["message"];
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                //Swallow error incase error object not as expected
                            }

                            Console.WriteLine($"\t\tAction Failed: {action.Name}");

                            runModel.FailedActions.Add(actionModel);
                        }
                    }
                }
                else
                {
                    //Ignore for now
                }
            });
        }