From 89bb9704dfb1967e48625b8a5d3fffb19a1c25d6 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 24 Feb 2019 20:18:02 -0500 Subject: [PATCH] Create Set-ZertoAlert function and tests --- Tests/Public/Set-ZertoAlert.Tests.ps1 | 22 ++++++++++++ ZertoApiWrapper/Public/Get-ZertoAlert.ps1 | 4 +-- ZertoApiWrapper/Public/Set-ZertoAlert.ps1 | 42 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Tests/Public/Set-ZertoAlert.Tests.ps1 create mode 100644 ZertoApiWrapper/Public/Set-ZertoAlert.ps1 diff --git a/Tests/Public/Set-ZertoAlert.Tests.ps1 b/Tests/Public/Set-ZertoAlert.Tests.ps1 new file mode 100644 index 0000000..adb2af4 --- /dev/null +++ b/Tests/Public/Set-ZertoAlert.Tests.ps1 @@ -0,0 +1,22 @@ +$moduleFileName = "ZertoApiWrapper.psm1" +$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' +$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' +$modulePath = $filePath -replace "Public", "" +Import-Module $modulePath\$moduleFileName -Force + +$userName = "zerto\build" +$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force +$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) + +# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml +$zertoServer = "192.168.1.100" +$zertoPort = "7669" + +Describe "Set-ZertoAlert" { + it "file should exist" { + "$filePath\$fileName" | should exist + } + it "module should have a function called Set-ZertoAlert" { + get-command Connect-ZertoServer | should be $true + } +} \ No newline at end of file diff --git a/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 b/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 index 0b5287d..d5d5469 100644 --- a/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoAlert.ps1 @@ -69,9 +69,9 @@ function Get-ZertoAlert { [string]$entity, [Parameter( ParameterSetName = "filter", - HelpMessage = "Returns alerts that are dismissed" + HelpMessage = 'Returns alerts that are dismissed when set to $true an undismissed alerts when set to $false' )] - [switch]$isDismissed + [bool]$isDismissed ) begin { diff --git a/ZertoApiWrapper/Public/Set-ZertoAlert.ps1 b/ZertoApiWrapper/Public/Set-ZertoAlert.ps1 new file mode 100644 index 0000000..93bd96e --- /dev/null +++ b/ZertoApiWrapper/Public/Set-ZertoAlert.ps1 @@ -0,0 +1,42 @@ +function Set-ZertoAlert { + [cmdletbinding( SupportsShouldProcess = $true )] + param ( + [Alias("identifier")] + [Parameter( + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + Mandatory = $true, + HelpMessage = "Alert identifier(s) to be dismissed or undismissed." + )] + [string[]]$alertId, + [Parameter( + ParameterSetName = "dismiss", + Mandatory = $true, + HelpMessage = "Will dismiss the selected alert." + )] + [switch]$dismiss, + [Parameter( + ParameterSetName = "undismiss", + Mandatory = $true, + HelpMessage = "Will undismiss the selected alert." + )] + [switch]$undismiss + ) + + begin { + $baseUri = "alerts" + } + + process { + foreach ($id in $alertId) { + $uri = "{0}/{1}/{2}" -f $baseUri, $id, $PSCmdlet.ParameterSetName + if ($PSCmdlet.ShouldProcess($PSCmdlet.ParameterSetName + " alertId $id")) { + Invoke-ZertoRestRequest -uri $uri -method "POST" | Out-Null + } + } + } + + end { + # Nothing to do. + } +} \ No newline at end of file