Exemple #1
0
        public void StorageInsightCreateFailsWithoutWorkspace()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourceClient = TestHelper.GetResourceManagementClient(this, context);
                var client         = TestHelper.GetOperationalInsightsManagementClient(this, context);

                string resourceGroupName = TestUtilities.GenerateName("OIAutoRest");
                var    resourceGroup     = TestHelper.CreateResourceGroup(resourceGroupName, resourceClient);

                // Create a storage insight on a non-existent workspace
                string storageInsightName = TestUtilities.GenerateName("AzTestSI");
                string storageAccountName = TestUtilities.GenerateName("AzTestFakeSA");
                string workspaceName      = TestUtilities.GenerateName("AzTest");
                var    storageInsight     = new StorageInsight
                {
                    StorageAccount =
                        new StorageAccount
                    {
                        Id  = string.Format(StorageAccountIdFormat, client.SubscriptionId, resourceGroupName, storageAccountName),
                        Key = "1234"
                    }
                };

                TestHelper.VerifyCloudException(HttpStatusCode.NotFound,
                                                () => client.StorageInsights.CreateOrUpdate(resourceGroupName, workspaceName, storageInsightName, storageInsight));
            }
        }
Exemple #2
0
        public virtual StorageInsight CreateOrUpdateStorageInsight(
            string resourceGroupName,
            string workspaceName,
            string name,
            string storageAccountResourceId,
            string storageAccountKey,
            List <string> tables,
            List <string> containers)
        {
            StorageInsight properties = new StorageInsight {
                Containers = containers, Tables = tables
            };

            if (!string.IsNullOrWhiteSpace(storageAccountResourceId) || !string.IsNullOrWhiteSpace(storageAccountKey))
            {
                properties.StorageAccount = new StorageAccount {
                    Id = storageAccountResourceId, Key = storageAccountKey
                };
            }

            var response = OperationalInsightsManagementClient.StorageInsights.CreateOrUpdate(
                resourceGroupName,
                workspaceName,
                name,
                properties);

            return(response);
        }
Exemple #3
0
        /// <summary>
        /// Validates a storage insight matches the expected properties.  Throws assertion exceptions if validation fails.
        /// </summary>
        /// <param name="expected">Expected storage insight</param>
        /// <param name="actual">Actual storage insight</param>
        internal static void ValidateStorageInsight(StorageInsight expected, StorageInsight actual)
        {
            Assert.NotNull(actual);
            Assert.NotNull(actual.Id);
            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(StorageInsightResourceType, actual.Type);
            if (expected.Tags != null)
            {
                Assert.Equal(expected.Tags.Count, actual.Tags.Count);
                foreach (var tag in expected.Tags)
                {
                    Assert.True(actual.Tags.Contains(tag));
                }
            }
            else
            {
                Assert.Null(actual.Tags);
            }

            Assert.NotNull(actual.Properties);
            Assert.Equal("OK", actual.Properties.Status.State);
            Assert.Equal(expected.Properties.StorageAccount.Id, actual.Properties.StorageAccount.Id);
            Assert.Null(actual.Properties.StorageAccount.Key);

            if (expected.Properties.Containers != null)
            {
                Assert.Equal(expected.Properties.Containers.Count, actual.Properties.Containers.Count);
                foreach (var container in expected.Properties.Containers)
                {
                    Assert.Contains(container, actual.Properties.Containers);
                }
            }
            else
            {
                Assert.Empty(actual.Properties.Containers);
            }

            if (expected.Properties.Tables != null)
            {
                Assert.Equal(expected.Properties.Tables.Count, actual.Properties.Tables.Count);

                foreach (var table in expected.Properties.Tables)
                {
                    Assert.Contains(table, actual.Properties.Tables);
                }
            }
            else
            {
                Assert.Empty(actual.Properties.Tables);
            }
        }
Exemple #4
0
        public virtual PSStorageInsight UpdatePSStorageInsight(UpdatePSStorageInsightParameters parameters)
        {
            // Get the existing storage insight
            StorageInsight storageInsight = OperationalInsightsManagementClient.StorageInsights.Get(parameters.ResourceGroupName, parameters.WorkspaceName, parameters.Name);

            // Execute the update
            StorageInsight updatedStorageInsight = CreateOrUpdateStorageInsight(
                parameters.ResourceGroupName,
                parameters.WorkspaceName,
                storageInsight.Name,
                storageInsight.StorageAccount.Id,
                string.IsNullOrWhiteSpace(parameters.StorageAccountKey) ? storageInsight.StorageAccount.Key : parameters.StorageAccountKey,
                parameters.Tables ?? storageInsight.Tables.ToList(),
                parameters.Containers ?? storageInsight.Containers.ToList());

            return(new PSStorageInsight(updatedStorageInsight, parameters.ResourceGroupName, parameters.WorkspaceName));
        }
Exemple #5
0
        public virtual PSStorageInsight UpdatePSStorageInsight(PSStorageInsightParameters parameters)
        {
            // Get the existing storage insight
            PSStorageInsight storageInsight;

            try
            {
                storageInsight = GetStorageInsight(parameters.ResourceGroupName, parameters.WorkspaceName, parameters.Name);
            }
            catch (RestException)
            {
                throw new PSArgumentException($"StorageInsight {parameters.Name} under workspace {parameters.WorkspaceName} does not existed");
            }

            // Execute the update
            StorageInsight updatedStorageInsight = CreateOrUpdateStorageInsight(parameters);

            return(new PSStorageInsight(updatedStorageInsight, parameters.ResourceGroupName, parameters.WorkspaceName));
        }
Exemple #6
0
        public PSStorageInsight(StorageInsight storageInsight, string resourceGroupName, string workspaceName)
        {
            if (storageInsight == null)
            {
                throw new ArgumentNullException("storageInsight");
            }

            this.ResourceGroupName = resourceGroupName;
            this.WorkspaceName     = workspaceName;
            this.Name       = storageInsight.Name;
            this.ResourceId = storageInsight.Id;

            if (storageInsight.Properties != null)
            {
                this.StorageAccountResourceId = storageInsight.Properties.StorageAccount != null ? storageInsight.Properties.StorageAccount.Id : null;
                this.Tables     = storageInsight.Properties.Tables.ToList();
                this.Containers = storageInsight.Properties.Containers.ToList();
                this.State      = storageInsight.Properties.Status != null ? storageInsight.Properties.Status.State : null;
            }
        }
        public PSStorageInsight(StorageInsight storageInsight, string resourceGroupName, string workspaceName)
        {
            if (storageInsight == null)
            {
                throw new ArgumentNullException("storageInsight");
            }

            this.ResourceGroupName = resourceGroupName;
            this.WorkspaceName     = workspaceName;
            this.Name       = storageInsight.Name;
            this.ResourceId = storageInsight.Id;
            this.Type       = storageInsight.Type;
            this.StorageAccountResourceId = storageInsight.StorageAccount?.Id;
            this.StorageAccountKey        = storageInsight.StorageAccount?.Key;
            this.Tables           = storageInsight.Tables.ToList();
            this.Containers       = storageInsight.Containers.ToList();
            this.State            = storageInsight.Status?.State;
            this.StateDescription = storageInsight.Status?.Description;
            this.ETag             = storageInsight.ETag;
            this.Tags             = storageInsight.Tags == null ? null : new Hashtable((IDictionary)storageInsight.Tags);
        }
Exemple #8
0
        public virtual StorageInsight CreateOrUpdateStorageInsight(PSStorageInsightParameters parameters)
        {
            StorageInsight storageInsightsToUpdate = new StorageInsight {
                Containers = parameters.Containers,
                Tables     = parameters.Tables,
                ETag       = parameters.Etag,
                Tags       = parameters.Tags?.Cast <DictionaryEntry>().ToDictionary(kv => (string)kv.Key, kv => (string)kv.Value)
            };

            if (!string.IsNullOrWhiteSpace(parameters.StorageAccountResourceId) && !string.IsNullOrWhiteSpace(parameters.StorageAccountKey))
            {
                storageInsightsToUpdate.StorageAccount = new StorageAccount {
                    Id = parameters.StorageAccountResourceId, Key = parameters.StorageAccountKey
                };
            }

            return(OperationalInsightsManagementClient.StorageInsightConfigs.CreateOrUpdate(
                       parameters.ResourceGroupName,
                       parameters.WorkspaceName,
                       parameters.Name,
                       storageInsightsToUpdate));
        }
 /// <summary>
 /// Create or update a storage insight.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group to get. The name is case insensitive.
 /// </param>
 /// <param name='workspaceName'>
 /// Log Analytics Workspace name that will contain the storageInsightsConfigs
 /// resource
 /// </param>
 /// <param name='storageInsightName'>
 /// Name of the storageInsightsConfigs resource
 /// </param>
 /// <param name='parameters'>
 /// The parameters required to create or update a storage insight.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task <StorageInsight> CreateOrUpdateAsync(this IStorageInsightsOperations operations, string resourceGroupName, string workspaceName, string storageInsightName, StorageInsight parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, storageInsightName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Create or update a storage insight.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group to get. The name is case insensitive.
 /// </param>
 /// <param name='workspaceName'>
 /// Log Analytics Workspace name that will contain the storageInsightsConfigs
 /// resource
 /// </param>
 /// <param name='storageInsightName'>
 /// Name of the storageInsightsConfigs resource
 /// </param>
 /// <param name='parameters'>
 /// The parameters required to create or update a storage insight.
 /// </param>
 public static StorageInsight CreateOrUpdate(this IStorageInsightsOperations operations, string resourceGroupName, string workspaceName, string storageInsightName, StorageInsight parameters)
 {
     return(System.Threading.Tasks.Task.Factory.StartNew(s => ((IStorageInsightsOperations)s).CreateOrUpdateAsync(resourceGroupName, workspaceName, storageInsightName, parameters), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemple #11
0
        public void CanCreateUpdateDeleteStorageInsight()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourceClient = TestHelper.GetResourceManagementClient(this, context);
                var client         = TestHelper.GetOperationalInsightsManagementClient(this, context);

                string resourceGroupName = TestUtilities.GenerateName("OIAutoRest");
                var    resourceGroup     = TestHelper.CreateResourceGroup(resourceGroupName, resourceClient, "East US");

                // Create a workspace that will house the storage insights
                string workspaceName = TestUtilities.GenerateName("AzTest");

                var workspace = new Workspace()
                {
                    Location = resourceGroup.Location,
                    Sku      = new Sku(SkuNameEnum.Standard)
                };

                var workspaceResponse = client.Workspaces.CreateOrUpdate(
                    resourceGroupName,
                    workspaceName,
                    workspace);

                // Create a storage insight
                string storageInsightName = TestUtilities.GenerateName("AzTestSI");
                string storageAccountName = TestUtilities.GenerateName("AzTestFakeSA");

                var storageInsight = new StorageInsight
                {
                    Tables         = new[] { "WADWindowsEventLogsTable", "LinuxSyslogVer2v0" },
                    Containers     = new[] { "wad-iis-logfiles" },
                    StorageAccount =
                        new StorageAccount
                    {
                        Id  = string.Format(StorageAccountIdFormat, client.SubscriptionId, resourceGroupName, storageAccountName),
                        Key = "1234"
                    }
                };

                var createResponse = client.StorageInsights.CreateOrUpdate(resourceGroupName, workspaceName, storageInsightName, storageInsight);
                TestHelper.ValidateStorageInsight(storageInsight, createResponse);

                // Get the storage insight
                var getResponse = client.StorageInsights.Get(resourceGroupName, workspaceName, storageInsightName);
                TestHelper.ValidateStorageInsight(storageInsight, getResponse);

                // Create a second storage insight for list testing
                var storageInsightNameTwo = TestUtilities.GenerateName("AzTestSI");
                var storageInsightTwo     = new StorageInsight
                {
                    Tables         = new[] { "WADWindowsEventLogsTable", "LinuxSyslogVer2v0" },
                    Containers     = null,
                    StorageAccount =
                        new StorageAccount
                    {
                        Id  = string.Format(StorageAccountIdFormat, client.SubscriptionId, resourceGroupName, storageAccountName),
                        Key = "1234"
                    }
                };

                createResponse = client.StorageInsights.CreateOrUpdate(resourceGroupName, workspaceName, storageInsightNameTwo, storageInsightTwo);
                TestHelper.ValidateStorageInsight(storageInsightTwo, createResponse);

                // List the storage insights in the workspace
                var listResponse = client.StorageInsights.ListByWorkspace(resourceGroupName, workspaceName);
                Assert.Equal(2, listResponse.Count());
                Assert.Null(listResponse.NextPageLink);
                Assert.Single(listResponse.Where(w => w.Name.Equals(storageInsightName, StringComparison.OrdinalIgnoreCase)));
                Assert.Single(listResponse.Where(w => w.Name.Equals(storageInsightNameTwo, StringComparison.OrdinalIgnoreCase)));

                // Perform an update on one of the storage insights
                createResponse.StorageAccount.Key = "9876";
                createResponse.Tables             = new[] { "WADWindowsEventLogsTable" };
                createResponse.Containers         = new[] { "wad-iis-logfiles" };

                //var updateResponse = client.StorageInsights.CreateOrUpdate(resourceGroupName, workspaceName, storageInsightNameTwo, storageInsightTwo);
                var updateResponse = client.StorageInsights.CreateOrUpdate(resourceGroupName, workspaceName, storageInsightNameTwo, createResponse);

                storageInsightTwo.StorageAccount.Key = "9876";
                storageInsightTwo.Tables             = new[] { "WADWindowsEventLogsTable" };
                storageInsightTwo.Containers         = new[] { "wad-iis-logfiles" };
                TestHelper.ValidateStorageInsight(storageInsightTwo, updateResponse);

                // Delete a storage insight
                client.StorageInsights.Delete(resourceGroupName, workspaceName, storageInsightName);

                // Verify the storageinsight is gone
                TestHelper.VerifyCloudException(HttpStatusCode.NotFound, () => client.StorageInsights.Get(resourceGroupName, workspaceName, storageInsightName));
            }
        }
Exemple #12
0
 /// <summary>
 /// Create or update a storage insight.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group. The name is case insensitive.
 /// </param>
 /// <param name='workspaceName'>
 /// The name of the workspace.
 /// </param>
 /// <param name='storageInsightName'>
 /// Name of the storageInsightsConfigs resource
 /// </param>
 /// <param name='parameters'>
 /// The parameters required to create or update a storage insight.
 /// </param>
 public static StorageInsight CreateOrUpdate(this IStorageInsightConfigsOperations operations, string resourceGroupName, string workspaceName, string storageInsightName, StorageInsight parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, workspaceName, storageInsightName, parameters).GetAwaiter().GetResult());
 }