Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public RedisCacheClient(AzureContext context)
 {
     _client = AzureSession.ClientFactory.CreateArmClient<RedisManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
     _insightsClient = AzureSession.ClientFactory.CreateClient<InsightsManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
     _resourceManagementClient = AzureSession.ClientFactory.CreateClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
 }