Created
April 5, 2022 12:34
-
-
Save Panzerbjrn/a7290cc473d4634ce061c7d2d55b0086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
runId: 0 | |
azureResourceManagerConnection: '' | |
subscriptionId: '' | |
artifactName: '' | |
resourcesLocation: '' | |
deployKeyVault: false | |
deployStorage: false | |
deployManagement: false | |
deployDashboards: false | |
deployAlerts: false | |
steps: | |
- task: PowerShell@2 | |
displayName: Deploying Data Collection Rule | |
inputs: | |
targetType: 'inline' | |
script: | | |
Install-Module Az.Resources,Az.Storage,Az.OperationalInsights,Az.Monitor -Scope CurrentUser -AllowClobber -Force | |
$ResourceGroup = "${{ parameters.resourcegroup }}" | |
$Storageaccount = "${{ parameters.storageaccount }}" | |
$Region = "${{ parameters.region }}" | |
$RuleName = "${{ parameters.rulename }}" | |
$WorkSpacename = "${{ parameters.workspacename }}" | |
$Location = (Get-AzLocation | Where-Object {$_.DisplayName -eq $Region}).Location | |
try { | |
Get-AzResourceGroup -Name $ResourceGroup -ErrorAction Stop -Verbose | |
} catch { | |
Write-Output $($PSITEM) | |
Write-Output "$ResourceGroup Doesn't Exist" | |
} | |
try { | |
$LAW = Get-AzOperationalInsightsWorkSpace -ResourceGroupName $ResourceGroup -Name $WorkSpacename -ErrorAction Stop -Verbose | |
} catch { | |
Write-Output $($PSITEM) | |
Write-Output "WorkSpacename $WorkSpacename Doesn't Exist" | |
} | |
$Cid = $LAW.Customerid | |
$Rid = $LAW.ResourceId | |
$tmp = @" | |
{ | |
"properties": { | |
"dataSources": { | |
"performanceCounters": [ | |
{ | |
"streams": [ | |
"Microsoft-InsightsMetrics" | |
], | |
"scheduledTransferPeriod": "PT1M", | |
"samplingFrequencyInSeconds": 10, | |
"counterSpecifiers": [ | |
"\\Processor Information(_Total)\\% Processor Time" | |
], | |
"name": "perfCounter01" | |
} | |
] | |
}, | |
"destinations": { | |
"azureMonitorMetrics": { | |
"name": "azureMonitorMetrics-default" | |
} | |
}, | |
"dataFlows": [ | |
{ | |
"streams": [ | |
"Microsoft-InsightsMetrics" | |
], | |
"destinations": [ | |
"azureMonitorMetrics-default" | |
] | |
} | |
] | |
} | |
} | |
"@ | |
$TMP | Add-Content "$(Agent.BuildDirectory)/Rules.json" | |
IF(Test-Path "$(Agent.BuildDirectory)/Rules.json"){Write-Output "Rules.json exists"} | |
ELSE{Write-Output "Rules.json Doesn't exist"} | |
$NewAzDataCollectionRuleSplat = @{ | |
Location = $Region | |
ResourceGroupName = $ResourceGroup | |
RuleName = $RuleName | |
RuleFile = "$(Agent.BuildDirectory)/Rules.json" | |
Description = 'Dcr description' | |
} | |
$NewAzDataCollectionRuleSplat | |
New-AzDataCollectionRule @NewAzDataCollectionRuleSplat | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment