public async Task ViewLogCount(IDialogContext context, LuisResult result) { var entityDateTime = result.Entities.FirstOrDefault(x => x.Type == "datetime"); var entitySeverity = result.Entities.FirstOrDefault(x => x.Type == "severity"); var severity = ResolveSeverity(entitySeverity != null ? entitySeverity.Entity : string.Empty); if (entityDateTime != null && entityDateTime.Type == TimePeriodEntityPrefix) { TimeSpan span; TimeSpan?timeSpan = TimeSpan.TryParse(entityDateTime.Entity, out span) ? (TimeSpan?)span : null; var count = await AppInsightsService.GetNumberOfLogEntries(severity, timeSpan, entityDateTime.Resolution.FirstOrDefault().Value); var timeString = timeSpan == null?entityDateTime.Resolution.FirstOrDefault().Value : timeSpan.ToString(); await context.PostAsync($"There have been {count} {severity} log entries to the server in the requested timeframe ({timeString})"); context.Wait(MessageReceived); } else { var count = await AppInsightsService.GetNumberOfLogEntries(severity, null); await context.PostAsync($"There have been a total of {count} {severity} log entries to the server."); context.Wait(MessageReceived); } }
public async Task ViewTotalRequests(IDialogContext context, LuisResult result) { var entity = result.Entities.FirstOrDefault(x => x.Type.StartsWith(TimePeriodEntityPrefix)); if (entity != null && entity.Type.StartsWith(TimePeriodEntityPrefix)) { string customPeriod = entity.Resolution.FirstOrDefault().Value; DateTime dateTime; if (DateTime.TryParse(customPeriod, out dateTime)) { // A date was specified, not a duration, so transform to a time period customPeriod = $"{customPeriod}/{(dateTime + TimeSpan.FromDays(1)):yyyy-MM-dd}"; } var count = await AppInsightsService.GetNumberOfRequestsToServer(customPeriod); if (string.IsNullOrWhiteSpace(count)) { count = "0"; } await context.PostAsync($"There have been {count} requests to the server in the requested timeframe ({customPeriod})"); context.Wait(MessageReceived); } else { var count = await AppInsightsService.GetNumberOfRequestsToServer(); await context.PostAsync($"There have been a total of {count} requests to the server."); context.Wait(MessageReceived); } }
public ReportsController( DatasetStorageService datasetStorage, AppInsightsService appInsightsService) { _datasetStorage = datasetStorage; _appInsightsService = appInsightsService; }
public async Task FailedRequestExceptionQuery(IDialogContext context, LuisResult result) { //Retrieve Count if it exists int count = 10; EntityRecommendation entity = result.Entities.FirstOrDefault(x => x.Type == "builtin.number"); if (entity != null) { int.TryParse(entity.Resolution?.Values.FirstOrDefault(), out count); } string query = string.Empty; var dateEntity = result.Entities.FirstOrDefault(x => x.Type.StartsWith(TimePeriodEntityPrefix)); if (dateEntity != null) { switch (dateEntity.Type) { case "builtin.datetime.duration": string queryTimeInterval = DateConversionUtil.ToInsightsQueryTimeInterval(dateEntity.Resolution.FirstOrDefault().Value); query = await AppInsightsService.GetFailedRequestExceptions(queryTimeInterval, count); break; case "builtin.datetime.date": string startDateTime = dateEntity.Resolution.FirstOrDefault().Value; DateTime dateTime; if (DateTime.TryParse(startDateTime, out dateTime)) { query = await AppInsightsService.GetFailedRequestExceptions(dateTime, count); } break; } } else { query = await AppInsightsService.GetFailedRequestExceptions(count : count); } var message = context.MakeMessage(); message.Text = query; message.TextFormat = "markdown"; await context.PostAsync(message); context.Wait(MessageReceived); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Create the credential provider to be used with the Bot Framework Adapter. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); // Create the Bot Framework Adapter with error handling enabled. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.) services.AddSingleton <IStorage, MemoryStorage>(); // Create the User state. (Used in this bot's Dialog implementation.) services.AddSingleton <UserState>(); // Create the Conversation state. (Used by the Dialog system itself.) services.AddSingleton <ConversationState>(); // The Dialog that will be run by the bot. services.AddSingleton <MainDialog>(); //Aplication Insights AppInsightsService appInsights = new AppInsightsService(); appInsights.Name = ""; appInsights.TenantId = ""; appInsights.SubscriptionId = ""; appInsights.ResourceGroup = ""; appInsights.ServiceName = ""; appInsights.InstrumentationKey = ""; if (string.IsNullOrWhiteSpace(appInsights.InstrumentationKey)) { throw new InvalidOperationException("The Application Insights Instrumentation Key is required."); } var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey); TelemetryClient = new TelemetryClient(telemetryConfig) { InstrumentationKey = appInsights.InstrumentationKey, }; // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddTransient <IBot, DialogAndWelcomeBot <MainDialog> >(); }
/// <summary> /// Adds and configures services for Application Insights to the <see cref="IServiceCollection" />. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> which specifies the contract for a collection of service descriptors.</param> /// <param name="botConfiguration">Bot configuration that contains the Application Insights configuration information.</param> /// <param name="appInsightsServiceInstanceName">(OPTIONAL) Specifies a Application Insights instance name in the Bot configuration.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IServiceCollection AddBotApplicationInsights(this IServiceCollection services, BotConfiguration botConfiguration, string appInsightsServiceInstanceName = null) { if (botConfiguration == null) { throw new ArgumentNullException(nameof(botConfiguration)); } var appInsightsServices = botConfiguration.Services.OfType <AppInsightsService>(); AppInsightsService appInsightService = null; // Validate the bot file is correct. var instanceNameSpecified = appInsightsServiceInstanceName != null; if (instanceNameSpecified) { appInsightService = appInsightsServices.Where(ais => ais.Name == appInsightsServiceInstanceName).FirstOrDefault(); if (appInsightService == null) { throw new ArgumentException($"No Application Insights Service instance with the specified name \"{appInsightsServiceInstanceName}\" was found in the {nameof(BotConfiguration)}"); } } else { appInsightService = appInsightsServices.FirstOrDefault(); } CreateBotTelemetry(services); IBotTelemetryClient telemetryClient = null; if (appInsightService != null) { services.AddApplicationInsightsTelemetry(appInsightService.InstrumentationKey); telemetryClient = new BotTelemetryClient(new TelemetryClient()); } else { telemetryClient = NullBotTelemetryClient.Instance; } services.AddSingleton(telemetryClient); return(services); }
public async Task ViewDailyStats(IDialogContext context, LuisResult result) { var exceptionCount = await AppInsightsService.GetDailyExceptions(); var requestCount = await AppInsightsService.GetDailyRequests(); var cacheClearCount = await AppInsightsService.GetDailyCacheClearings(); await context.PostAsync("Your daily stats are:"); await context.PostAsync($"{exceptionCount} exceptions in the last 24 hours."); await context.PostAsync($"{requestCount} requests in the last 24 hours."); await context.PostAsync($"{cacheClearCount} Sitecore cache clears in the last 24 hours."); context.Wait(MessageReceived); }
public BotConfig(IConfiguration config) { Padlock = ""; Name = "AisBot"; Description = "Generated bot file for emulator reference"; CosmosStorage = new CosmosDbService(); config.Bind("botSettings:cosmosDb", CosmosStorage); Services.Add(CosmosStorage); QnAMaker = new QnAMakerService(); config.Bind("botSettings:qna", QnAMaker); Services.Add(QnAMaker); AppInsights = new AppInsightsService(); config.Bind("botSettings:appInsights", AppInsights); Services.Add(AppInsights); Secret = config["botSettings:secret"]; }
/// <summary> /// Initializes the Application Insights Query helper with appropriate metadata. /// </summary> /// <param name="botConfig">The BotConfiguration for the bot.</param> /// <param name="appInsightsInstance">[Optional] Identifies an Application Insights instance name to use within the Bot Configuration.</param> public ExportQueryHelper(BotConfiguration botConfig, string appInsightsInstance = null) { _botConfig = botConfig ?? throw new ArgumentNullException(nameof(botConfig)); if (!string.IsNullOrWhiteSpace(appInsightsInstance)) { _appInsights = (AppInsightsService)botConfig.Services.Find(x => x.Name == appInsightsInstance && x.Type == ServiceTypes.AppInsights) ?? throw new InvalidOperationException($"Application Insights `{appInsightsInstance}` not found in bot configuration."); } else { _appInsights = (AppInsightsService)botConfig.Services.Find(x => x.Type == ServiceTypes.AppInsights) ?? throw new InvalidOperationException("No Application Insights resource found in bot configuration."); } // Add AAD tenant ID only if it is a valid Guid Guid aadTenantGuid; if (!Guid.TryParse(_appInsights.TenantId, out aadTenantGuid)) { throw new InvalidOperationException("Application Insights tenant ID is invalid"); } }
public void EncryptWithEmptyPropertiesOK() { // all of these objects should have null properties, this should not cause secret to blow up var secret = Guid.NewGuid().ToString("n"); try { var generic = new GenericService(); generic.Configuration["test"] = string.Empty; generic.Encrypt(secret); generic.Decrypt(secret); } catch (Exception) { Assert.Fail("generic failed with empty values"); } try { var file = new FileService { Path = string.Empty, }; file.Encrypt(secret); file.Decrypt(secret); } catch (Exception) { Assert.Fail("file failed with empty values"); } try { var luis = new LuisService { SubscriptionKey = string.Empty, }; luis.Encrypt(secret); luis.Decrypt(secret); } catch (Exception) { Assert.Fail("luis failed with empty values"); } try { var dispatch = new DispatchService { SubscriptionKey = string.Empty, }; dispatch.Encrypt(secret); dispatch.Decrypt(secret); } catch (Exception) { Assert.Fail("dispatch failed with empty values"); } try { var insights = new AppInsightsService { InstrumentationKey = string.Empty, }; insights.Encrypt(secret); insights.Decrypt(secret); } catch (Exception) { Assert.Fail("insights failed with empty values"); } try { var bot = new BotService(); bot.Encrypt(secret); bot.Decrypt(secret); } catch (Exception) { Assert.Fail("bot failed with empty values"); } try { var cosmos = new CosmosDbService { Key = string.Empty, }; cosmos.Encrypt(secret); cosmos.Decrypt(secret); } catch (Exception) { Assert.Fail("cosmos failed with empty values"); } try { var qna = new QnAMakerService { SubscriptionKey = string.Empty, }; qna.Encrypt(secret); qna.Decrypt(secret); } catch (Exception) { Assert.Fail("qna failed with empty values"); } try { var blob = new BlobStorageService { ConnectionString = string.Empty, }; blob.Encrypt(secret); blob.Decrypt(secret); } catch (Exception) { Assert.Fail("blob failed with empty values"); } try { var endpoint = new EndpointService { AppPassword = string.Empty, }; endpoint.Encrypt(secret); endpoint.Decrypt(secret); } catch (Exception) { Assert.Fail("endpoint failed with empty values"); } }
public void EncryptWithNullPropertiesOK() { // all of these objects should have null properties, this should not cause secret to blow up var secret = Guid.NewGuid().ToString("n"); try { var generic = new GenericService(); generic.Encrypt(secret); generic.Decrypt(secret); } catch (Exception) { Assert.Fail("generic failed with empty values"); } try { var file = new FileService(); file.Encrypt(secret); file.Decrypt(secret); } catch (Exception) { Assert.Fail("file failed with empty values"); } try { var luis = new LuisService(); luis.Encrypt(secret); luis.Decrypt(secret); } catch (Exception) { Assert.Fail("luis failed with empty values"); } try { var dispatch = new DispatchService(); dispatch.Encrypt(secret); dispatch.Decrypt(secret); } catch (Exception) { Assert.Fail("dispatch failed with empty values"); } try { var insights = new AppInsightsService(); insights.Encrypt(secret); insights.Decrypt(secret); } catch (Exception) { Assert.Fail("insights failed with empty values"); } try { var bot = new BotService(); bot.Encrypt(secret); bot.Decrypt(secret); } catch (Exception) { Assert.Fail("bot failed with empty values"); } try { var cosmos = new CosmosDbService(); cosmos.Encrypt(secret); cosmos.Decrypt(secret); } catch (Exception) { Assert.Fail("cosmos failed with empty values"); } try { var qna = new QnAMakerService(); qna.Encrypt(secret); qna.Decrypt(secret); } catch (Exception) { Assert.Fail("qna failed with empty values"); } try { var blob = new BlobStorageService(); blob.Encrypt(secret); blob.Decrypt(secret); } catch (Exception) { Assert.Fail("blob failed with empty values"); } try { var endpoint = new EndpointService(); endpoint.Encrypt(secret); endpoint.Decrypt(secret); } catch (Exception) { Assert.Fail("endpoint failed with empty values"); } }