Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Author Hilko Krueger
- # QUIBIQ Hamburg GmbH
- # License MIT
- $json = Get-Content 'C:\xxxx\OMS\alerts.json' | Out-String | ConvertFrom-Json
- $searchNames = $($json.searches | Get-Member -MemberType *Property)
- $tenentID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- $appUser = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- $appUserPassword = "xxxxxxxxxxxxx"
- $subscriptionID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- armclient spn $tenentID $appUser $appUserPassword
- foreach ($search in $searchNames) {
- $searchValue = ($json.searches | Select-Object -ExpandProperty $search.Name)
- # create a search or update a search
- $savedSearchParametersJson = $searchValue.data | ConvertTo-Json -Depth 50 | % { [System.Text.RegularExpressions.Regex]::Unescape($_) }
- $savedSearchParametersJson = [System.Text.RegularExpressions.Regex]::Replace($savedSearchParametersJson, '"', "'")
- $savedSearchResponse = armclient put /subscriptions/$($subscriptionID)/resourceGroups/mms-weu/providers/Microsoft.OperationalInsights/workspaces/NordexTest/savedSearches/$($search.Name)?api-version=2015-03-20 "$savedSearchParametersJson" | Out-String | ConvertFrom-Json
- # no etag = ERROR
- if(!$savedSearchResponse.PSObject.Properties.Match('etag').Count) {
- Write-Error "Error with newSearchsearch: $($search.Name) Payload $($savedSearchParametersJson)"
- exit
- }
- Write-Output "Added Search $($search.Name)"
- $schedules = $($searchValue.schedules | Get-Member -MemberType *Property)
- foreach ($schedule in $schedules) {
- $scheduleValue = ($searchValue.schedules | Select-Object -ExpandProperty $schedule.Name)
- # create a search or update a search
- $scheduleJson = $scheduleValue.data | ConvertTo-Json -Depth 50 | % { [System.Text.RegularExpressions.Regex]::Unescape($_) }
- $scheduleJson = [System.Text.RegularExpressions.Regex]::Replace($scheduleJson, '"', "'")
- $savedScheduleResponse = armclient put /subscriptions/$($subscriptionID)/resourceGroups/mms-weu/providers/Microsoft.OperationalInsights/workspaces/NordexTest/savedSearches/$($search.Name)/schedules/$($schedule.Name)?api-version=2015-03-20 "$scheduleJson" | Out-String | ConvertFrom-Json
- # no etag = ERROR
- if(!$savedScheduleResponse.PSObject.Properties.Match('etag').Count) {
- Write-Error "Error with newSchedule: $($schedule.Name) in search: $($search.Name) Payload $($scheduleJson) Response: $($savedScheduleResponse)"
- exit
- }
- Write-Output "Added Schedule $($schedule.Name)"
- $actions = $($scheduleValue.actions | Get-Member -MemberType *Property)
- foreach ($action in $actions) {
- $actionValue = ($scheduleValue.actions | Select-Object -ExpandProperty $action.Name)
- # create a search or update a search
- $actionJson = $actionValue | ConvertTo-Json -Depth 50 | % { [System.Text.RegularExpressions.Regex]::Unescape($_) }
- $actionJson = [System.Text.RegularExpressions.Regex]::Replace($actionJson, '"', "'")
- $savedActionResponse = armclient put /subscriptions/$($subscriptionID)/resourceGroups/mms-weu/providers/Microsoft.OperationalInsights/workspaces/NordexTest/savedSearches/$($search.Name)/schedules/$($schedule.Name)/Actions/$($action.Name)?api-version=2015-03-20 "$actionJson" | Out-String | ConvertFrom-Json
- # no etag = ERROR
- if(!$savedActionResponse.PSObject.Properties.Match('etag').Count) {
- Write-Error "Error with newSchedule: $($schedule.Name) in search: $($action.Name) Payload $($actionJson) Response: $($savedActionResponse)"
- exit
- }
- Write-Output "Added Action $($action.Name)"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement