Пример #1
0
        public async Task QueryLogsAsPrimitive()
        {
            #region Snippet:QueryLogsAsPrimitive

#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <string> > response = await client.QueryAsync <string>(workspaceId,
                                                                                           "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count | project ResourceGroup",
                                                                                           TimeSpan.FromDays(1));

            foreach (var resourceGroup in response.Value)
            {
                Console.WriteLine(resourceGroup);
            }

            #endregion
        }
Пример #2
0
        public void CanSetServiceTimeout_Mocked()
        {
            string preferHeader = null;
            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            // TimeSpan? networkOverride = default;

            var mockTransport = MockTransport.FromMessageCallback(message =>
            {
                Assert.True(message.Request.Headers.TryGetValue("prefer", out preferHeader));
                // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
                //networkOverride = message.NetworkTimeout;

                return(new MockResponse(500));
            });

            var client = new LogsClient(new Uri("https://api.loganalytics.io"), new MockCredential(), new LogsClientOptions()
            {
                Transport = mockTransport
            });

            Assert.ThrowsAsync <RequestFailedException>(() => client.QueryAsync("wid", "tid", TimeSpan.FromDays(1), options: new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            }));

            Assert.AreEqual("wait=600", preferHeader);
            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            //Assert.AreEqual(TimeSpan.FromMinutes(10), networkOverride);
        }
Пример #3
0
        public async Task QueryLogsWithTimeout()
        {
            #region Snippet:QueryLogsWithTimeout
#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <int> > response = await client.QueryAsync <int>(workspaceId,
                                                                                     "AzureActivity | summarize count()",
                                                                                     TimeSpan.FromDays(1),
                                                                                     options : new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            });

            foreach (var resourceGroup in response.Value)
            {
                Console.WriteLine(resourceGroup);
            }

            #endregion
        }
Пример #4
0
        public async Task QueryLogsAsTablePrintAll()
        {
            #region Snippet:QueryLogsPrintTable

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated");

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var column in table.Columns)
            {
                Console.Write(column.Name + ";");
            }

            Console.WriteLine();

            var columnCount = table.Columns.Count;
            foreach (var row in table.Rows)
            {
                for (int i = 0; i < columnCount; i++)
                {
                    Console.Write(row[i] + ";");
                }

                Console.WriteLine();
            }

            #endregion
        }
Пример #5
0
        public void CanSetServiceTimeout_Mocked()
        {
            string   preferHeader    = null;
            TimeSpan?networkOverride = default;

            var mockTransport = MockTransport.FromMessageCallback(message =>
            {
                Assert.True(message.Request.Headers.TryGetValue("prefer", out preferHeader));
                networkOverride = message.NetworkTimeout;

                return(new MockResponse(500));
            });

            var client = new LogsClient(new MockCredential(), new LogsClientOptions()
            {
                Transport = mockTransport
            });

            Assert.ThrowsAsync <RequestFailedException>(() => client.QueryAsync("wid", "tid", options: new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            }));

            Assert.AreEqual("wait=600", preferHeader);
            Assert.AreEqual(TimeSpan.FromMinutes(10), networkOverride);
        }
Пример #6
0
        public async Task QueryLogsAsTable()
        {
            #region Snippet:QueryLogsAsTable

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated");

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var row in table.Rows)
            {
                Console.WriteLine(row["OperationName"] + " " + row["ResourceGroup"]);
            }

            #endregion
        }
Пример #7
0
        public async Task QueryLogsAsModels()
        {
            #region Snippet:QueryLogsAsModels

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <MyLogEntryModel> > response = await client.QueryAsync <MyLogEntryModel>(workspaceId,
                                                                                                             "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count");

            foreach (var logEntryModel in response.Value)
            {
                Console.WriteLine($"{logEntryModel.ResourceGroup} had {logEntryModel.Count} events");
            }

            #endregion
        }
Пример #8
0
        public async Task QueryLogsAsPrimitive()
        {
            #region Snippet:QueryLogsAsPrimitive

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <string> > response = await client.QueryAsync <string>(workspaceId,
                                                                                           "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count | project ResourceGroup");

            foreach (var resourceGroup in response.Value)
            {
                Console.WriteLine(resourceGroup);
            }

            #endregion
        }
Пример #9
0
        public async Task BadRequest()
        {
            #region Snippet:BadRequest
#if SNIPPET
            string workspaceId = "<workspace_id>";
#else
            string workspaceId = TestEnvironment.WorkspaceId;
#endif
            LogsClient client = new LogsClient(new DefaultAzureCredential());
            try
            {
                await client.QueryAsync(workspaceId, "My Not So Valid Query", TimeSpan.FromDays(1));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            #endregion
        }
Пример #10
0
        public async Task QueryLogsAsTable()
        {
            #region Snippet:QueryLogsAsTable
#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated", TimeSpan.FromDays(1));

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var row in table.Rows)
            {
                Console.WriteLine(row["OperationName"] + " " + row["ResourceGroup"]);
            }

            #endregion
        }
Пример #11
0
        public async Task QueryLogsAsTablePrintAll()
        {
            #region Snippet:QueryLogsPrintTable

#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated", TimeSpan.FromDays(1));

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var column in table.Columns)
            {
                Console.Write(column.Name + ";");
            }

            Console.WriteLine();

            var columnCount = table.Columns.Count;
            foreach (var row in table.Rows)
            {
                for (int i = 0; i < columnCount; i++)
                {
                    Console.Write(row[i] + ";");
                }

                Console.WriteLine();
            }

            #endregion
        }