|
| 1 | +# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +function Get-MonkeyAZApplicationInsightComponent { |
| 17 | +<# |
| 18 | + .SYNOPSIS |
| 19 | + Azure Collector to get application insight component |
| 20 | +
|
| 21 | + .DESCRIPTION |
| 22 | + Azure Collector to get application insight component |
| 23 | +
|
| 24 | + .INPUTS |
| 25 | +
|
| 26 | + .OUTPUTS |
| 27 | +
|
| 28 | + .EXAMPLE |
| 29 | +
|
| 30 | + .NOTES |
| 31 | + Author : Juan Garrido |
| 32 | + Twitter : @tr1ana |
| 33 | + File Name : Get-MonkeyAZApplicationInsightComponent |
| 34 | + Version : 1.0 |
| 35 | +
|
| 36 | + .LINK |
| 37 | + https://github.com/silverhack/monkey365 |
| 38 | + #> |
| 39 | + |
| 40 | + [CmdletBinding()] |
| 41 | + param( |
| 42 | + [Parameter(Mandatory = $false,HelpMessage = "Background Collector ID")] |
| 43 | + [string]$collectorId |
| 44 | + ) |
| 45 | + Begin { |
| 46 | + #Collector metadata |
| 47 | + $monkey_metadata = @{ |
| 48 | + Id = "az000108"; |
| 49 | + Provider = "Azure"; |
| 50 | + Resource = "Subscription"; |
| 51 | + ResourceType = $null; |
| 52 | + resourceName = $null; |
| 53 | + collectorName = "Get-MonkeyAZApplicationInsightComponent"; |
| 54 | + ApiType = "resourceManagement"; |
| 55 | + description = "Azure Collector to get application insight component"; |
| 56 | + Group = @( |
| 57 | + "Subscription" |
| 58 | + ); |
| 59 | + Tags = @( |
| 60 | + |
| 61 | + ); |
| 62 | + references = @( |
| 63 | + "https://silverhack.github.io/monkey365/" |
| 64 | + ); |
| 65 | + ruleSuffixes = @( |
| 66 | + "az_insight_component" |
| 67 | + ); |
| 68 | + dependsOn = @( |
| 69 | + |
| 70 | + ); |
| 71 | + enabled = $true; |
| 72 | + supportClientCredential = $true |
| 73 | + } |
| 74 | + #Get Config |
| 75 | + $config = $O365Object.internal_config.ResourceManager | Where-Object { $_.Name -eq "azureInsightsComponent" } | Select-Object -ExpandProperty resource |
| 76 | + #Get instances |
| 77 | + $Instances = $O365Object.all_resources.Where({ $_.Id -like '*microsoft.insights/components*' }) |
| 78 | + if (-not $Instances) { continue } |
| 79 | + $AllInstances = $null |
| 80 | + } |
| 81 | + Process { |
| 82 | + $msg = @{ |
| 83 | + MessageData = ($message.MonkeyGenericTaskMessage -f $collectorId,"Azure Insights Component",$O365Object.current_subscription.displayName); |
| 84 | + callStack = (Get-PSCallStack | Select-Object -First 1); |
| 85 | + logLevel = 'info'; |
| 86 | + InformationAction = $InformationAction; |
| 87 | + Tags = @('AzureInsightsInfo'); |
| 88 | + } |
| 89 | + Write-Information @msg |
| 90 | + if ($Instances.Count -gt 0) { |
| 91 | + $new_arg = @{ |
| 92 | + APIVersion = $config.api_version; |
| 93 | + } |
| 94 | + $p = @{ |
| 95 | + ScriptBlock = { Get-MonkeyAzInsightComponentInfo -InputObject $_ }; |
| 96 | + Arguments = $new_arg; |
| 97 | + Runspacepool = $O365Object.monkey_runspacePool; |
| 98 | + ReuseRunspacePool = $true; |
| 99 | + Debug = $O365Object.VerboseOptions.Debug; |
| 100 | + Verbose = $O365Object.VerboseOptions.Verbose; |
| 101 | + MaxQueue = $O365Object.nestedRunspaces.MaxQueue; |
| 102 | + BatchSleep = $O365Object.nestedRunspaces.BatchSleep; |
| 103 | + BatchSize = $O365Object.nestedRunspaces.BatchSize; |
| 104 | + } |
| 105 | + $AllInstances = $Instances | Invoke-MonkeyJob @p |
| 106 | + } |
| 107 | + } |
| 108 | + End { |
| 109 | + if ($AllInstances) { |
| 110 | + $AllInstances.PSObject.TypeNames.Insert(0,'Monkey365.Azure.Application.Insights.Components') |
| 111 | + [pscustomobject]$obj = @{ |
| 112 | + Data = $AllInstances; |
| 113 | + Metadata = $monkey_metadata; |
| 114 | + } |
| 115 | + $returnData.az_insight_component = $obj |
| 116 | + } |
| 117 | + else { |
| 118 | + $msg = @{ |
| 119 | + MessageData = ($message.MonkeyEmptyResponseMessage -f "Azure Insights Component",$O365Object.TenantID); |
| 120 | + callStack = (Get-PSCallStack | Select-Object -First 1); |
| 121 | + logLevel = "verbose"; |
| 122 | + InformationAction = $O365Object.InformationAction; |
| 123 | + Tags = @('AzureInsightsEmptyResponse'); |
| 124 | + Verbose = $O365Object.Verbose; |
| 125 | + } |
| 126 | + Write-Verbose @msg |
| 127 | + } |
| 128 | + } |
| 129 | +} |
0 commit comments