Modules/services.psm1
# GET/rest/v1.0/dd-systems/{SYSTEM-ID}/services/ntp function Get-DDServices { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'ntp')] [switch]$ntp, [Parameter(Mandatory = $true, ParameterSetName = 'asup')] [switch]$asup, [Parameter(Mandatory = $false, ParameterSetName = 'asup')] [Parameter(Mandatory = $false, ParameterSetName = 'default')] [Parameter(Mandatory = $false, ParameterSetName = 'ntp')] $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "GET" } process { $uri = "dd-systems/$($SYSTEM_ID)/services/$($PsCmdlet.ParameterSetName)" switch ($PsCmdlet.ParameterSetName) { 'default' { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/services" } 'ntp' { $apiver = "rest/v1.0" } 'asup' { $apiver = "api/v2" } } $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.services | Select-Object -ExcludeProperty link } 'ntp' { $response | Select-Object -ExcludeProperty links, link, servers -ExppandProperty servers } 'asup' { $response | Select-Object -ExcludeProperty links, link, serversservers } } } } # /rest/v2.0/dd-systems/{SYSTEM-ID}/services/ntp function Set-DDntpservice { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'delete_servers')] [switch]$delete_servers, [Parameter(Mandatory = $true, ParameterSetName = 'add_servers')] [switch]$add_servers, [Parameter(Mandatory = $true, ParameterSetName = 'add_servers')] [Parameter(Mandatory = $true, ParameterSetName = 'delete_servers')] [string[]]$servers, [Parameter(Mandatory = $true, ParameterSetName = 'disable')] [switch]$disable, [Parameter(Mandatory = $true, ParameterSetName = 'enable')] [switch]$enable, $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "PUT" } process { $apiver = "rest/v2.0" $uri = "dd-systems/$($SYSTEM_ID)/services/ntp" $json = @{operation = $PsCmdlet.ParameterSetName } switch ($PsCmdlet.ParameterSetName) { { ($_ -eq 'add_servers') -or ($_ -eq 'delete_servers') } { $json.Add('servers', @{'server' = $servers }) } } $json = $json | ConvertTo-Json Write-Verbose ($json | out-string) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $json 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 | Select-Object * -ExcludeProperty links, link, servers -ExpandProperty servers } } } } function Set-DDAutoSupport { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [switch]$alertsummary, [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [switch]$detailedAutoSupport, [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [switch]$sendReport, [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] $mailSubjectTag, [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [string[]]$subscriberEmails, [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [string][ValidateSet('daily', 'never', 'custom')]$frequency = 'daily', [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [string[]][ValidateSet( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" )]$days = 'Mon', [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [int][Validaterange(0, 23)]$hours = 6, [Parameter(Mandatory = $false, ParameterSetName = 'detailedAutoSupport')] [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [int][ValidateRange(0, 59)]$minutes = 0 , [Parameter(Mandatory = $false, ParameterSetName = 'alertSummary')] [string][ValidateSet('text', 'html')]$format = 'text', $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "PUT" } process { $apiver = "api/v2" $uri = "dd-systems/$($SYSTEM_ID)/services/asup" $json = @{} if ($mailSubjectTag) { $json.Add('mailSubjectTag', $mailSubjectTag) } if ($sendReport.IsPresent) { $json.Add('sendReport', $sendReport.IsPresent) } # creating body by pset switch ($PsCmdlet.ParameterSetName) { 'alertSummary' { $json.Add('alertSummary', @{}) if ($subscriberEmails) { $json.alertSummary.Add('subscriberEmails', $subscriberEmails) } $json.alertSummary.Add('format', $format) $json.alertSummary.Add('schedule', @{}) $json.alertSummary.schedule.Add('frequency', $frequency) if ($frequency -ne 'never') { $json.alertSummary.schedule.Add('time', @{}) $json.alertSummary.schedule.time.Add('hours', $hours) $json.alertSummary.schedule.time.Add('minutes', $minutes) if ($frequency -eq "custom") { $json.alertSummary.schedule.Add('days', $days) } } } 'detailedAutoSupport' { $json.Add('detailedAutoSupport', @{}) if ($subscriberEmails) { $json.detailedAutoSupport.Add('subscriberEmails', $subscriberEmails) } $json.detailedAutoSupport.Add('schedule', @{}) $json.detailedAutoSupport.schedule.Add('frequency', $frequency) if ($frequency -ne 'never') { $json.detailedAutoSupport.schedule.Add('time', @{}) $json.detailedAutoSupport.schedule.time.Add('hours', $hours) $json.detailedAutoSupport.schedule.time.Add('minutes', $minutes) if ($frequency -eq "custom") { $json.detailedAutoSupport.schedule.Add('days', $days) } } } } $json = $json | ConvertTo-Json -Depth 5 Write-Verbose ($json | out-string) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $json 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 | Select-Object -ExcludeProperty link } } } } |