private async Task <string> UpdateMessageWithSearchResultsAsync(string teamsMessageTemplate, AlertConfiguration alertConfiguration, AllOf condition, int conditionIndex)
        {
            IQueryResultFetcher queryResultFetcher = _queryResultFetcherFabric.CreateQueryResultFetcher(condition.LinkToSearchResultsApi);
            var result = await queryResultFetcher.FetchLogQueryResultsAsync(condition.LinkToSearchResultsApi, alertConfiguration.Context.ToString());

            foreach (var table in result.Tables)
            {
                var tableIndex = Array.IndexOf(result.Tables, table) + 1;

                foreach (var row in table.Rows)
                {
                    var rowIndex = Array.IndexOf(table.Rows, row) + 1;

                    var columns = table.Columns.Select(c => c.Name).ToArray();
                    foreach (var column in columns)
                    {
                        teamsMessageTemplate = teamsMessageTemplate
                                               .Replace($"[[$.data.alertContext.SearchResults[{conditionIndex}].Tables[{tableIndex}].Rows[{rowIndex}].{column}]]", row[Array.IndexOf(columns, column)], StringComparison.InvariantCultureIgnoreCase);
                    }
                }
            }

            return(teamsMessageTemplate);
        }
 public LogAnalyticsAlertProcessor(ILogger <LogAnalyticsAlertProcessor> log, ILogAnalyticsQueryResultFetcher queryResultFetcher)
 {
     _log = log;
     _queryResultFetcher = queryResultFetcher;
 }
Exemple #3
0
 public ApplicationInsightsAlertProcessor(ILogger <ApplicationInsightsAlertProcessor> log, IAppInsightsQueryResultFetcher queryResultFetcher)
 {
     _log = log;
     _queryResultFetcher = queryResultFetcher;
 }