Skip to content

Commit 6aaa373

Browse files
committed
Add Azure collectors
1 parent 346b6da commit 6aaa373

3 files changed

Lines changed: 69 additions & 78 deletions

File tree

collectors/azure/virtualmachines/disks/Get-MonkeyAZDisk.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function Get-MonkeyAZDisk {
7474
#Get Azure Storage Auth
7575
$AzureDiskConfig = $O365Object.internal_config.ResourceManager | Where-Object { $_.Name -eq "azureDisk" } | Select-Object -ExpandProperty resource
7676
#Get disks
77-
$managed_disks = $O365Object.all_resources.Where({ $_.type -like 'Microsoft.Compute/disks' })
77+
$managed_disks = $O365Object.all_resources.Where({ $_.type -match '^Microsoft\.Compute/disks$' })
7878
if (-not $managed_disks) { continue }
7979
#Set array
8080
$all_managed_disks = $null;

collectors/azure/virtualmachines/virtualmachines/Get-MonkeyAzRMVM.ps1

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,22 @@ function Get-MonkeyAZRMVM {
7474
#Get Config
7575
$AzureVMConfig = $O365Object.internal_config.ResourceManager | Where-Object { $_.Name -eq "azureVm" } | Select-Object -ExpandProperty resource
7676
#Get VMs
77-
$vms_v2 = $O365Object.all_resources.Where({ $_.type -like 'Microsoft.Compute/virtualMachines' })
78-
if (-not $vms_v2) { continue }
79-
#set null
80-
$vms = $null
77+
$virtualMachines = $O365Object.all_resources.Where({ $_.type -match '^Microsoft\.Compute/virtualMachines$' })
8178
}
8279
process {
83-
$msg = @{
84-
MessageData = ($message.MonkeyGenericTaskMessage -f $collectorId,"Azure Virtual machines",$O365Object.current_subscription.displayName);
85-
callStack = (Get-PSCallStack | Select-Object -First 1);
86-
logLevel = 'info';
87-
InformationAction = $O365Object.InformationAction;
88-
Tags = @('AzureVMInfo');
89-
}
90-
Write-Information @msg
91-
if ($vms_v2.Count -gt 0) {
92-
$new_arg = @{
80+
If($virtualMachines.Count -gt 0){
81+
$msg = @{
82+
MessageData = ($message.MonkeyGenericTaskMessage -f $collectorId,"Azure Virtual machines",$O365Object.current_subscription.displayName);
83+
callStack = (Get-PSCallStack | Select-Object -First 1);
84+
logLevel = 'info';
85+
InformationAction = $O365Object.InformationAction;
86+
Tags = @('AzureVMInfo');
87+
}
88+
Write-Information @msg
89+
$new_arg = @{
9390
APIVersion = $AzureVMConfig.api_version;
9491
}
95-
$p = @{
92+
$p = @{
9693
ScriptBlock = { Get-MonkeyAzVirtualMachineInfo -InputObject $_ };
9794
Arguments = $new_arg;
9895
Runspacepool = $O365Object.monkey_runspacePool;
@@ -103,28 +100,26 @@ function Get-MonkeyAZRMVM {
103100
BatchSleep = $O365Object.nestedRunspaces.BatchSleep;
104101
BatchSize = $O365Object.nestedRunspaces.BatchSize;
105102
}
106-
$vms = $vms_v2 | Invoke-MonkeyJob @p
107-
}
108-
}
109-
end {
110-
if ($vms) {
111-
$vms.PSObject.TypeNames.Insert(0,'Monkey365.Azure.VirtualMachines')
112-
[pscustomobject]$obj = @{
113-
Data = $vms;
114-
Metadata = $monkey_metadata;
115-
}
116-
$returnData.az_virtual_machines = $obj
117-
}
118-
else {
119-
$msg = @{
120-
MessageData = ($message.MonkeyEmptyResponseMessage -f "Azure Virtual machines",$O365Object.TenantID);
121-
callStack = (Get-PSCallStack | Select-Object -First 1);
122-
logLevel = "verbose";
123-
InformationAction = $O365Object.InformationAction;
124-
Tags = @('AzureVMEmptyResponse');
125-
Verbose = $O365Object.Verbose;
126-
}
127-
Write-Verbose @msg
103+
$vms = $virtualMachines | Invoke-MonkeyJob @p
104+
If ($vms) {
105+
$vms.PSObject.TypeNames.Insert(0,'Monkey365.Azure.VirtualMachines')
106+
[pscustomobject]$obj = @{
107+
Data = $vms;
108+
Metadata = $monkey_metadata;
109+
}
110+
$returnData.az_virtual_machines = $obj
111+
}
112+
Else {
113+
$msg = @{
114+
MessageData = ($message.MonkeyEmptyResponseMessage -f "Azure Virtual machines",$O365Object.TenantID);
115+
callStack = (Get-PSCallStack | Select-Object -First 1);
116+
logLevel = "verbose";
117+
InformationAction = $O365Object.InformationAction;
118+
Tags = @('AzureVMEmptyResponse');
119+
Verbose = $O365Object.Verbose;
120+
}
121+
Write-Verbose @msg
122+
}
128123
}
129124
}
130125
}

collectors/azure/virtualmachines/virtualmachines/Get-MonkeyAzVMScaleSet.ps1

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Get-MonkeyAzVMScaleSet {
4242
[Parameter(Mandatory = $false,HelpMessage = "Background Collector ID")]
4343
[string]$collectorId
4444
)
45-
begin {
45+
Begin {
4646
#Collector metadata
4747
$monkey_metadata = @{
4848
Id = "az00053";
@@ -52,7 +52,7 @@ function Get-MonkeyAzVMScaleSet {
5252
resourceName = $null;
5353
collectorName = "Get-MonkeyAzVMScaleSet";
5454
ApiType = "resourceManagement";
55-
description = "Collector to get information about Redis instances from Azure";
55+
description = "Collector to get information about Virtual Machines ScaleSet from Azure";
5656
Group = @(
5757
"VirtualMachines"
5858
);
@@ -74,25 +74,23 @@ function Get-MonkeyAzVMScaleSet {
7474
#Get Config
7575
$AzureVMScaleConfig = $O365Object.internal_config.ResourceManager | Where-Object { $_.Name -eq "azureVMScaleSet" } | Select-Object -ExpandProperty resource
7676
#Get vm instances
77-
$vms = $O365Object.all_resources.Where({ $_.Id -like "*Microsoft.Compute/virtualMachineScaleSets*" })
78-
if (-not $vms) { continue }
79-
$AllVMs = $null
77+
$vmScaleSets = $O365Object.all_resources.Where({$_.type -match '^Microsoft\.Compute/virtualMachineScaleSets$'});
8078
}
81-
process {
82-
$msg = @{
83-
MessageData = ($message.MonkeyGenericTaskMessage -f $collectorId,"Azure Virtual Machine scale set",$O365Object.current_subscription.displayName);
84-
callStack = (Get-PSCallStack | Select-Object -First 1);
85-
logLevel = 'info';
86-
InformationAction = $O365Object.InformationAction;
87-
Tags = @('AzureVMInfo');
88-
}
89-
Write-Information @msg
90-
if ($vms) {
91-
$new_arg = @{
79+
Process {
80+
If($vmScaleSets.Count -gt 0){
81+
$msg = @{
82+
MessageData = ($message.MonkeyGenericTaskMessage -f $collectorId,"Azure Virtual Machine scale set",$O365Object.current_subscription.displayName);
83+
callStack = (Get-PSCallStack | Select-Object -First 1);
84+
logLevel = 'info';
85+
InformationAction = $O365Object.InformationAction;
86+
Tags = @('AzureVMInfo');
87+
}
88+
Write-Information @msg
89+
$new_arg = @{
9290
APIVersion = $AzureVMScaleConfig.api_version;
9391
}
94-
$p = @{
95-
ScriptBlock = { Get-MonkeyAzVMScaleSetInfo -InputObject $_ };
92+
$p = @{
93+
ScriptBlock = { Get-MonkeyAzVirtualMachineScaleSetInfo -InputObject $_ };
9694
Arguments = $new_arg;
9795
Runspacepool = $O365Object.monkey_runspacePool;
9896
ReuseRunspacePool = $true;
@@ -102,28 +100,26 @@ function Get-MonkeyAzVMScaleSet {
102100
BatchSleep = $O365Object.nestedRunspaces.BatchSleep;
103101
BatchSize = $O365Object.nestedRunspaces.BatchSize;
104102
}
105-
$AllVMs = $vms | Invoke-MonkeyJob @p
106-
}
107-
}
108-
end {
109-
if ($AllVMs) {
110-
$AllVMs.PSObject.TypeNames.Insert(0,'Monkey365.Azure.VMScaleSet')
111-
[pscustomobject]$obj = @{
112-
Data = $AllVMs;
113-
Metadata = $monkey_metadata;
114-
}
115-
$returnData.az_vm_scaleSet = $obj;
116-
}
117-
else {
118-
$msg = @{
119-
MessageData = ($message.MonkeyEmptyResponseMessage -f "Azure Virtual Machine scale set",$O365Object.TenantID);
120-
callStack = (Get-PSCallStack | Select-Object -First 1);
121-
logLevel = "verbose";
122-
InformationAction = $O365Object.InformationAction;
123-
Tags = @('AzureVMEmptyResponse');
124-
Verbose = $O365Object.Verbose;
125-
}
126-
Write-Verbose @msg
103+
$AllVMs = $vmScaleSets | Invoke-MonkeyJob @p
104+
If ($AllVMs) {
105+
$AllVMs.PSObject.TypeNames.Insert(0,'Monkey365.Azure.VMScaleSet')
106+
[pscustomobject]$obj = @{
107+
Data = $AllVMs;
108+
Metadata = $monkey_metadata;
109+
}
110+
$returnData.az_vm_scaleSet = $obj;
111+
}
112+
Else {
113+
$msg = @{
114+
MessageData = ($message.MonkeyEmptyResponseMessage -f "Azure Virtual Machine scale set",$O365Object.TenantID);
115+
callStack = (Get-PSCallStack | Select-Object -First 1);
116+
logLevel = "verbose";
117+
InformationAction = $O365Object.InformationAction;
118+
Tags = @('AzureVMEmptyResponse');
119+
Verbose = $O365Object.Verbose;
120+
}
121+
Write-Verbose @msg
122+
}
127123
}
128124
}
129125
}

0 commit comments

Comments
 (0)