Skip to content

Commit

Permalink
add powershell module and test for alert repair SDK
Browse files Browse the repository at this point in the history
fix spacing

add hasvalidremediationaction check for repair tests

add changelog and update assembly version reference

fix typo

update references
  • Loading branch information
sumitabarahmand committed Nov 15, 2018
1 parent e29868d commit ec97de9
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AzureStack.Management.InfrastructureInsights.Admin, Version=0.2.0-preview">
<HintPath>..\..\..\packages\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.0.2.0-preview\lib\net452\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.dll</HintPath>
<Reference Include="Microsoft.AzureStack.Management.InfrastructureInsights.Admin, Version=0.3.0-preview">
<HintPath>..\..\..\packages\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.0.3.0-preview\lib\net452\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
- Additional information about change #1
-->
## Current Release
## Version 0.3.0
* New admin cmdlet added
* Repair-AzsAlert

## Version 0.2.0
* Module dependencies updated
* AzureRM.Profile
* AzureRM.Resources
* AzureRM.Profile
* AzureRM.Resources
* Support handling names of nested resources
* Get-AzsAlert
* Close-AzsAlert
* Get-AzsRegistrationHealth
* Get-AzsRPHealth
* Get-AzsAlert
* Close-AzsAlert
* Get-AzsRegistrationHealth
* Get-AzsRPHealth
* Deprecations
* Get-AzsRegistrationHealth, the parameter ResourceHealthId is now an alias for Name
* Get-AzsRegistrationHealth, the parameter ServiceRegistrationId is now an alias for ServiceRegistrationName
* Get-AzsRPHealth, the parameter ServiceHealth is now an alias for Name
* Get-AzsRegistrationHealth, the parameter ResourceHealthId is now an alias for Name
* Get-AzsRegistrationHealth, the parameter ServiceRegistrationId is now an alias for ServiceRegistrationName
* Get-AzsRPHealth, the parameter ServiceHealth is now an alias for Name
* Bug fixes
* Handle ErrrorAction correctly now
* Handle ErrrorAction correctly now
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<#
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See License.txt in the project root for license information.
#>

<#
.SYNOPSIS
Repairs the given alert.
.DESCRIPTION
Repairs the given alert.
.PARAMETER Name
The alert identifier.
.PARAMETER Location
Name of the location.
.PARAMETER ResourceGroupName
Resource group name which the resource resides.
.PARAMETER InputObject
An alert returned from Get-AzsAlert.
.PARAMETER Force
Don't ask for confirmation.
.EXAMPLE
PS C:\> Repair-AzsAlert -Name f2147f3d-42ac-4316-8cbc-f0f9c18888b0
Repairs an alert by Name.
.EXAMPLE
PS C:\> Get-AzsAlert -Name f2147f3d-42ac-4316-8cbc-f0f9c18888b0 | Repair-AzsAlert
Repairs an alert through piping.
#>
function Repair-AzsAlert {
[CmdletBinding(DefaultParameterSetName = 'Repair', SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true, ParameterSetName = 'Repair')]
[ValidateNotNullOrEmpty()]
[System.String]
$Name,

[Parameter(Mandatory = $false, ParameterSetName = 'Repair')]
[System.String]
$Location,

[Parameter(Mandatory = $false, ParameterSetName = 'Repair')]
[ValidateLength(1, 90)]
[System.String]
$ResourceGroupName,

[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'InputObject')]
[ValidateNotNullOrEmpty()]
[Microsoft.AzureStack.Management.InfrastructureInsights.Admin.Models.Alert]
$InputObject,

[Parameter(Mandatory = $false)]
[switch]
$Force
)

Begin {
Initialize-PSSwaggerDependencies -Azure
$tracerObject = $null
if (('continue' -eq $DebugPreference) -or ('inquire' -eq $DebugPreference)) {
$oldDebugPreference = $global:DebugPreference
$global:DebugPreference = "continue"
$tracerObject = New-PSSwaggerClientTracing
Register-PSSwaggerClientTracing -TracerObject $tracerObject
}
}

Process {

if ('InputObject' -eq $PsCmdlet.ParameterSetName) {
$GetArmResourceIdParameterValue_params = @{
IdTemplate = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.InfrastructureInsights.Admin/regionHealths/{region}/alerts/{alertName}'
}

$GetArmResourceIdParameterValue_params['Id'] = $InputObject.Id
$ArmResourceIdParameterValues = Get-ArmResourceIdParameterValue @GetArmResourceIdParameterValue_params

$ResourceGroupName = $ArmResourceIdParameterValues['resourceGroupName']
$Location = $ArmResourceIdParameterValues['region']
$Name = $ArmResourceIdParameterValues['alertName']
}

if ($PSCmdlet.ShouldProcess("$Name" , "Repair Alert")) {
if ($Force.IsPresent -or $PSCmdlet.ShouldContinue("Repair Alert?", "Performing operation repair on alert $Name")) {

$NewServiceClient_params = @{
FullClientTypeName = 'Microsoft.AzureStack.Management.InfrastructureInsights.Admin.InfrastructureInsightsAdminClient'
}

$GlobalParameterHashtable = @{}
$NewServiceClient_params['GlobalParameterHashtable'] = $GlobalParameterHashtable

$GlobalParameterHashtable['SubscriptionId'] = $null
if ($PSBoundParameters.ContainsKey('SubscriptionId')) {
$GlobalParameterHashtable['SubscriptionId'] = $PSBoundParameters['SubscriptionId']
}

$InfrastructureInsightsAdminClient = New-ServiceClient @NewServiceClient_params

if ([System.String]::IsNullOrEmpty($Location)) {
$Location = (Get-AzureRMLocation).Location
}

if ([System.String]::IsNullOrEmpty($ResourceGroupName)) {
$ResourceGroupName = "System.$Location"
}

if ('Repair' -eq $PsCmdlet.ParameterSetName -or 'InputObject' -eq $PsCmdlet.ParameterSetName) {
Write-Verbose -Message 'Performing operation RepairWithHttpMessagesAsync on $InfrastructureInsightsAdminClient.'
$TaskResult = $InfrastructureInsightsAdminClient.Alerts.RepairWithHttpMessagesAsync($ResourceGroupName, $Location, $Name)
} else {
Write-Verbose -Message 'Failed to map parameter set to operation method.'
throw 'Module failed to find operation to execute.'
}

if ($TaskResult) {
$GetTaskResult_params = @{
TaskResult = $TaskResult
}

Get-TaskResult @GetTaskResult_params
}
}
}
}

End {
if ($tracerObject) {
$global:DebugPreference = $oldDebugPreference
Unregister-PSSwaggerClientTracing -TracerObject $tracerObject
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AzureStack.Management.InfrastructureInsights.Admin" version="0.2.0-preview" targetFramework="net452" />
<package id="Microsoft.AzureStack.Management.InfrastructureInsights.Admin" version="0.3.0-preview" targetFramework="net452" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AzureStack.Management.InfrastructureInsights.Admin, Version=0.2.0-preview">
<HintPath>..\..\..\packages\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.0.2.0-preview\lib\net452\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.dll</HintPath>
<Reference Include="Microsoft.AzureStack.Management.InfrastructureInsights.Admin, Version=0.3.0-preview">
<HintPath>..\..\..\packages\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.0.3.0-preview\lib\net452\Microsoft.AzureStack.Management.InfrastructureInsights.Admin.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
Loading

0 comments on commit ec97de9

Please sign in to comment.