Monitor logs for Azure Web Application Firewall (2024)

  • Article

You can monitor Web Application Firewall resources using logs. You can save performance, access, and other data or consume it from a resource for monitoring purposes.

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

Diagnostic logs

You can use different types of logs in Azure to manage and troubleshoot application gateways. You can access some of these logs through the portal. All logs can be extracted from Azure Blob storage and viewed in different tools, such as Azure Monitor logs, Excel, and Power BI. You can learn more about the different types of logs from the following list:

  • Activity log: You can use Azure activity logs to view all operations that are submitted to your Azure subscription, and their status. Activity log entries are collected by default, and you can view them in the Azure portal.
  • Access Resource log: You can use this log to view Application Gateway access patterns and analyze important information. This includes the caller's IP, requested URL, response latency, return code, and bytes in and out. This log contains individual records for each request and associates that request to the unique Application Gateway that processed the request. Unique Application Gateway instances can be identified by the property instanceId.
  • Performance Resource log: You can use this log to view how Application Gateway instances are performing. This log captures performance information for each instance, including total requests served, throughput in bytes, total requests served, failed request count, and healthy and unhealthy back-end instance count. A performance log is collected every 60 seconds. The Performance log is available only for the v1 SKU. For the v2 SKU, use Metrics for performance data.
  • Firewall Resource log: You can use this log to view the requests that are logged through either detection or prevention mode of an application gateway that is configured with the web application firewall.

Note

Logs are available only for resources deployed in the Azure Resource Manager deployment model. You cannot use logs for resources in the classic deployment model. For a better understanding of the two models, see the Understanding Resource Manager deployment and classic deployment article.

You have three options for storing your logs:

  • Storage account: Storage accounts are best used for logs when logs are stored for a longer duration and reviewed when needed.
  • Event hubs: Event hubs are a great option for integrating with other security information and event management (SIEM) tools to get alerts on your resources.
  • Azure Monitor logs: Azure Monitor logs is best used for general real-time monitoring of your application or looking at trends.

Enable logging through PowerShell

Activity logging is automatically enabled for every Resource Manager resource. You must enable access and performance logging to start collecting the data available through those logs. To enable logging, use the following steps:

  1. Note your storage account's resource ID, where the log data is stored. This value is of the form: /subscriptions/<subscriptionId>/resourceGroups/<resource group name>/providers/Microsoft.Storage/storageAccounts/<storage account name>. You can use any storage account in your subscription. You can use the Azure portal to find this information.

    Monitor logs for Azure Web Application Firewall (1)

  2. Note your application gateway's resource ID for which logging is enabled. This value is of the form: /subscriptions/<subscriptionId>/resourceGroups/<resource group name>/providers/Microsoft.Network/applicationGateways/<application gateway name>. You can use the portal to find this information.

    Monitor logs for Azure Web Application Firewall (2)

  3. Enable resource logging by using the following PowerShell cmdlet:

    Set-AzDiagnosticSetting -ResourceId /subscriptions/<subscriptionId>/resourceGroups/<resource group name>/providers/Microsoft.Network/applicationGateways/<application gateway name> -StorageAccountId /subscriptions/<subscriptionId>/resourceGroups/<resource group name>/providers/Microsoft.Storage/storageAccounts/<storage account name> -Enabled $true 

Tip

Activity logs do not require a separate storage account. The use of storage for access and performance logging incurs service charges.

Enable logging through the Azure portal

  1. In the Azure portal, find your resource and select Diagnostic settings.

    For Application Gateway, three logs are available:

    • Access log
    • Performance log
    • Firewall log
  2. Select Add diagnostic setting.

  3. The Diagnostic setting page provides the settings for the resource logs. In this example, Log Analytics stores the logs. You can also use an event hub, a storage account, or a partner solution to save the resource logs.

    Monitor logs for Azure Web Application Firewall (3)

  4. Type a name for the settings, confirm the settings, and select Save.

Activity log

Azure generates the activity log by default. The logs are preserved for 90 days in the Azure event logs store. Learn more about these logs by reading the View events and activity log article.

Access log

The access log is generated only if you've enabled it on each Application Gateway instance, as detailed in the preceding steps. The data is stored in the storage account that you specified when you enabled the logging. Each access of Application Gateway is logged in JSON format, as shown in the following example for v1:

ValueDescription
instanceIdApplication Gateway instance that served the request.
clientIPOriginating IP for the request.
clientPortOriginating port for the request.
httpMethodHTTP method used by the request.
requestUriURI of the received request.
RequestQueryServer-Routed: Back-end pool instance that was sent the request.X-AzureApplicationGateway-LOG-ID: Correlation ID used for the request. It can be used to troubleshoot traffic issues on the back-end servers. SERVER-STATUS: HTTP response code that Application Gateway received from the back end.
UserAgentUser agent from the HTTP request header.
httpStatusHTTP status code returned to the client from Application Gateway.
httpVersionHTTP version of the request.
receivedBytesSize of packet received, in bytes.
sentBytesSize of packet sent, in bytes.
timeTakenLength of time (in milliseconds) that it takes for a request to be processed and its response to be sent. This is calculated as the interval from the time when Application Gateway receives the first byte of an HTTP request to the time when the response send operation finishes. It's important to note that the Time-Taken field usually includes the time that the request and response packets are traveling over the network.
sslEnabledWhether communication to the back-end pools used TLS/SSL. Valid values are on and off.
hostThe hostname with which the request has been sent to the backend server. If backend hostname is being overridden, this name will reflect that.
originalHostThe hostname with which the request was received by the Application Gateway from the client.
{ "resourceId": "/SUBSCRIPTIONS/{subscriptionId}/RESOURCEGROUPS/PEERINGTEST/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/{applicationGatewayName}", "operationName": "ApplicationGatewayAccess", "timestamp": "2017-04-26T19:27:38Z", "category": "ApplicationGatewayAccessLog", "properties": { "instanceId": "ApplicationGatewayRole_IN_0", "clientIP": "191.96.249.97", "clientPort": 46886, "httpMethod": "GET", "requestUri": "/phpmyadmin/scripts/setup.php", "requestQuery": "X-AzureApplicationGateway-CACHE-HIT=0&SERVER-ROUTED=10.4.0.4&X-AzureApplicationGateway-LOG-ID=874f1f0f-6807-41c9-b7bc-f3cfa74aa0b1&SERVER-STATUS=404", "userAgent": "-", "httpStatus": 404, "httpVersion": "HTTP/1.0", "receivedBytes": 65, "sentBytes": 553, "timeTaken": 205, "sslEnabled": "off", "host": "www.contoso.com", "originalHost": "www.contoso.com" }}

For Application Gateway and WAF v2, the logs show a little more information:

ValueDescription
instanceIdApplication Gateway instance that served the request.
clientIPOriginating IP for the request.
clientPortOriginating port for the request.
httpMethodHTTP method used by the request.
requestUriURI of the received request.
UserAgentUser agent from the HTTP request header.
httpStatusHTTP status code returned to the client from Application Gateway.
httpVersionHTTP version of the request.
receivedBytesSize of packet received, in bytes.
sentBytesSize of packet sent, in bytes.
timeTakenLength of time (in milliseconds) that it takes for a request to be processed and its response to be sent. This is calculated as the interval from the time when Application Gateway receives the first byte of an HTTP request to the time when the response send operation finishes. It's important to note that the Time-Taken field usually includes the time that the request and response packets are traveling over the network.
sslEnabledWhether communication to the back-end pools used TLS. Valid values are on and off.
sslCipherCipher suite being used for TLS communication (if TLS is enabled).
sslProtocolTLS protocol being used (if TLS is enabled).
serverRoutedThe backend server that application gateway routes the request to.
serverStatusHTTP status code of the backend server.
serverResponseLatencyLatency of the response from the backend server.
hostAddress listed in the host header of the request.
{ "resourceId": "/SUBSCRIPTIONS/{subscriptionId}/RESOURCEGROUPS/PEERINGTEST/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/{applicationGatewayName}", "operationName": "ApplicationGatewayAccess", "time": "2017-04-26T19:27:38Z", "category": "ApplicationGatewayAccessLog", "properties": { "instanceId": "appgw_1", "clientIP": "191.96.249.97", "clientPort": 46886, "httpMethod": "GET", "requestUri": "/phpmyadmin/scripts/setup.php", "userAgent": "-", "httpStatus": 404, "httpVersion": "HTTP/1.0", "receivedBytes": 65, "sentBytes": 553, "timeTaken": 205, "sslEnabled": "off", "sslCipher": "", "sslProtocol": "", "serverRouted": "104.41.114.59:80", "serverStatus": "200", "serverResponseLatency": "0.023", "host": "www.contoso.com", }}

Performance log

The performance log is generated only if you have enabled it on each Application Gateway instance, as detailed in the preceding steps. The data is stored in the storage account that you specified when you enabled the logging. The performance log data is generated in 1-minute intervals. It is available only for the v1 SKU. For the v2 SKU, use Metrics for performance data. The following data is logged:

ValueDescription
instanceIdApplication Gateway instance for which performance data is being generated. For a multiple-instance application gateway, there is one row per instance.
healthyHostCountNumber of healthy hosts in the back-end pool.
unHealthyHostCountNumber of unhealthy hosts in the back-end pool.
requestCountNumber of requests served.
latencyAverage latency (in milliseconds) of requests from the instance to the back end that serves the requests.
failedRequestCountNumber of failed requests.
throughputAverage throughput since the last log, measured in bytes per second.
{ "resourceId": "/SUBSCRIPTIONS/{subscriptionId}/RESOURCEGROUPS/{resourceGroupName}/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/{applicationGatewayName}", "operationName": "ApplicationGatewayPerformance", "time": "2016-04-09T00:00:00Z", "category": "ApplicationGatewayPerformanceLog", "properties": { "instanceId":"ApplicationGatewayRole_IN_1", "healthyHostCount":"4", "unHealthyHostCount":"0", "requestCount":"185", "latency":"0", "failedRequestCount":"0", "throughput":"119427" }}

Note

Latency is calculated from the time when the first byte of the HTTP request is received to the time when the last byte of the HTTP response is sent. It's the sum of the Application Gateway processing time plus the network cost to the back end, plus the time that the back end takes to process the request.

Firewall log

The firewall log is generated only if you have enabled it for each application gateway, as detailed in the preceding steps. This log also requires that the web application firewall is configured on an application gateway. The data is stored in the destination that you specified when you enabled the logging. The following data is logged:

ValueDescription
instanceIdApplication Gateway instance for which firewall data is being generated. For a multiple-instance application gateway, there is one row per instance.
clientIpOriginating IP for the request.
clientPortOriginating port for the request.
requestUriURL of the received request.
ruleSetTypeRule set type. The available value is OWASP.
ruleSetVersionRule set version used. Available values are 2.2.9 and 3.0.
ruleIdRule ID of the triggering event.
messageUser-friendly message for the triggering event. More details are provided in the details section.
actionPolicy Mode: Detection - Detected - This is the only action for the WAF when in detection mode. All the conditions for a given rule were matched and the request was logged then passed to the backend.Policy Mode: Prevention - Allowed - All conditions were matched for a given rule and the request was passed to the backend. - Blocked - All of the conditions were matched for a given rule and the request was blocked. - Matched - One/more conditions were matched for a given rule, but the decision to block or pass the request will need further evaluation and will be evaluated based on the final anomaly scoring rule.
siteSite for which the log was generated. Currently, only Global is listed because rules are global.
detailsDetails of the triggering event.
details.messageDescription of the rule.
details.dataSpecific data found in request that matched the rule.
details.fileConfiguration file that contained the rule.
details.lineLine number in the configuration file that triggered the event.
hostnameHostname or IP address of the Application Gateway.
transactionIdUnique ID for a given transaction which helps group multiple rule violations that occurred within the same request.
policyIdUnique ID of the Firewall Policy associated with the Application Gateway, Listener, or Path.
policyScopeThe location of the policy - values can be "Global", "Listener", or "Location".
policyScopeNameThe name of the object where the policy is applied.
{ "resourceId": "/SUBSCRIPTIONS/{subscriptionId}/RESOURCEGROUPS/{resourceGroupName}/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/{applicationGatewayName}", "operationName": "ApplicationGatewayFirewall", "time": "2017-03-20T15:52:09.1494499Z", "category": "ApplicationGatewayFirewallLog", "properties": { "instanceId": "ApplicationGatewayRole_IN_0", "clientIp": "52.161.109.147", "clientPort": "0", "requestUri": "/", "ruleSetType": "OWASP", "ruleSetVersion": "3.0", "ruleId": "920350", "ruleGroup": "920-PROTOCOL-ENFORCEMENT", "message": "Host header is a numeric IP address", "action": "Matched", "site": "Global", "details": { "message": "Warning. Pattern match \"^[\\\\d.:]+$\" at REQUEST_HEADERS:Host ....", "data": "127.0.0.1", "file": "rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf", "line": "791" }, "hostname": "127.0.0.1", "transactionId": "16861477007022634343", "policyId": "/subscriptions/1496a758-b2ff-43ef-b738-8e9eb5161a86/resourceGroups/drewRG/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/perListener", "policyScope": "Listener", "policyScopeName": "httpListener1" } }}

View and analyze the activity log

You can view and analyze activity log data by using any of the following methods:

  • Azure tools: Retrieve information from the activity log through Azure PowerShell, the Azure CLI, the Azure REST API, or the Azure portal. Step-by-step instructions for each method are detailed in the Activity operations with Resource Manager article.
  • Power BI: If you don't already have a Power BI account, you can try it for free. By using the Power BI template apps, you can analyze your data.

View and analyze the access, performance, and firewall logs

Azure Monitor logs can collect the counter and event log files from your Blob storage account. It includes visualizations and powerful search capabilities to analyze your logs.

You can also connect to your storage account and retrieve the JSON log entries for access and performance logs. After you download the JSON files, you can convert them to CSV and view them in Excel, Power BI, or any other data-visualization tool.

Tip

If you are familiar with Visual Studio and basic concepts of changing values for constants and variables in C#, you can use the log converter tools available from GitHub.

Analyzing Access logs through GoAccess

We have published a Resource Manager template that installs and runs the popular GoAccess log analyzer for Application Gateway Access Logs. GoAccess provides valuable HTTP traffic statistics such as Unique Visitors, Requested Files, Hosts, Operating Systems, Browsers, HTTP Status codes and more. For more details, please see the Readme file in the Resource Manager template folder in GitHub.

Next steps

  • Visualize counter and event logs by using Azure Monitor logs.
  • Visualize your Azure activity log with Power BI blog post.
  • View and analyze Azure activity logs in Power BI and more blog post.
Monitor logs for Azure Web Application Firewall (2024)

FAQs

How do I monitor Azure WAF logs? ›

Access WAF Metrics in Azure portal
  1. From the Azure portal menu, select All Resources >> <your-Application-Gateway-profile>.
  2. Under Monitoring, select Metrics:
  3. In Metrics, select the metric to add:
  4. Select Add filter to add a filter:
  5. Select New chart to add a new chart.
Mar 10, 2023

How do I investigate WAF logs? ›

Resolution
  1. Open the Amazon CloudWatch console.
  2. In the navigation pane, choose Logs, and then choose Log Insights.
  3. For Select log group(s), choose one or more log groups to query that consist of AWS WAF access logs.
  4. (Optional) Choose a time range for the period that you want to query.
  5. Use query syntax to design queries.

How do I monitor application logs in Azure? ›

In the left navigation, click on Diagnose and solve problems – Checkout the tile for “Diagnostic Tools” and “Availability and Performance” > "Application Logs" title. With the new Azure Monitor integration, you can create Diagnostic Settings (preview) to send logs to Storage Accounts, Event Hubs and Log Analytics.

What is Web application firewall logs? ›

The Web App Firewall generates log messages for tracking configuration, policy invocation, and security check violation details.

What are WAF logs? ›

AWS WAF logs include information about the traffic that is analyzed by your web ACL, such as the time that AWS WAF received the request from your AWS resource, detailed information about the request, and the action for the rule that each request matched.

How should firewalls be monitored with logging solutions? ›

Firewall Rule Monitoring

Manual verification is done by looking at the firewall logs to see if the expected traffic is being allowed or denied. Software tools can automate this process by monitoring the firewall in real time and generating alerts when unexpected traffic is detected.

What should I look for in firewall logs? ›

The IP of the source of the connection (your PC), the IP of the destination (your desired recipient, e.g. a webpage), and the port used on your computer. You can use this to identify any ports that need opening for software to work. You should also look out for any suspicious connections, as they may indicate malware.

Where are Azure Monitor logs stored? ›

Logs in Azure Monitor are stored in a Log Analytics workspace that's based on Azure Data Explorer, which provides a powerful analysis engine and rich query language.

How do you get audit logs for Azure Application Gateway? ›

In the Azure portal, find your resource and select Diagnostic settings. For Application Gateway, three logs are available: Access log. Performance log.

How does the WAF detect and respond to attacks? ›

The WAF can analyze the traffic and identify the specific SQL syntax used in the attack. The WAF can then generate policies to block this specific syntax and prevent the attack from succeeding. Once the security policy has been generated, WAF applies the policy to secure the application.

How do I know if a website is behind a WAF? ›

- One of the ways to detect a WAF is manual discovery. You can check the cookies as some WAFs are known to add their cookies during communications between the web server and client. - You can also detect WAFs through headers because many WAF products let headers be rewritten.

What is Azure log Monitor? ›

Azure Monitor Logs is a feature of Azure Monitor that collects and organizes log and performance data from monitored resources.

How does Azure Firewall work? ›

Azure Firewall decrypts outbound traffic, performs required security checks, and then encrypts the traffic to the destination. It works in conjunction with URL filtering and web categories by letting administrators allow or deny user access to website categories such as gambling or social media.

How do I maintain logs in Azure? ›

Best practices when logging in Azure
  1. Use Azure SDKs when implementing the logging system. ...
  2. Log as much as necessary. ...
  3. Include contextual information in your logs. ...
  4. Use structured logging format. ...
  5. Exclude sensitive information. ...
  6. Use the appropriate log level. ...
  7. Centralize all your logs in Azure Monitor.
Nov 23, 2023

How do I enable WAF logs? ›

Turn on AWS WAF logs
  1. Open the AWS WAF console.
  2. For Region, select the AWS Region where you created your web ACL. ...
  3. Select your web ACL.
  4. Choose Logging and Metrics, then choose Enable.
  5. Choose the Destination of where you want to store the AWS WAF logs from the supported destinations.

How do I check my Azure log Analytics? ›

To access Azure Log Analytics, you need to sign in to the Azure portal with your Azure account. Once you're signed in, you can access Log Analytics by selecting it from the list of services in the portal. To use Log Analytics, you need to create a Log Analytics workspace in your Azure subscription.

How do I view logs in Azure Log Analytics? ›

Azure portal: You can view and query your data directly from the Azure portal. Simply go to your Log Analytics Workspace, select the "Logs" option, and start writing queries to retrieve the data you need.

How do I view Azure diagnostic logs? ›

View logs in Log Analytics
  1. From the Azure portal, locate and select Log Analytics from the left-hand navigation menu.
  2. Locate and select the resource you created when enabling diagnostics.
  3. Under General, locate and select Logs. From this page, you can run queries against your logs.
Jan 20, 2024

Top Articles
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 5667

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.