Exemplo n.º 1
0
 public PSSavedSearchProperties(SavedSearchProperties properties)
 {
     if (properties != null)
     {
         this.Category    = properties.Category;
         this.DisplayName = properties.DisplayName;
         this.Query       = properties.Query;
         this.Version     = properties.Version;
     }
 }
Exemplo n.º 2
0
        protected override void ProcessRecord()
        {
            SavedSearchProperties properties = new SavedSearchProperties()
            {
                Category    = this.Category,
                DisplayName = this.DisplayName,
                Query       = this.Query,
                Version     = this.Version
            };

            properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tags, properties.Query);

            WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
        }
Exemplo n.º 3
0
        protected override void ProcessRecord()
        {
            SavedSearchProperties properties = new SavedSearchProperties()
            {
                Category    = this.Category,
                DisplayName = this.DisplayName,
                Query       = this.Query,
                Version     = this.Version,
                Tags        = new List <Tag>()
                {
                    new Tag()
                    {
                        Name = "Group", Value = "Computer"
                    }
                }
            };

            WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
        }
Exemplo n.º 4
0
        public PSSavedSearchProperties(SavedSearchProperties properties)
        {
            if (properties != null)
            {
                this.Category    = properties.Category;
                this.DisplayName = properties.DisplayName;
                this.Query       = properties.Query;
                this.Version     = properties.Version;
                this.Tags        = new Hashtable();

                if (properties.Tags != null)
                {
                    foreach (Tag tag in properties.Tags)
                    {
                        this.Tags[tag.Name] = tag.Value;
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected override void ProcessRecord()
        {
            SavedSearchProperties properties = new SavedSearchProperties()
            {
                Category    = this.Category,
                DisplayName = this.DisplayName,
                Query       = this.Query,
                Version     = this.Version,
                Tags        = new List <Tag>()
                {
                    new Tag()
                    {
                        Name = "Group", Value = "Computer"
                    }
                }
            };

            if (!SearchCommandHelper.IsListOfComputers(this.Query))
            {
                throw new PSArgumentException("Query is not a list of computers. Please use aggregations such as: distinct Computer or measure count() by Computer.");
            }

            WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
        }
        public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName, string workspaceName, string savedSearchId, SavedSearchProperties properties, bool force, Action <bool, string, string, string, Action> ConfirmAction, string ETag = null)
        {
            HttpStatusCode status            = HttpStatusCode.Ambiguous;
            Action         createSavedSearch = () =>
            {
                SearchCreateOrUpdateSavedSearchParameters searchParameters = new SearchCreateOrUpdateSavedSearchParameters();
                if (ETag != null && ETag != "")
                {
                    searchParameters.ETag = ETag;
                }
                searchParameters.Properties = properties;
                AzureOperationResponse response = OperationalInsightsManagementClient.Search.CreateOrUpdateSavedSearch(resourceGroupName, workspaceName, savedSearchId, searchParameters);
                status = response.StatusCode;
            };

            if (force)
            {
                createSavedSearch();
            }
            else
            {
                bool savedSearchExists = CheckSavedSearchExists(resourceGroupName, workspaceName, savedSearchId);

                ConfirmAction(
                    !savedSearchExists,    // prompt only if the saved search exists
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.SavedSearchExists,
                        savedSearchId,
                        workspaceName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.SavedSearchCreating,
                        savedSearchId,
                        workspaceName),
                    savedSearchId,
                    createSavedSearch);
            }
            return(status);
        }
        public void CanCreateOrUpdateAndDeleteSavedSearches()
        {
            BasicDelegatingHandler handler = new BasicDelegatingHandler();

            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();

                var client = TestHelper.GetOperationalInsightsManagementClient(handler);

                string resourceGroupName = "mms-eus";
                string workspaceName     = "workspace-861bd466-5400-44be-9552-5ba40823c3aa";
                string newSavedSearchId  = "test-new-saved-search-id-2015";

                SearchCreateOrUpdateSavedSearchParameters parameters = new SearchCreateOrUpdateSavedSearchParameters();
                parameters.Properties             = new SavedSearchProperties();
                parameters.Properties.Version     = 1;
                parameters.Properties.Query       = "* | measure Count() by Computer";
                parameters.Properties.DisplayName = "Create or Update Saved Search Test";
                parameters.Properties.Category    = " Saved Search Test Category";
                parameters.Properties.Tags        = new List <Tag>()
                {
                    new Tag()
                    {
                        Name = "Group", Value = "Computer"
                    }
                };

                var result = client.Search.ListSavedSearches(resourceGroupName, workspaceName);

                var createSavedSearchResults = client.Search.CreateOrUpdateSavedSearch(
                    resourceGroupName,
                    workspaceName,
                    newSavedSearchId,
                    parameters);
                Assert.NotNull(createSavedSearchResults);

                // Verify that the saved search was saved
                var savedSearchesResult = client.Search.ListSavedSearches(resourceGroupName, workspaceName);
                Assert.NotNull(savedSearchesResult);
                Assert.NotNull(savedSearchesResult.Value);
                Assert.NotEqual(savedSearchesResult.Value.Count, 0);
                Assert.NotNull(savedSearchesResult.Value[0].Id);
                Assert.NotNull(savedSearchesResult.Value[0].Properties);
                bool foundSavedSearch = false;
                for (int i = 0; i < savedSearchesResult.Value.Count; i++)
                {
                    SavedSearchProperties properties = savedSearchesResult.Value[i].Properties;
                    if (properties.Category.Equals(parameters.Properties.Category) &&
                        properties.Version == parameters.Properties.Version &&
                        properties.Query.Equals(parameters.Properties.Query) &&
                        properties.DisplayName.Equals(parameters.Properties.DisplayName) &&
                        properties.Tags[0].Name.Equals(parameters.Properties.Tags[0].Name) &&
                        properties.Tags[0].Value.Equals(parameters.Properties.Tags[0].Value))
                    {
                        foundSavedSearch = true;
                        parameters.ETag  = savedSearchesResult.Value[i].ETag;
                    }
                }
                Assert.True(foundSavedSearch);

                // Test updating a saved search
                parameters.Properties.Query = "*";
                parameters.Properties.Tags  = new List <Tag>()
                {
                    new Tag()
                    {
                        Name = "Source", Value = "Test2"
                    }
                };
                var updateSavedSearchResults = client.Search.CreateOrUpdateSavedSearch(
                    resourceGroupName,
                    workspaceName,
                    newSavedSearchId,
                    parameters);
                Assert.NotNull(updateSavedSearchResults);
                // Verify that the saved search was saved
                savedSearchesResult = client.Search.ListSavedSearches(resourceGroupName, workspaceName);
                Assert.NotNull(savedSearchesResult);
                Assert.NotNull(savedSearchesResult.Value);
                Assert.NotEqual(savedSearchesResult.Value.Count, 0);
                Assert.NotNull(savedSearchesResult.Value[0].Id);
                Assert.NotNull(savedSearchesResult.Value[0].Properties);
                foundSavedSearch = false;
                for (int i = 0; i < savedSearchesResult.Value.Count; i++)
                {
                    SavedSearchProperties properties = savedSearchesResult.Value[i].Properties;
                    if (properties.Category.Equals(parameters.Properties.Category) &&
                        properties.Version == parameters.Properties.Version &&
                        properties.Query.Equals(parameters.Properties.Query) &&
                        properties.DisplayName.Equals(parameters.Properties.DisplayName) &&
                        properties.Tags[0].Name.Equals(parameters.Properties.Tags[0].Name) &&
                        properties.Tags[0].Value.Equals(parameters.Properties.Tags[0].Value))
                    {
                        foundSavedSearch = true;
                    }
                }
                Assert.True(foundSavedSearch);



                // Test the function to delete a saved search
                client.Search.DeleteSavedSearch(resourceGroupName, workspaceName, newSavedSearchId);
                savedSearchesResult = client.Search.ListSavedSearches(resourceGroupName, workspaceName);

                foundSavedSearch = false;
                for (int i = 0; i < savedSearchesResult.Value.Count; i++)
                {
                    SavedSearchProperties properties = savedSearchesResult.Value[i].Properties;
                    if (properties.Category.Equals(parameters.Properties.Category) &&
                        properties.Version == parameters.Properties.Version &&
                        properties.Query.Equals(parameters.Properties.Query) &&
                        properties.DisplayName.Equals(parameters.Properties.DisplayName))
                    {
                        foundSavedSearch = true;
                    }
                }
                Assert.False(foundSavedSearch);
            }
        }