Azure门户自定义互动程序-降价互动程序
是否可以在azure仪表板中显示自定义信息?Azure门户自定义互动程序-降价互动程序,azure,powershell,azure-automation,azureportal,azure-runbook,Azure,Powershell,Azure Automation,Azureportal,Azure Runbook,是否可以在azure仪表板中显示自定义信息? 我正在搜索如何在azure dashboards中添加自定义内容,但没有找到任何内容。唯一接近的是markdown互动程序,它允许显示html 考虑到这一点,经过大量挖掘,我找到了一个解决方案: 基本上,我们需要一个显示从RESTAPI检索到的数据的自定义磁贴 1。在新的或现有的仪表板上创建一个新的、空的“降价”磁贴,并给它一个“标题” 2。共享仪表板 3。导航到所有服务,按ResourceGroup筛选器中的“dashboards”进行筛选 -单击
我正在搜索如何在azure dashboards中添加自定义内容,但没有找到任何内容。唯一接近的是markdown互动程序,它允许显示html 考虑到这一点,经过大量挖掘,我找到了一个解决方案: 基本上,我们需要一个显示从RESTAPI检索到的数据的自定义磁贴 1。在新的或现有的仪表板上创建一个新的、空的“降价”磁贴,并给它一个“标题” 2。共享仪表板 3。导航到所有服务,按ResourceGroup筛选器中的“dashboards”进行筛选 -单击包含“降价”互动程序的仪表板 -记下“资源ID” 在我们的场景中,我们使用了Azure自动化运行手册。在这个场景中,我们使用了Azure资源管理器REST api 4。创建新的RunBook[Powershell RunBook]
#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
以下步骤涉及以下内容:
-登录到ResourceManagerRapi
-按ID获取Azure资源[上面的资源ID]
-按ID更新Azure资源[上面的资源ID]
在继续之前,我们需要获取客户端凭据。为此:
-单击门户菜单栏中的Cloud Shell
-“az”型
-键入'az ad sp create for rpac-n“runbooks”'//runbooks只是一个名称,请随意输入其他字符串
-上面的命令应该列出所需的凭据。如果发生错误,请联系您的Azure管理员并从他们的帐户运行它
5。在空的powershell runbook中,添加以下两个变量:
$ExpectedTileName = "Extension/HubsExtension/PartType/MarkdownPart"
$MarkdownTileTitle = "<The Markdown title you've set in the first step>"
#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
$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
8。在仪表板内的所有平铺中循环。请注意,磁贴不包含在数组中,因此您可能需要增加/减少for循环的长度。
#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
}
}
总之:
$ExpectedTileName = "Extension/HubsExtension/PartType/MarkdownPart"
$MarkdownTileTitle = "<The Markdown title you've set in the first step>"
#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
$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
$ExpectedTileName=“扩展/轮毂张力/零件类型/MarkdownPart”
$MarkdownTileTitle=“您需要将其分为两部分:问题和答案您是对的,谢谢您的评论。请随意提出门户网站可以做的事情,以使这一点在未来变得更容易:实际上,看起来这可能可以通过允许REST调用的磁贴和将响应格式化为降价的功能来简化。@BrianHauger这就是问题所在,没有允许REST调用的磁贴。此外@BrianHauger我已经订阅了以下线程:但是Azure团队已将其标记为计划外。