/// <summary> /// Runs Smart Detector wizard logic at the beginning of a template wizard run. /// Replaces the template parameters according to the selected template type. /// </summary> /// <param name="automationObject">The automation object being used by the template wizard.</param> /// <param name="replacementsDictionary">The list of standard parameters to be replaced.</param> /// <param name="runKind">A run kind indicating the type of wizard run</param> /// <param name="customParams">The custom parameters with which to perform parameter replacement in the project.</param> public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { try { wizardForm = new WizardForm(); wizardForm.ShowDialog(); if (wizardForm.DialogResult == DialogResult.Cancel) { throw new WizardBackoutException(); } selectedTemplate = wizardForm.SelectedTemplate; replacementsDictionary.Add("$detectorName$", "MySmartDetector"); replacementsDictionary.Add("$alertName$", "MyAlert"); switch (selectedTemplate) { case SmartDetectorTemplateType.Empty: replacementsDictionary.Add("$resourceType$", "VirtualMachine"); break; case SmartDetectorTemplateType.LogAnalytics: replacementsDictionary.Add("$dataType$", "Log Analytics"); replacementsDictionary.Add("$query$", "Perf " + "| summarize Count=count() by bin(TimeGenerated, 1h) "); replacementsDictionary.Add("$tableName$", "Perf"); replacementsDictionary.Add("$resourceType$", "VirtualMachine"); break; case SmartDetectorTemplateType.ApplicationInsights: replacementsDictionary.Add("$dataType$", "Application Insights"); replacementsDictionary.Add("$query$", "traces " + "| summarize Count=count() by bin(timestamp, 1h) "); replacementsDictionary.Add("$tableName$", "traces"); replacementsDictionary.Add("$resourceType$", "ApplicationInsights"); break; case SmartDetectorTemplateType.Metric: replacementsDictionary.Add("$dataType$", "Metric"); replacementsDictionary.Add("$resourceType$", "AzureStorage"); break; } } catch (WizardBackoutException) { var directoryToDelete = replacementsDictionary["$destinationdirectory$"]; if (replacementsDictionary["$exclusiveproject$"] == "True") { directoryToDelete = replacementsDictionary["$solutiondirectory$"]; } if (Directory.Exists(directoryToDelete)) { Directory.Delete(directoryToDelete, true); } throw; } }
/// <summary> /// Occurs when the Metric template is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MetricButton_Click(object sender, EventArgs e) { this.SelectedTemplate = SmartDetectorTemplateType.Metric; templateInfo.Text = "A project template for creating Smart Detector that detects alerts based on a resource's metrics."; }
/// <summary> /// Occurs when the Log Analytics template is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LogAnalyticsButton_Click(object sender, EventArgs e) { this.SelectedTemplate = SmartDetectorTemplateType.LogAnalytics; templateInfo.Text = "A project template for creating Smart Detector that detects alerts based on the result of a Log Analytics query."; }
/// <summary> /// Occurs when the Application Insights template is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ApplicationInsightsButton_Click(object sender, EventArgs e) { this.SelectedTemplate = SmartDetectorTemplateType.ApplicationInsights; templateInfo.Text = "A project template for creating Smart Detector that detects alerts based on the result of an Application Insights query."; }
/// <summary> /// Occurs when the Empty template is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EmptyButton_Click(object sender, EventArgs e) { this.SelectedTemplate = SmartDetectorTemplateType.Empty; templateInfo.Text = "An empty project template for creating Smart Detector. This template does not have any content in it."; }