Modules/alerts.psm1
# /rest/v1.0/dd-systems/{SYSTEM-ID}/alerts function Get-DDAlerts { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'byID')] [string]$id, [Parameter(Mandatory = $false, ParameterSetName = 'byID')] [Parameter(Mandatory = $false, ParameterSetName = 'default')] [string] $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "GET" } process { switch ($PsCmdlet.ParameterSetName) { default { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/alerts" } 'byID' { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/alerts/$ID" } } $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'default' { $response.alert_list | Select-Object -ExcludeProperty links, link, -Property *,@{N="alert_gen";E={(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($_.alert_gen_epoch))}},@{N="clear";E={(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($_.clear_epoch))}} } 'byID' { $response[-1] | Select-Object -Property * -ExcludeProperty link } } } } |