Advertise with Googlier.com
Steve Spencer's Blog - LoggingBlogging on Azure Stuff
http://blogs.recneps.net/
http://www.rssboard.org/rss-specificationBlogEngine.NET 2.9.1.0en-UShttp://blogs.recneps.net/opml.axdhttp://www.dotnetblogengine.net/syndication.axdSteve SpencerSteve Spencer's Blog0.0000000.000000Exporting Logs from Application Insights using Continuous Export<p>This is the fifth post of my series of posts about Log Analytics and Application Insights. The <a href="http://blogs.recneps.net/post/Adding-Application-Insights-Logging-to-your-code">previous post</a> talked about adding custom logging to you code using Application Insights. Now you’ve got your logging into Application Insights you can run log analytics queries and build dash boards, alerts etc. Sometime though you want to use this data in other systems and it would be useful if you could export the data and use it else where. This post will show you how you can regularly export the data from Application Insights into Azure Storage. Once it is in Storage it can easily be moved into other systems or used else where such as PowerBI. This can be achieved using the Continuous Export feature of Application Insights</p><p>To enable Continuous Export, login to the Azure management portal and navigate to Application Insights. Click on the instance you want Continuous Export enabled. The scroll down the options on the left until you find the Configure section and click on Continuous Export</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_146.png"><img width="521" height="349" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_146.png" border="0"></a></p><p>To use Continuous Export you will need to configure a storage account. Click Add:</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_147.png"><img width="297" height="354" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_147.png" border="0"></a></p><p>Click Data types to export:</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_148.png"><img width="254" height="523" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_148.png" border="0"></a></p><p>I was only interested in the logs I emitted from my custom logging, so selected Custom Event, Exception and Trace then clicked OK</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_149.png"><img width="252" height="527" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_149.png" border="0"></a></p><p>Next pick a storage location. Make sure you use one where your Application Insights instance is located otherwise you will be charged egress fees to move the data to a new datacentre.</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_150.png"><img width="203" height="451" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_150.png" border="0"></a></p><p>You can now pick an existing storage account or create a new one. Upon selecting a storage account you can pick an existing container or create a new one.Once a blob container is selected click OK.</p><p>Continuous Export is now configured. You will not see anything in the storage container until the next set of logs are sent to Application Insights.</p><p>My log analytics query shows the following logs have been generated:</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_151.png"><img width="508" height="235" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_151.png" border="0"></a></p><p>If you look at the continuous Export configuration page you will see that the last updated date has changed.</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_152.png"><img width="450" height="305" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_152.png" border="0"></a></p><p>Now look in blob storage. You should see a folder that is<ApplicationInsights_ServiceName>_<ApplicationInsights_InstrumentationKey</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_153.png"><img width="486" height="145" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_153.png" border="0"></a></p><p>Click through and you will see a number of folders. One for each of the logs that I enabled when setting up Continuous Export. Click through one of them and you will see a folder for the date and then a folder for the hour of the logs. Then a file containing the logs for that hour.</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_154.png"><img width="828" height="93" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_154.png" border="0"></a></p><p>You will get a row of json data for each row output for the log query. Note the whole logs emitted will be in each of the folders.</p><p>e.g. </p><blockquote><p>{<br> "event": [<br> {<br> "name": "Some Important Work Completed",<br> "count": 1<br> }<br> ],<br> "internal": {<br> "data": {<br> "id": "a guid is here",<br> "documentVersion": "1.61"<br> }<br> },<br> "context": {<br> "data": {<br> "eventTime": "2020-03-22T18:12:30.2553417Z",<br> "isSynthetic": false,<br> "samplingRate": 100.0<br> },<br> "cloud": {},<br> "device": {<br> "type": "PC",<br> "roleInstance": "yourcomputer",<br> "screenResolution": {}<br> },<br> "session": {<br> "isFirst": false<br> },<br> "operation": {},<br> "location": {<br> "clientip": "0.0.0.0",<br> "continent": "Europe",<br> "country": "United Kingdom",<br> "province": "Nottinghamshire",<br> "city": "Nottingham"<br> },<br> "custom": {<br> "dimensions": [<br> {<br> "CustomerID": "4df16004-2f1b-48c0-87d3-c1251a5db3f6"<br> },<br> {<br> "OrderID": "5440d1cf-5d06-4b0e-bffb-fad522af4ad1"<br> },<br> {<br> "InvoiceID": "a7d5a8fb-2a2e-4697-8ab4-f7bf8b8dbe18"<br> }<br> ]<br> }<br> }<br>
}<br>
</p></blockquote><p>As the data is now out of Application Insights you can move it where ever you need it. You will also need to manage the blob storage data too otherwise you will end up with the logs stored in two places and the storage costs will be doubled. </p><p>One example of subsequent usage is exporting the data to Event Hub. As the data is in blob storage you can use a function with a blob trigger to read the blob in a row at a time and publish the data onto Event Hub:</p><blockquote><p>[FunctionName("ContinuousExport")]<br>
public static async void Run([BlobTrigger("logs/{name}", Connection = "ConitnuousExportBlobSetting")]Stream myBlob, string name, <br> [EventHub("logging", Connection = "EventHubConnectionAppSetting")] IAsyncCollector<string> outputEvents,TraceWriter log)<br>
{<br> log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");<br> StreamReader textReader = new StreamReader(myBlob);<br> while (!textReader.EndOfStream)<br> {<br> string line = textReader.ReadLine();<br> log.Info(line);<br> await outputEvents.AddAsync(line);<br> }<br>
}</p></blockquote><p>Note: This is an example, so will need additional code to make sure that you don’t exceed the <a href="https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-quotas">Event Hub maximum message size</a></p><p>So with Continuous Export you can extract your log data from Application insights and move it to other systems for processing.</p>
http://blogs.recneps.net/post/Exporting-Logs-from-Application-Insights-using-Continuous-Export
http://blogs.recneps.net/post/Exporting-Logs-from-Application-Insights-using-Continuous-Export#commenthttp://blogs.recneps.net/post.aspx?id=821f90dc-d513-47e1-a252-fae8b111f30bSun, 22 Mar 2020 18:44:07 +0000Azure FunctionsAzure StorageLoggingMicrosoft Azurestevehttp://blogs.recneps.net/pingback.axdhttp://blogs.recneps.net/post.aspx?id=821f90dc-d513-47e1-a252-fae8b111f30b7http://blogs.recneps.net/trackback.axd?id=821f90dc-d513-47e1-a252-fae8b111f30bhttp://blogs.recneps.net/post/Exporting-Logs-from-Application-Insights-using-Continuous-Export#commenthttp://blogs.recneps.net/syndication.axd?post=821f90dc-d513-47e1-a252-fae8b111f30bAdding Application Insights Logging to your code<p>This is the fourth of a series about Application Insights and Log analytics. I’ve shown you how to add <a href="http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics">existing logs</a>, using the log analytics <a href="http://blogs.recneps.net/post/Querying-Exception-Logs-in-Azure-Log-Analytics">query language to view you logs</a> and how to <a href="http://blogs.recneps.net/post/Refining-your-Azure-Log-Analytics-Queries">enhance your query</a> to drill down and get to the logs you are interested in. This post is about how you can add logs from your code and provide the information to allow you refine your queries and help you to diagnose your faults more easily</p><p>If you don’t already have application insights then you can create a new instance in the Azure portal (<a href="https://portal.azure.com/">https://portal.azure.com/</a>) </p><p>Get your application insights key from the azure portal. Click on your application insights instance and navigate to the Overview section then copy your instrumentation key. You will need this in your code.</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_106.png"><img width="932" height="201" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_106.png" border="0"></a></p><p>In your project, add application insights via nuget : </p><pre>Install-Package Microsoft.ApplicationInsights -Version 2.10.0</pre><p>In you code you need to assign the key to Application Insights as follows:</p><p><pre>TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault();<br>configuration.InstrumentationKey = “put your key here”;</pre><p>To log details using application insights then you need a telemetry client.</p><p><pre>TelemetryClient telemetry = new TelemetryClient(configuration);</pre><p>The telemetry client has a larger number of features than I am not going to talk about here as I am just interested in logging today. There are three methods of interest: TrackEvent, TrackException and TrackTrace.</p><p>I use TrackEvent to log out things like start and end of methods of if something specific occurs that I want to log; TrackException is for logging Exception details and TrackTrace is for everything else.</p><p><pre>telemetry.TrackEvent("Some Important Work Started");<br>try
{<br> telemetry.TrackTrace("I'm logging out the details of the work that is being done", SeverityLevel.Information);
}
catch(Exception ex)
{<br> telemetry.TrackException(ex);
}
telemetry.TrackEvent("Some Important Work Completed");</pre>
<p>You now have the basics for logging. This will be useful to some extent, but it will be difficult to follow the traces when you have a busy system with logs of concurrent calls to the same methods. To assist you to filter your logs it would be useful to provide some identifying information that you can add to your logs to allow you to track and trace calls through your system. You could add these directly to your logs but this then makes your logs bloated and difficult to read. Application Insights provides a mechanism to pass properties along with the logs which will appear in the Log Analytics data that is returned from your query. Along with each log you can pass a dictionary of properties. I add to the set of properties as the code progresses to provide identifying information to assist with filtering the logs.I generally add in each new identifier as they are created. I can then use these in my queries to track the calls through my system and remove the ones I am not interested in. Diagnosing faults then becomes a lot easier. To make this work then you need to be consistent with the naming of the properties so that you always use the same name for the same property in different parts of the system. Also try and be consistent about when you use TrackEvent and TrackTrace. You can set levels for your traces based upon the severity level (Verbose, Information, Warning, Error, Critical)</p><p><pre>TelemetryConfiguration.Active.InstrumentationKey = Key;
TelemetryClient telemetry = new TelemetryClient();
var logProperties = new Dictionary<string string="" ,="">();
</string><string string="" ,="">
logProperties.Add("CustomerID", "the customer id pass through from elsewhere");
telemetry.TrackEvent("Some Important Work Started", logProperties);
try
{
var orderId = GenerateOrder();
logProperties.Add("OrderID", orderId.ToString());
telemetry.TrackTrace("I just created an order", logProperties);
var invoiceId = GenerateInvoice();
logProperties.Add("InvoiceID", invoiceId.ToString());
telemetry.TrackTrace("I've just created an invoice", logProperties);
SendInvoice(invoiceId);
}
catch (Exception ex)
{
telemetry.TrackException(ex, logProperties);
</string><string string="" ,="">}
telemetry.TrackEvent("Some Important Work Completed", logProperties);</string><br>telemetry.Flush();</pre><p>Flush needs to be called at the end to ensure that the data is sent to Log Analytics. In the code above you can see that I’ve added a CustomerId, OrderId and InvoiceId to the log properties and pass the log properties to each of the telemetry calls. Each of the logs will contain the properties that were set at the time of logging. I’ve generally wrap all this code so that I do not have to pass in the log properties into each call. I can add to the log properties whenever I have new properties and then each of the telemetry calls will include the log properties.</p><p>When we look at the logs via log analytics will can see the additional properties on the logs and then use them in our queries.</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_107.png"><img width="831" height="211" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_107.png" border="0"></a></p><p><a href="http://blogs.recneps.net/image.axd?picture=image_108.png"><img width="829" height="238" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_108.png" border="0"></a></p><p>The log properties appear in customDimensions and you can see how the invoice log has the invoice id as well as the customer id and order id. The order log only has the customer id and order id.</p><p>You can add the custom dimensions to your queries as follows:</p><blockquote><p>union traces, customEvents, exceptions<p>|order by timestamp asc<p>| where customDimensions.CustomerID == "e56e4baa-9e1d-4c3c-b498-365bf2807a5f"</p></blockquote><p>You can also see in the logs the severity level which allows you to filter your logs to a sensible level. You need to plan your logs carefully and set an appropriate level to stop you flooding your logs with unnecessary data until you need it.</p><p>I’ve now shown you how to add logs to your application. You can find out more about the other methods available on the telemetry api <a href="https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics">here</a></p>
http://blogs.recneps.net/post/Adding-Application-Insights-Logging-to-your-code
http://blogs.recneps.net/post/Adding-Application-Insights-Logging-to-your-code#commenthttp://blogs.recneps.net/post.aspx?id=49fe7455-0f79-454d-bba1-eb12b6c7cba6Sat, 17 Aug 2019 13:55:57 +0000LoggingMicrosoft Azurestevehttp://blogs.recneps.net/pingback.axdhttp://blogs.recneps.net/post.aspx?id=49fe7455-0f79-454d-bba1-eb12b6c7cba6384http://blogs.recneps.net/trackback.axd?id=49fe7455-0f79-454d-bba1-eb12b6c7cba6http://blogs.recneps.net/post/Adding-Application-Insights-Logging-to-your-code#commenthttp://blogs.recneps.net/syndication.axd?post=49fe7455-0f79-454d-bba1-eb12b6c7cba6Refining your Azure Log Analytics Queries<p>This is part 2 of a series of post about Log Analytics in Azure. In <a href="http://blogs.recneps.net/post/Querying-Exception-Logs-in-Azure-Log-Analytics">Part 1</a> I discussed how to access log analytics and use it to query your Exceptions. I also showed you how to display your output as a graph.</p><p>In this post we will look at some other tables, how we can view them and how we can refine the details we want to view.</p><p>I’ve been using Application Insights in my code to add my application logs and these log into a number of different tables depending upon which API call is used. </p><p>If you look at the tables we have with Application Insights, you can see that as well as exceptions there are a number of other tables</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_99.png"><img width="195" height="244" title="image" style="margin: 0px; display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_99.png" border="0"></a></p><p>The ones I am interested in are traces, custom events and exceptions. Traces is used for general logging, custom events are used to indicate something has happened, for example, The start and end of some activity. Exceptions are used when something has gone wrong. You can query each of these tables separately.</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_100.png"><img width="477" height="260" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_100.png" border="0"></a></p><p><a href="http://blogs.recneps.net/image.axd?picture=image_101.png"><img width="480" height="242" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_101.png" border="0"></a></p><p><a href="http://blogs.recneps.net/image.axd?picture=image_102.png"><img width="480" height="258" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_102.png" border="0"></a></p><p>What you can see with these three logs is that we can easily retrieve the data but it would be useful if it could be done in one query. For that you need to use the “union” keyword as follows:</p><blockquote><p>union traces, exceptions, customEvents<p>| where customDimensions.Source <> "ApplicationInsightsProfiler"</p></blockquote><p>Note, I need to add in the where clause as the ApplicationInsights Profiler is enabled on my site and I am not currently interested in those logs</p><p>If you run this query you will get a snapshot of the data in each of the table which is not always that useful</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_103.png"><img width="482" height="477" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_103.png" border="0"></a></p><p>What would be useful is if I could order the logs by the timestamp.</p><p>To do this add another pipe and use the “order by” keywords and pick the “timestamp” column. I’ve added “asc” as I want to show my oldest log first. You can reverse it by using “desc” instead.</p><blockquote><p>union traces, exceptions, customEvents<p>| where customDimensions.Source <> "ApplicationInsightsProfiler"<p>| order by timestamp asc </p></blockquote><p><a href="http://blogs.recneps.net/image.axd?picture=image_104.png"><img width="529" height="398" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_104.png" border="0"></a></p><p>Now my logs are in a sensible order and I can see what is happening. The issue I have now is that I’ve got too much information on the screen to be able to view everything I need, plus the different tables have information in different columns. You can see with the events that the details do not appear in the message column making it difficult to view the event details. In order to control what I see I can use projection.This is achieved using the “project” keyword. To make best use of “project” you need to identify the columns of interest in each of the table we are using. Projection also allows you to order the columns. The order of the columns after “project” is the order they will appear in the results </p><blockquote><p>union traces, exceptions, customEvents<p>| where customDimensions.Source <> "ApplicationInsightsProfiler"<p>| project timestamp, itemType, name, message, problemId, customDimensions<p>|order by timestamp asc </p></blockquote><p>“timestamp” is the date/time of the log</p><p>“itemType” will show trace, customEvent or exception</p><p>“Name” contains the name of the custom event</p><p>“message” contains the details of the trace</p><p>“problemId” shows the top level details of the exception and custom</p><p>“customDimensions” shows custom properties that have been attached to the log</p><p>This results in the following log output:</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_105.png"><img width="579" height="522" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_105.png" border="0"></a></p><p>You can see now that the logs are in a more usable format and I can drill down a little by clicking on the > next to the log. By using projection however you will limit the columns that are returned. If you need to drill down to get information you have filtered out, then you will need to run a different query. One example of this is when you get an exception, This projection will only give you the problemId so you will need to run a query on the exceptions table to bring back all the exceptions details.</p><p>In my next post I will show you how to use custom logging in your code with Application Insights.</p>
http://blogs.recneps.net/post/Refining-your-Azure-Log-Analytics-Queries
http://blogs.recneps.net/post/Refining-your-Azure-Log-Analytics-Queries#commenthttp://blogs.recneps.net/post.aspx?id=fc7f605b-e22f-499b-9e0f-b39f54572093Sat, 27 Jul 2019 09:38:37 +0000LoggingMicrosoft Azurestevehttp://blogs.recneps.net/pingback.axdhttp://blogs.recneps.net/post.aspx?id=fc7f605b-e22f-499b-9e0f-b39f545720937http://blogs.recneps.net/trackback.axd?id=fc7f605b-e22f-499b-9e0f-b39f54572093http://blogs.recneps.net/post/Refining-your-Azure-Log-Analytics-Queries#commenthttp://blogs.recneps.net/syndication.axd?post=fc7f605b-e22f-499b-9e0f-b39f54572093Querying Exception Logs in Azure Log Analytics<p>In a <a href="http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics">previous post</a> I’ve talked about how you can add logs to Azure Log Analytics. This post is about how you can make use of that logging . The key to Log Analytics (once your log data is in) is its query language. </p><p>You can navigate to Log Analytics from the Azure Portal. I’m using Application Insights for the examples and you can get to Log Analytics from the menu bar or by clicking search in the left hand panel and then Log analytics</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_88.png"><img width="636" height="54" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_88.png" border="0"></a></p><p><a href="http://blogs.recneps.net/image.axd?picture=image_89.png"><img width="464" height="303" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_89.png" border="0"></a></p><p>Once in Log Analytics there will be an area for queries</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_90.png"><img width="471" height="218" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_90.png" border="0"></a></p><p>An area for your data sources</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_91.png"><img width="214" height="244" title="image" style="margin: 0px; display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_91.png" border="0"></a></p><p>and a query explorer where you can find queries that you or your team have saved previously.</p><p>The data sources section is a useful place to start because double clicking a data source will add it to the query. So starting with double clicking “exceptions” the press the Run button. This will query the exceptions logs and return all the exception logs that happening in the last 24 hours (as indicated by the time range next to the run button). If you want to add a time period to your query so that you can use it in a dashboard for example. There are some date functions to help. If you are unsure about how to add query parameters then you can go to the data that is returned and click the plus button next to the item you want to add to your query as below:</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_92.png"><img width="605" height="204" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_92.png" border="0"></a></p><p>This will make the query look as follows:</p><blockquote><p>exceptions <p>| where timestamp == todatetime('2019-06-26T18:21:49.1473946Z') </p></blockquote><p>This is useful as you can add in >= to the query to find all logs that happened after this time but if you want to get all logs that happened over a specific period you can use the DateTime functions by typing a space after the greater than sign and see a list of the available functions</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_93.png"><img width="515" height="149" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_93.png" border="0"></a></p><p>I use the “ago” function which also has help tips once you select it</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_94.png"><img width="515" height="130" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_94.png" border="0"></a></p><p>As you can see there are examples for minutes, hours and days. </p><p>Queries are also built up using the pipe symbol so you can easily append.</p><p>If you want to summarise your data so you can get a count of each of the exceptions then you add a new pipe using the summarize keyword and the count function.You need to tell the query which property you wish to count. If you look at the “filter on” screen shot above you will see that there is a type property in the log record. If we summarize that property with count then the query will return all the exceptions in the timeframe and how often they have occurred</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_95.png"><img width="352" height="428" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_95.png" border="0"></a></p><p>The query language also has a use “render” keyword that allows you to return the query in a variety of graphs</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_96.png"><img width="403" height="145" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_96.png" border="0"></a></p><p>So the final query looks like this</p><blockquote><p>exceptions<p>| where timestamp > ago(70d) <p>| summarize count() by type<p>| render piechart </p></blockquote><p><a href="http://blogs.recneps.net/image.axd?picture=image_97.png"><img width="665" height="398" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_97.png" border="0"></a></p><p>Clicking the save button allows you to save your queries so that you can use them later or share them with other uses who share the same log analytics instance</p><p><a href="http://blogs.recneps.net/image.axd?picture=image_98.png"><img width="176" height="447" title="image" style="display: inline; background-image: none;" alt="image" src="http://blogs.recneps.net/image.axd?picture=image_thumb_98.png" border="0"></a></p><p>In my <a href="http://blogs.recneps.net/post/Refining-your-Azure-Log-Analytics-Queries">next post</a> I will show how you can use some of the other log tables, ordering and selecting the columns you wish to display</p>
http://blogs.recneps.net/post/Querying-Exception-Logs-in-Azure-Log-Analytics
http://blogs.recneps.net/post/Querying-Exception-Logs-in-Azure-Log-Analytics#commenthttp://blogs.recneps.net/post.aspx?id=e73d88c0-fea7-43b4-b1f3-e3b2d9fff121Thu, 27 Jun 2019 18:33:48 +0000Microsoft AzureLoggingstevehttp://blogs.recneps.net/pingback.axdhttp://blogs.recneps.net/post.aspx?id=e73d88c0-fea7-43b4-b1f3-e3b2d9fff12165http://blogs.recneps.net/trackback.axd?id=e73d88c0-fea7-43b4-b1f3-e3b2d9fff121http://blogs.recneps.net/post/Querying-Exception-Logs-in-Azure-Log-Analytics#commenthttp://blogs.recneps.net/syndication.axd?post=e73d88c0-fea7-43b4-b1f3-e3b2d9fff121Adding existing logs to Log Analytics<p>I created a <a href="https://www.youtube.com/watch?v=I7eN-VuRD2o">video</a> to walk you through how to add existing logs to Log Analytics. There have been some changes to the way you do this.</p> <p>The location of the settings to configure this has now move to Log Analytics in the Azure Portal. Previously, this was in the Operations Management Suite (OMS).</p> <p>Logon to your Azure Portal (<a href="https://portal.azure.com">https://portal.azure.com</a>) and click through to your log analytics workspace. Then click on Advanced Settings</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_63.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_63.png" width="245" height="368"></a></p> <p>The Advanced Settings page will allow you to configure your data sources and where your logs will be pulled from. The rest of the <a href="https://www.youtube.com/watch?v=I7eN-VuRD2o">video</a> is the same.</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_64.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_64.png" width="635" height="304"></a></p>
http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics
http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics#commenthttp://blogs.recneps.net/post.aspx?id=be430a58-d897-49ed-a562-3833b2edad39Sat, 24 Nov 2018 06:23:00 +0000AzureLoggingstevehttp://blogs.recneps.net/pingback.axdhttp://blogs.recneps.net/post.aspx?id=be430a58-d897-49ed-a562-3833b2edad3915http://blogs.recneps.net/trackback.axd?id=be430a58-d897-49ed-a562-3833b2edad39http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics#commenthttp://blogs.recneps.net/syndication.axd?post=be430a58-d897-49ed-a562-3833b2edad39Azure Key Vault Logging and Events with Log Analytics<p>Following on from my previous blog post (<a href="http://blogs.recneps.net/post/Setting-up-Azure-Key-Vault-with-Audit-logging">http://blogs.recneps.net/post/Setting-up-Azure-Key-Vault-with-Audit-logging</a>) which explains how to set up Azure key vault with logging enabled, this post explains how to access the details of these logs and also to create an alert so you can see if someone is accessing the key vault from an unknown ip address (for example) <p>Open the <a href="https://portal.azure.com">Azure portal</a> and navigate to the Resource Groups section and pick the resource group that we configured last time which contains the key vault and log analytics resources <p><a href="http://blogs.recneps.org/image.axd?picture=image_43.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_43.png" width="738" height="151"></a> <p>Click your log analytics item, to open Log Analytics. <p>You can then select Log Search <p><a href="http://blogs.recneps.org/image.axd?picture=image_44.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_44.png" width="734" height="168"></a> <p>This screen allows you to create your own query or select from existing ones. <p><a href="http://blogs.recneps.org/image.axd?picture=image_45.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_45.png" width="585" height="328"></a> <p>Selecting “All Collected Logs” will show you the logs for the last day. I’ve highlighted the areas where you can change the time period, see the query and also click on Advanced Analytics to give a richer environment for analysing your logs. <p><a href="http://blogs.recneps.org/image.axd?picture=image_46.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_46.png" width="597" height="333"></a> <p>If you want to query just for the Key Vault Audit logs then you can use the following query: <p>search * | where Category=="AuditEvent" <p><a href="http://blogs.recneps.org/image.axd?picture=image_47.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_47.png" width="348" height="379"></a> <p>This will default to a list view, but clicking the Table button will format the data in an easier to read table. <p><a href="http://blogs.recneps.org/image.axd?picture=image_48.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_48.png" width="602" height="251"></a> <p>You can sort and filter on the column headers. This can also be achieved using the order by clause as follows: <p>search * |where Category=="AuditEvent" | order by TimeGenerated desc <p>A blog post discussing the query language can be found <a href="https://azure.microsoft.com/en-gb/blog/azure-log-analytics-meet-our-new-query-language-2/">here</a> <p>We are interested in all calls where someone has tried to access a Secret from the key vault. For that we are looking for an AuditEvent with an OperationName of SecretGet. If we also want to restrict the columns we retrieve then you can use “project” e.g. <p>search * | where Category=="AuditEvent" and OperationName == "SecretGet"<br>| order by TimeGenerated desc<br>| project TimeGenerated, OperationName, CallerIPAddress, ResultSignature, requestUri_s </p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_49.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_49.png" width="608" height="162"></a></p> <p>Now we are familiar with writing queries we can look at alerting. I’d like to set up an alert when the key vault is access from an IP Address other than the one where my application is running. This can be done as follows:</p> <p>search * | where Category=="AuditEvent" and CallerIPAddress != "51.140.184.51" </p> <p>This ip address is actually the Azure Portal and is shown when you view the resource group that contains the key vault.I’m using this ip address so that I will actually get an alert (at the wrong time) when my application runs </p> <p>Click New Alert Rule</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_50.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_50.png" width="607" height="235"></a></p> <p>The following screen should appear</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_51.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_51.png" width="603" height="500"></a></p> <p>The Alert Target should be the Log Analytics we’ve been using and the Target Criteria (when clicked) should show the query we’ve just written</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_52.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_52.png" width="298" height="633"></a></p> <p>We need to configure the rule for when this alert should be triggered. I’m interested when at least 1 attempt has been made in the last 5 minutes to access the Key Vault from an unknown location, so I set the threshold to be zero and click Done. We’ve now configured the logic to determine when the event is fired. Now we need to say what we want to happen when it fires.Firstly we need to give the alert a name and description</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_53.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_53.png" width="496" height="254"></a></p> <p>Now we need to configure how we are alerted. For this you need to create an action group. An action group allows you to define a collection of activities that will happen when the alert is fired. Click New Action Group</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_54.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_54.png" width="641" height="335"></a></p> <p>Action Types can be any of the following:</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_55.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_55.png" width="244" height="154"></a></p> <p>An action group can have multiple actions and you can select both email and SMS in a single action.Once you have created your Action Group you need to select in then click “Create alert rule”</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_56.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_56.png" width="529" height="269"></a></p> <p>Your alert is now set up and running. You can view/edit alerts by selecting Monitor in the Azure Portal</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_57.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_57.png" width="210" height="244"></a></p> <p>then click Alerts (preview), you will be able to see the alerts that have fired.</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_58.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_58.png" width="545" height="214"></a></p> <p>Click Manage Rules to edit the alert.</p> <p>When the alert is fired I will get an email containing the details of the alert. </p> <p>Log analytics is a powerful tool and whilst this series of posts has been related to auditing of Key Vault we can use log analytics for a wide variety of log sources such as Application Insights. We can also use the same mechanism for alerting to these other log sources,</p> <p>The <a href="https://www.youtube.com/watch?v=I7eN-VuRD2o&t=10s">next post is a video</a> that shows you how to connect existing log files to log analytics</p>
http://blogs.recneps.net/post/Azure-Key-Vault-Logging-and-Events-with-Log-Analytics
http://blogs.recneps.net/post/Azure-Key-Vault-Logging-and-Events-with-Log-Analytics#commenthttp://blogs.recneps.net/post.aspx?id=f7ef288d-4e33-48a2-a7f3-6b95cfc11820Thu, 22 Feb 2018 19:59:03 +0000AzureLoggingSecuritystevehttp://blogs.recneps.net/pingback.axdhttp://blogs.recneps.net/post.aspx?id=f7ef288d-4e33-48a2-a7f3-6b95cfc11820600http://blogs.recneps.net/trackback.axd?id=f7ef288d-4e33-48a2-a7f3-6b95cfc11820http://blogs.recneps.net/post/Azure-Key-Vault-Logging-and-Events-with-Log-Analytics#commenthttp://blogs.recneps.net/syndication.axd?post=f7ef288d-4e33-48a2-a7f3-6b95cfc11820