3

Is it possible to show custom information in azure dashboards? I was searching on how to add custom content in azure dashboards but did not find anything. The only thing close was the markdown tile which allows html to be displayed.

Dash
  • 401
  • 5
  • 14

1 Answers1

3

With this in mind and after a lot of digging I found a solution:

Basically we needed a custom tile that displays data retrieved from our REST api.

1. Create a new, empty 'Markdown' tile on a new or existing dashboard, give it a 'Title'

2. Share the dashboard

3. Navigate to All services, Filter by 'dashboards' in the ResourceGroup filter - Click on the dashboard which contains the 'Markdown' tile - Take a note of the 'RESOURCE ID'

In our scenario, we used Azure Automation Runbooks. In this scenario we utilized the Azure Resource Manager REST api.

4. Create a new RunBook [Powershell Runbook]

The following steps concern the following: - Login to the ResourceManagerAPI - Get Azure Resource by ID [The Resource ID above] - Update Azure Resource by ID [The Resource ID above]

Before we continue, we need to get our client credentials. To do so: - Click on Cloud Shell in the Portal Menu bar - Type 'az' - Type 'az ad sp create-for-rpac -n "runbooks"' //runbooks is just a name, feel free to input a different string - The above command should list out the credentials needed. If an error occurs, kindly contact your Azure admin and run it from their account.

5. In your empty powershell runbook, add the following 2 variables:

$ExpectedTileName = "Extension/HubsExtension/PartType/MarkdownPart"
$MarkdownTileTitle = "<The Markdown title you've set in the first step>"

6. Getting the Access_Token [The variables <> represent the values retrieved from the previous step]

#Get Bearer Token
$TenantId = '<Your tenantID>'
$LoginUri = "https://login.microsoftonline.com/"+$TenantId+"/oauth2/token"
$params = @{
"grant_type"="client_credentials";
"client_id"="<appId>";
"client_secret"="<password>";
"resource"="https://management.azure.com";
}
$LoginResponse = Invoke-RestMethod -Uri $LoginUri -Method Post -Body $params
$Access_Token = $LoginResponse.access_token;
$Access_TokenString = "Bearer " + $Access_Token

7. Getting the DashboardResource by ResourceID:

#Get Resource
$RMUri = "https://management.azure.com/"+ $DashboardId +"?api-version=2015-08-01-preview"
$DashboardResource = (Invoke-RestMethod -Uri $RMUri -Method Get -Headers @{'Authorization'=$Access_TokenString}) | ConvertTo-Json -Depth 100 | ConvertFrom-Json

8. Looping through all tiles within the dashboard. Please note that tiles are not contained within an array, thus you may need to increase/decrease the length of the for loop.

#Loop through all tiles within the dashboard
$Parts = $DashboardResource.properties.lenses.0.0.parts
For ($i=0; $i -lt 200; $i++)
{    
    $Part = $Parts | Select-Object -Property $i.toString()
    if($Part.$i)
    {   
        if($Part.$i.metadata.type -eq $ExpectedTileName -And $Part.$i.metadata.settings.content.settings.title -eq $MarkdownTileTitle)
        {   
            $Part.$i.metadata.settings.content.settings.content = <CustomValue ex: invoke a get request to your api>
        }        
    }
    else
    {
        break
    }
}

9. Finally we need to update the dashboard resource

#Update Resource
$UpdateUri = "https://management.azure.com/"+ $DashboardId +"?api-version=2015-08-01-preview"
$JsonValue = $DashboardResource | ConvertTo-Json -Depth 100
Invoke-RestMethod -Uri $UpdateUri -Method Put -Headers @{'Authorization'=$Access_TokenString; 'Content-type'='application/json'} -Body $JsonValue

To sum it up:

$ExpectedTileName = "Extension/HubsExtension/PartType/MarkdownPart"
$MarkdownTileTitle = "<The Markdown title you've set in the first step>"

#Get Bearer Token
$TenantId = '<Your subscriptionID>'
$LoginUri = "https://login.microsoftonline.com/"+$TenantId+"/oauth2/token"
$params = @{
"grant_type"="client_credentials";
"client_id"="<appId>";
"client_secret"="<password>";
"resource"="https://management.azure.com";
}
$LoginResponse = Invoke-RestMethod -Uri $LoginUri -Method Post -Body $params
$Access_Token = $LoginResponse.access_token;
$Access_TokenString = "Bearer " + $Access_Token

#Get Resource
$RMUri = "https://management.azure.com/"+ $DashboardId +"?api-version=2015-08-01-preview"
$DashboardResource = (Invoke-RestMethod -Uri $RMUri -Method Get -Headers @{'Authorization'=$Access_TokenString}) | ConvertTo-Json -Depth 100 | ConvertFrom-Json

#Loop through all tiles within the dashboard
$Parts = $DashboardResource.properties.lenses.0.0.parts
For ($i=0; $i -lt 200; $i++)
{    
    $Part = $Parts | Select-Object -Property $i.toString()
    if($Part.$i)
    {   
        if($Part.$i.metadata.type -eq $ExpectedTileName -And $Part.$i.metadata.settings.content.settings.title -eq $MarkdownTileTitle)
        {   
            $Part.$i.metadata.settings.content.settings.content = <CustomValue ex: invoke a get request to your api>
        }        
    }
    else
    {
        break
    }
}

#Update Resource
$UpdateUri = "https://management.azure.com/"+ $DashboardId +"?api-version=2015-08-01-preview"
$JsonValue = $DashboardResource | ConvertTo-Json -Depth 100
Invoke-RestMethod -Uri $UpdateUri -Method Put -Headers @{'Authorization'=$Access_TokenString; 'Content-type'='application/json'} -Body $JsonValue

Conclusion With this newly created runbook we can now schedule it to run every 1 hour. In our case, 1 hour was too much. The following article shows how we can schedule the runbook to run every 1 minute.

https://blogs.technet.microsoft.com/stefan_stranger/2017/06/21/azure-scheduler-schedule-your-runbooks-more-often-than-every-hour/

Dash
  • 401
  • 5
  • 14
  • Feel free to suggest things that the portal could do to make this easier in the future here: https://feedback.azure.com/forums/223579-azure-portal – Brian Hauger Jan 23 '19 at 04:37
  • Actually, it looks like this could probably be simplified by a tile that allows a REST call and the ability to format the response into markdown. – Brian Hauger Jan 23 '19 at 04:48
  • @BrianHauger That's the problem, there are no tiles that allow REST calls. – Dash Jan 24 '19 at 07:09
  • Furthermore @BrianHauger I am already subscribed to the following thread: https://feedback.azure.com/forums/223579-azure-portal/suggestions/13208379-create-custom-tiles But the Azure team have marked it as Unplanned. – Dash Jan 24 '19 at 12:26