Get all comments in an Azure Sentinel incident programmatically

For any kind of report you may want to get all comments in an Azure Sentinel in order to archive as an forensic or incident artifact in an incident case before it is closed. Even comments in Azure Sentinel is not really much helpful it is still play an important role.

In this article, let’s explore a way to extract all comments in an Azure Sentinel incident. You will be playing with both PowerShell and Azure CLI (+ Curl) to work with Azure Sentinel comment API.

TL;DR: You can skip this article and use this script

Use Case

What is a use case for extracting all comments in an Azure Sentinel incident? There are a few. First, if you don’t have an integration of ticket management system or IM (instant messaging) system you are likely going to have to use Comment feature in Azure Sentinel. This feature is not actually helpful and likely doesn’t satisfy your need but it is still helpful and is needed when you still don’t have a better choice. SecOps analyst would like to have comment before investigating a case. For example give a first-look comment or simply say this is his testing and the incident should be marked as a False Positive case.

You would need to archive everything stored in an Azure Sentinel incident to be an artifact of incident before it is closed. In this case getting all comments in an Azure Sentinel is likely required.

Azure Sentinel Comment API

To use Azure Sentinel comment API, you simply need to call the following URI with GET method:

$uri = "" + $workspaceId `
                                      + "/providers/Microsoft.SecurityInsights/incidents/" `
                                      + $IncidentId `
                                      + "/comments" `
                                      + "?api-version=2021-04-01"
  • WorkspaceId is the Id of the Log Analytics workspace that Azure Sentinel connects to.
  • IncidentId is the ID of the incident you want to get all comments.

Below is the sample JSON converted response when calling Azure Sentinel Comment API:

        "id": "/subscriptions/67d6111d-a99d-4xxxxxxxxxx",
        "name": "8bc3db9f-034b-40df-b2ab-f9b1ea1ea37b",
        "type": "Microsoft.SecurityInsights/Cases/Comments",
        "properties": {
            "message": "Hi Andy. \n\nI looked at the resource and quickly checked log.",
            "createdTimeUtc": "2020-01-27T16:32:46.467213Z",
            "userInfo": "@{objectId=f84a055f-2958-4116-ttc7-7e49baac8cfa; email=; name=Linda Chung}"
        "id": "/subscriptions/67d6111d-a99d-4xxxxxxxxxxxx",
        "name": "f976b609-8e2e-4adf-bd6d-e79a9bcef77d",
        "type": "Microsoft.SecurityInsights/Cases/Comments",
        "properties": {
            "message": "Linda could you help look into this? This seems to be a true positive.",
            "createdTimeUtc": "2020-01-27T16:30:16.5526602Z",
            "userInfo": "@{objectId=b8c7b934-b11b-2256-a089-fb322add2d6c; email=; name=Andy Nguyen}"

For those who are not interested in touching PowerShell, here is a dirty script to achieve similar result with Bash and Azure CLI:

ACCESS_TOKEN=$(az account get-access-token --query 'accessToken' -o tsv)
AUTH_HEADER="Authorization: Bearer $ACCESS_TOKEN"
CONTENT_TYPE="Content-Type: application/json"
WORKSPACE_ID=$(az monitor log-analytics workspace show --resource-group $RG_NAME \
                                                       --workspace-name $WORKSPACE_NAME \
                                                       --query 'id' \
                                                       -o tsv)

You need latest Azure CLI to use az monitor log-analytics workspace

Some of other articles related to Azure Sentinel you might want to check out:

This entry was posted in Security Automation and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.