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 = $true, ParameterSetName = 'snmp')] [switch]$snmp, [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" } 'snmp' { $apiver = "rest/v2.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 } 'snmp' { $response | Select-Object -ExcludeProperty links, link # servers -ExppandProperty servers } '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 } } } } <# { "description": "Existing access hosts, users and traphosts will be replaced by new input, or reset to default if not explicitly specified", "type": "object", "properties": { "enable": { "description": "True: enable; false: disable", "type": "boolean" }, "general_info": { "type": "object", "properties": { "system_contact": { "type": "string" }, "system_location": { "type": "string" }, "system_notes": { "type": "string" } } }, "v2c_access_hosts": { "type": "array", "minItems": 0, "items": { "required": [ "community", "access" ], "type": "object", "properties": { "community": { "type": "string" }, "access": { "description": "SNMP access type", "enum": [ "read-write", "read-only" ], "type": "string" }, "hosts": { "type": "array", "minItems": 0, "items": { "type": "string" } } } } }, "v3_users": { "type": "array", "minItems": 0, "items": { "required": [ "name", "access" ], "type": "object", "properties": { "name": { "maxLength": 32, "minLength": 8, "pattern": "[^:]", "type": "string" }, "access": { "description": "SNMP access type", "enum": [ "read-write", "read-only" ], "type": "string" }, "auth_protocol": { "description": "Authentication protocol type", "enum": [ "SHA1", "SHA256", "MD5" ], "type": "string" }, "auth_key": { "maxLength": 1023, "minLength": 8, "type": "string" }, "priv_protocol": { "description": "Privacy Protocol type", "enum": [ "AES", "DES" ], "type": "string" }, "priv_key": { "maxLength": 1023, "minLength": 8, "type": "string" } } } }, "v2c_traphosts": { "type": "array", "minItems": 0, "items": { "required": [ "trap_host", "community" ], "type": "object", "properties": { "trap_host": { "required": [ "host" ], "type": "object", "properties": { "host": { "maxLength": 1023, "type": "string" }, "port": { "format": "int32", "minimum": 1, "maximum": 65535, "type": "integer" } } }, "community": { "type": "string" } } } }, "v3_traphosts": { "type": "array", "minItems": 0, "items": { "required": [ "trap_host", "user" ], "type": "object", "properties": { "trap_host": { "required": [ "host" ], "type": "object", "properties": { "host": { "maxLength": 1023, "type": "string" }, "port": { "format": "int32", "minimum": 1, "maximum": 65535, "type": "integer" } } }, "user": { "type": "string" } } } } } }#> function Set-DDsnmpservice { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'v2c_access_hosts')] [Parameter(Mandatory = $true, ParameterSetName = 'v2c_traphosts')] [string[]]$hosts, [Parameter(Mandatory = $true, ParameterSetName = 'v2c_traphosts')] [string]$traphost, [Parameter(Mandatory = $true, ParameterSetName = 'v2c_traphosts')] [int]$port, [Parameter(Mandatory = $true, ParameterSetName = 'v2c_access_hosts')] [Parameter(Mandatory = $true, ParameterSetName = 'v2c_traphosts')] [string][ValidateSet('read-write', 'read-only')]$access, [Parameter(Mandatory = $true, ParameterSetName = 'v2c_access_hosts')] [Parameter(Mandatory = $true, ParameterSetName = 'v2c_traphosts')] [string]$community, $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "PUT" } process { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/services/snmp" $json = @{} switch ($PsCmdlet.ParameterSetName) { 'v2c_access_hosts' { $json.Add($PsCmdlet.ParameterSetName, @()) $json.$($PsCmdlet.ParameterSetName) += @{ 'access' = $access 'community' = $community 'hosts' = @($hosts) } } 'v2c_traphosts' { $json.Add('v2c_access_hosts', @()) $json.v2c_access_hosts += @{ 'access' = $access 'community' = $community 'hosts' = @($hosts) } $json.Add($PsCmdlet.ParameterSetName, @()) $json.$($PsCmdlet.ParameterSetName) += @{ 'community' = $community 'trap_host' = @{ 'host' = $traphost 'port' = $port } } } } $json = $json | ConvertTo-Json -Depth 4 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 } } } } |