public void CreateAutoscalePolicies(ICloudAppConfig appConfig, string resourceUrl, string appName, string resGroupName) { Logger.Info("CreateAutoscalePolicies - Creating"); var autoscaleconfig = (ICloudAppConfigAutoScaling)appConfig; var emailForScaling = autoscaleconfig.AutoScaleNotificationMailAddress; var capacity = CreateScaleCapacity(); var rules = CreateRulesForAutoScaling(resourceUrl); var profiles = CreateAutoScaleProfile(capacity, rules); var notifications = CreateAutoscaleNotifications(emailForScaling); var autoscalesettingName = autoscaleconfig.AutoScaleSettingName; var asr = new AutoscaleSettingResource { Name = autoscalesettingName, AutoscaleSettingResourceName = autoscalesettingName, TargetResourceUri = resourceUrl, Enabled = true, Profiles = profiles, Notifications = notifications, Location = autoscaleconfig.AutoScaleResourceLocation }; using (var imc = new InsightsManagementClient(appConfig.Creds) { SubscriptionId = appConfig.SubscriptionId }) { imc.AutoscaleSettings.CreateOrUpdate(resGroupName, autoscalesettingName, asr); } Logger.Info("CreateAutoscalePolicies - Created"); }
public void LogProfiles_ListTest() { var logProfile = CreateLogProfile(); var expectedResponse = new LogProfileListResponse { LogProfileCollection = new LogProfileCollection { Value = new List <LogProfileResource> { new LogProfileResource() { Id = ResourceId, Name = DefaultName, Properties = logProfile } } } }; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expectedResponse.LogProfileCollection.ToJson()), }; var handler = new RecordedDelegatingHandler(response); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); LogProfileListResponse actualResponse = customClient.LogProfilesOperations.List(); Assert.Equal(expectedResponse.LogProfileCollection.Value.Count, actualResponse.LogProfileCollection.Value.Count); AreEqual( expectedResponse.LogProfileCollection.Value[0].Properties, actualResponse.LogProfileCollection.Value[0].Properties); }
public void Autoscale_GetSetting() { var expectedAutoscaleSetting = CreateAutoscaleSetting(ResourceUri, "CpuPercentage", string.Empty); var expectedAutoscaleSettingGetResponse = new AutoscaleSettingGetResponse() { Id = ResourceUri, Location = "East US", Tags = new Dictionary <string, string> { { "tag1", "value1" } }, Name = expectedAutoscaleSetting.Name, Properties = expectedAutoscaleSetting, RequestId = "request id", StatusCode = HttpStatusCode.OK }; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expectedAutoscaleSettingGetResponse.ToJson()), }; var handler = new RecordedDelegatingHandler(response); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); AutoscaleSettingGetResponse actualResponse = customClient.AutoscaleOperations.GetSetting("resourceGroup1", "setting1"); AreEqual(expectedAutoscaleSettingGetResponse.Properties, actualResponse.Properties); }
public void LogProfiles_DeleteTest() { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(string.Empty) }; var handler = new RecordedDelegatingHandler(response); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); customClient.LogProfiles.Delete(logProfileName: DefaultName); }
private static void CreateOrUpdateAlert( InsightsManagementClient insightsClient, string resourceGroupName, string insightsResourceUri, string webTestUri) { string webTestName = GetNameFromUri(webTestUri); string alertName = string.Format("{0}-alert", webTestName); var parameters = new RuleCreateOrUpdateParameters { Location = "East US", Properties = new Rule() { Name = alertName, Description = string.Empty, IsEnabled = true, LastUpdatedTime = DateTime.UtcNow, Action = new RuleEmailAction { SendToServiceOwners = true }, Condition = new LocationThresholdRuleCondition { DataSource = new RuleMetricDataSource { MetricName = "GSMT_AvRaW", ResourceUri = webTestUri }, FailedLocationCount = 1, WindowSize = TimeSpan.FromMinutes(5) }, }, Tags = { { string.Format("hidden-link:{0}", insightsResourceUri), "Resource" }, { string.Format("hidden-link:{0}", webTestUri), "Resource" } } }; var alertCreateOrUpdateResult = insightsClient.AlertOperations.CreateOrUpdateRuleAsync( resourceGroupName, parameters).Result; if (alertCreateOrUpdateResult.StatusCode != HttpStatusCode.Created && alertCreateOrUpdateResult.StatusCode != HttpStatusCode.OK) { throw new InvalidOperationException( string.Format("Unable to create resource '{0}' (HTTP Status Code: {1}).", insightsResourceUri, alertCreateOrUpdateResult.StatusCode)); } }
protected InsightsManagementClient GetInsightsManagementClient(RecordedDelegatingHandler handler) { handler.IsPassThrough = false; var tokenProvider = new StringTokenProvider("granted", "SimpleString"); var id = Guid.NewGuid().ToString(); var token = new TokenCredentials(tokenProvider: tokenProvider, tenantId: id, callerId: id); var client = new InsightsManagementClient(token, handler); token.InitializeServiceClient(client); client.SubscriptionId = id; return(client); }
public AlertRuleResource CreateAlertRule(IResourceGroup resgrp, string targetResUriWebSite) { using (var imc = new InsightsManagementClient(_appconfig.Creds) { SubscriptionId = _appconfig.SubscriptionId }) { _logger.Info("CreateAlertRule - Creating"); var alertRuleRes = CreateAlertRuleFor500Errors(targetResUriWebSite, resgrp); var x = imc.AlertRules.CreateOrUpdate(resgrp.Name, alertRuleRes.Name, alertRuleRes); _logger.Info("CreateAlertRule - Created"); return(x); } }
public void CreateOrUpdateSettingTest() { var handler = new RecordedDelegatingHandler(); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); AutoscaleSettingCreateOrUpdateParameters parameters = new AutoscaleSettingCreateOrUpdateParameters { Properties = CreateAutoscaleSetting(ResourceUri, "CpuPercentage", string.Empty), Location = "East US", Tags = new Dictionary <string, string> { { "tag1", "value1" } } }; customClient.AutoscaleOperations.CreateOrUpdateSetting("resourceGroup1", "setting1", parameters); var actualResponse = JsonExtensions.FromJson <AutoscaleSettingCreateOrUpdateParameters>(handler.Request); AreEqual(parameters.Properties, actualResponse.Properties); }
public void LogProfiles_PutTest() { var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(string.Empty), }; var handler = new RecordedDelegatingHandler(response); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); var parameters = new ServiceDiagnosticSettingsPutParameters { Properties = CreateDiagnosticSettings() }; customClient.ServiceDiagnosticSettingsOperations.Put(ResourceUri, parameters); var actualResponse = JsonExtensions.FromJson <ServiceDiagnosticSettingsPutParameters>(handler.Request); AreEqual(parameters.Properties, actualResponse.Properties); }
public void LogProfiles_CreateOrUpdateTest() { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(string.Empty) }; var handler = new RecordedDelegatingHandler(response); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); var parameters = new LogProfileCreatOrUpdateParameters { Properties = CreateLogProfile() }; customClient.LogProfilesOperations.CreateOrUpdate(DefaultName, parameters); var actualRequest = JsonExtensions.FromJson <LogProfileCreatOrUpdateParameters>(handler.Request); AreEqual(parameters.Properties, actualRequest.Properties); }
public void LogProfiles_GetTest() { var diagnosticSettings = CreateDiagnosticSettings(); var expectedResponse = new ServiceDiagnosticSettingsGetResponse() { Name = "service", Properties = diagnosticSettings, RequestId = "request id", StatusCode = HttpStatusCode.OK }; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expectedResponse.ToJson()), }; var handler = new RecordedDelegatingHandler(response); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); ServiceDiagnosticSettingsGetResponse actualResponse = customClient.ServiceDiagnosticSettingsOperations.Get(ResourceUri); AreEqual(expectedResponse.Properties, actualResponse.Properties); }
static void Main(string[] args) { string resourceGroupName = "<YOUR AZURE RESOURCE GROUP NAME>"; string streamAnalyticsJobName = "<YOUR STREAM ANALYTICS JOB NAME>"; // Get authentication token TokenCloudCredentials aadTokenCredentials = new TokenCloudCredentials( ConfigurationManager.AppSettings["SubscriptionId"], GetAuthorizationHeader()); Uri resourceManagerUri = new Uri(ConfigurationManager.AppSettings["ResourceManagerEndpoint"]); // Create Stream Analytics and Insights management client StreamAnalyticsManagementClient streamAnalyticsClient = new StreamAnalyticsManagementClient(aadTokenCredentials, resourceManagerUri); InsightsManagementClient insightsClient = new InsightsManagementClient(aadTokenCredentials, resourceManagerUri); // Get an existing Stream Analytics job JobGetParameters jobGetParameters = new JobGetParameters() { PropertiesToExpand = "inputs,transformation,outputs" }; JobGetResponse jobGetResponse = streamAnalyticsClient.StreamingJobs.Get(resourceGroupName, streamAnalyticsJobName, jobGetParameters); // Enable monitoring ServiceDiagnosticSettingsPutParameters insightPutParameters = new ServiceDiagnosticSettingsPutParameters() { Properties = new ServiceDiagnosticSettings() { StorageAccountName = "<YOUR STORAGE ACCOUNT NAME>" } }; InsightsClient.ServiceDiagnosticSettingsOperations.Put(jobGetResponse.Job.Id, insightPutParameters); }
public void ItShouldCreateOrUpdateResources() { const string resourceGroupName = "AppInsigtsResourceGroup"; const string insightsResourceName = "AppInsightsResource"; const string webTestName = "YahooPingTest"; const string webTestUrl = "http://www.yahoo.com"; const string location = "centralus"; var credentials = GetCloudCredentials(); var resourceClient = new ResourceManagementClient(credentials); var registrationResult = resourceClient.Providers.RegisterAsync("microsoft.insights").Result; var insightsClient = new InsightsManagementClient(credentials); var insightsResource = CreateOrUpdateInsightsResource( resourceClient, resourceGroupName, insightsResourceName, location); var webTest = CreateOrUpdateWebTest( resourceClient, resourceGroupName, insightsResource.Id, webTestName, webTestUrl, location); CreateOrUpdateAlert( insightsClient, resourceGroupName, insightsResource.Id, webTest.Id); Assert.IsNotNull(insightsResource); Assert.IsNotNull(webTest); }
public void LogProfiles_GetTest() { var logProfile = CreateLogProfile(); var expectedResponse = new LogProfileGetResponse() { Id = ResourceId, Name = DefaultName, Properties = logProfile, RequestId = "request id", StatusCode = HttpStatusCode.OK }; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(expectedResponse.ToJson()), }; var handler = new RecordedDelegatingHandler(response); InsightsManagementClient customClient = this.GetInsightsManagementClient(handler); LogProfileGetResponse actualResponse = customClient.LogProfilesOperations.Get(DefaultName); AreEqual(expectedResponse.Properties, actualResponse.Properties); }
public RedisCacheClient(IAzureContext context) { _client = AzureSession.Instance.ClientFactory.CreateArmClient <RedisManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager); _insightsClient = AzureSession.Instance.ClientFactory.CreateClient <InsightsManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager); _resourceManagementClient = AzureSession.Instance.ClientFactory.CreateArmClient <ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager); }
private static void CreateAlertRule(string authorizationToken) { string token = GetAuthorizationHeader(); TokenCloudCredentials credentials = new TokenCloudCredentials(subscriptionId, token); InsightsManagementClient client = new InsightsManagementClient(credentials, new Uri(ServiceUrl)); RuleCreateOrUpdateParameters parameters = new RuleCreateOrUpdateParameters(); List <RuleAction> actions = new List <RuleAction>(); //The new RuleWebhookAction has two properties - the uri and a property bag, which can be key value pairs //Lets create some key-value pairs to be added as properties for this webhook Dictionary <string, string> properties = new Dictionary <string, string>(); properties.Add("Hello1", "World1!"); properties.Add("json_stuff", "{\"type\":\"critical\", \"color\":\"red\"}'"); properties.Add("customId", "wd39ue9832ue9iuhd9iuewhd9edh"); properties.Add("send_emails_to", "*****@*****.**"); // NOTE: you can add up to 5 webhooks for an alert programmatically // if you configure multiple webhooks programmtically, you can only view/edit the 1st one via the Azure Portal UI // We will add the ability to configure multiple webhooks via the portal soon // my runscope uri actions.Add(new RuleWebhookAction() { ServiceUri = "your_runscope_uri", Properties = properties }); //pager_duty uri actions.Add(new RuleWebhookAction() { ServiceUri = "your_pagerduty_uri", Properties = properties }); parameters.Properties = new Rule() { Name = "Alert_webhook_demo1", Action = new RuleEmailAction() { CustomEmails = new List <string>() { "*****@*****.**" } }, IsEnabled = true, Actions = actions, Condition = new ThresholdRuleCondition() { DataSource = new RuleMetricDataSource() { MetricName = "\\Memory\\Available Bytes", ResourceUri = "your_resource_id" }, Operator = ConditionOperator.GreaterThan, Threshold = 1.0, TimeAggregation = TimeAggregationOperator.Average, WindowSize = TimeSpan.FromMinutes(5), } }; parameters.Location = "location_for_your_alert_rule"; // e.g "eastus" var response = client.AlertOperations.CreateOrUpdateRule("your_resoureGroupeName", parameters); Console.WriteLine("Alert created with a webhook!"); }