From fb14b760d46ce4a23b7e8ce42a247dff3395e426 Mon Sep 17 00:00:00 2001 From: Olli Janatuinen Date: Wed, 31 Jul 2019 09:20:44 +0300 Subject: [PATCH] Added support for services New functions: - Add-NSLBServiceMonitorBinding - Get-NSLBService - Get-NSLBServiceMonitorBinding - New-NSLBService - Remove-NSLBService - Remove-NSLBServiceMonitorBinding - Set-NSLBService --- NetScaler/NetScaler.psd1 | 7 + .../Public/Add-NSLBServiceMonitorBinding.ps1 | 118 +++++++ NetScaler/Public/Get-NSLBService.ps1 | 69 ++++ .../Public/Get-NSLBServiceMonitorBinding.ps1 | 67 ++++ NetScaler/Public/New-NSLBService.ps1 | 323 ++++++++++++++++++ NetScaler/Public/Remove-NSLBService.ps1 | 70 ++++ .../Remove-NSLBServiceMonitorBinding.ps1 | 75 ++++ NetScaler/Public/Set-NSLBService.ps1 | 253 ++++++++++++++ 8 files changed, 982 insertions(+) create mode 100644 NetScaler/Public/Add-NSLBServiceMonitorBinding.ps1 create mode 100644 NetScaler/Public/Get-NSLBService.ps1 create mode 100644 NetScaler/Public/Get-NSLBServiceMonitorBinding.ps1 create mode 100644 NetScaler/Public/New-NSLBService.ps1 create mode 100644 NetScaler/Public/Remove-NSLBService.ps1 create mode 100644 NetScaler/Public/Remove-NSLBServiceMonitorBinding.ps1 create mode 100644 NetScaler/Public/Set-NSLBService.ps1 diff --git a/NetScaler/NetScaler.psd1 b/NetScaler/NetScaler.psd1 index ab00b0a..45023ac 100644 --- a/NetScaler/NetScaler.psd1 +++ b/NetScaler/NetScaler.psd1 @@ -72,6 +72,7 @@ FunctionsToExport = @( 'Add-NSDnsNameServer', 'Add-NSDnsSuffix', 'Add-NSIPResource', + 'Add-NSLBServiceMonitorBinding', 'Add-NSLBServiceGroupMonitorBinding', 'Add-NSLBSSLVirtualServerCertificateBinding', 'Add-NSLBVirtualServerBinding', @@ -123,6 +124,8 @@ FunctionsToExport = @( 'Get-NSKCDAccount', 'Get-NSLBMonitor', 'Get-NSLBServer', + 'Get-NSLBService', + 'Get-NSLBServiceMonitorBinding', 'Get-NSLBServiceGroup', 'Get-NSLBServiceGroupMemberBinding', 'Get-NSLBServiceGroupMonitorBinding', @@ -168,6 +171,7 @@ FunctionsToExport = @( 'New-NSKCDAccount', 'New-NSLBMonitor', 'New-NSLBServer', + 'New-NSLBService', 'New-NSLBServiceGroup', 'New-NSLBServiceGroupMember', 'New-NSLBServiceGroupMonitor', @@ -187,6 +191,8 @@ FunctionsToExport = @( 'Remove-NSDnsSuffix', 'Remove-NSLBMonitor', 'Remove-NSLBServer', + 'Remove-NSLBService', + 'Remove-NSLBServiceMonitorBinding', 'Remove-NSLBServiceGroup', 'Remove-NSLBServiceGroupMonitorBinding', 'Remove-NSLBSSLVirtualServerProfile', @@ -204,6 +210,7 @@ FunctionsToExport = @( 'Save-NSConfig', 'Set-NSHostname', 'Set-NSLBServer', + 'Set-NSLBService', 'Set-NSLBServiceGroup', 'Set-NSLBSSLVirtualServer', 'Set-NSLBSSLVirtualServerProfile', diff --git a/NetScaler/Public/Add-NSLBServiceMonitorBinding.ps1 b/NetScaler/Public/Add-NSLBServiceMonitorBinding.ps1 new file mode 100644 index 0000000..ff94e9f --- /dev/null +++ b/NetScaler/Public/Add-NSLBServiceMonitorBinding.ps1 @@ -0,0 +1,118 @@ +<# +Copyright 2019 Olli Janatuinen + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#> + +function Add-NSLBServiceMonitorBinding { + <# + .SYNOPSIS + Adds a new service monitor binding. + + .DESCRIPTION + Adds a new service monitor binding. + + .EXAMPLE + Add-NSLBServiceMonitorBinding -ServiceName 'sg01' -MonitorName 'mon01' + + Bind the monitor 'mon01' to service 'sg01'. + + .EXAMPLE + Add-NSLBServiceMonitorBinding -ServiceName 'sg01' -MonitorName 'mon01' -Force -PassThru + + Bind the monitor 'mon01' to service 'sg01'', suppress the confirmation and return the result. + + .PARAMETER Session + The NetScaler session object. + + .PARAMETER ServiceName + Name of the service to bind the monitor to. + + .PARAMETER MonitorName + Name of the monitor to bind to the service. + + .PARAMETER Port + Port number of the service. Each service must have a unique port number. + + Range: 1 - 65535 + + .PARAMETER State + Initial state of the service after binding. + + Default value: ENABLED + Possible values: ENABLED, DISABLED + + .PARAMETER Weight + Weight to assign to the servers in the service. Specifies the capacity of the servers relative to the other servers in the load balancing configuration. The higher the weight, the higher the percentage of requests sent to the service. + + Range: 1 - 100 + + .PARAMETER Force + Suppress confirmation when binding the certificate key to the virtual server. + + .PARAMETER Passthru + Return the load balancer server object. + #> + [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] + param( + $Session = $script:session, + + [parameter(Mandatory)] + [string]$ServiceName, + + [parameter(Mandatory)] + [string]$MonitorName, + + [ValidateSet('ENABLED','DISABLED')] + [string]$State = 'ENABLED', + + [ValidateRange(1,100)] + [int]$Weight, + + [ValidateRange(1,65535)] + [int]$Port, + + [Switch]$Force, + + [Switch]$PassThru + ) + + begin { + _AssertSessionActive + } + + process { + if ($Force -or $PSCmdlet.ShouldProcess($ServiceName, 'Add Monitor Binding')) { + try { + $params = @{ + name = $ServiceName + monitor_name = $MonitorName + } + if ($PSBoundParameters.ContainsKey('Weight')) { + $params.Add('weight', $Weight) + } + if ($PSBoundParameters.ContainsKey('Port')) { + $params.Add('port', $Port) + } + + _InvokeNSRestApi -Session $Session -Method PUT -Type service_lbmonitor_binding -Payload $params + + if ($PSBoundParameters.ContainsKey('PassThru')) { + return Get-NSLBServiceMonitorBinding -Session $Session -Name $ServiceName + } + } catch { + throw $_ + } + } + } +} \ No newline at end of file diff --git a/NetScaler/Public/Get-NSLBService.ps1 b/NetScaler/Public/Get-NSLBService.ps1 new file mode 100644 index 0000000..75f501c --- /dev/null +++ b/NetScaler/Public/Get-NSLBService.ps1 @@ -0,0 +1,69 @@ +<# +Copyright 2019 Olli Janatuinen + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#> + +function Get-NSLBService { + <# + .SYNOPSIS + Gets the specified load balancer service object. + + .DESCRIPTION + Gets the specified load balancer service object. + + .EXAMPLE + Get-NSLBService + + Get all load balancer service objects. + + .EXAMPLE + Get-NSLBService -Name 'sg01' + + Get the load balancer service named 'sg01'. + + .PARAMETER Session + The NetScaler session object. + + .PARAMETER Name + The name or names of the load balancer service to get. + #> + [cmdletbinding()] + param( + $Session = $script:session, + + [parameter(ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName)] + [string[]]$Name = @() + ) + + begin { + _AssertSessionActive + $services = @() + } + + process { + if ($Name.Count -gt 0) { + foreach ($item in $Name) { + $services = _InvokeNSRestApi -Session $Session -Method Get -Type service -Action Get -Resource $item + if ($Services.psobject.properties.name -contains 'service') { + return $services.service + } + } + } else { + $services = _InvokeNSRestApi -Session $Session -Method Get -Type service -Action Get + if ($Services.psobject.properties.name -contains 'service') { + return $services.service + } + } + } +} \ No newline at end of file diff --git a/NetScaler/Public/Get-NSLBServiceMonitorBinding.ps1 b/NetScaler/Public/Get-NSLBServiceMonitorBinding.ps1 new file mode 100644 index 0000000..60287b6 --- /dev/null +++ b/NetScaler/Public/Get-NSLBServiceMonitorBinding.ps1 @@ -0,0 +1,67 @@ +<# +Copyright 2019 Olli Janatuinen + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#> + +function Get-NSLBServiceMonitorBinding { + <# + .SYNOPSIS + Gets the service binding for a service. + + .DESCRIPTION + Gets the service binding for a service. + + .EXAMPLE + Get-NSLBServiceMonitorBinding -Name $sg + + Gets the service bindings for the 'sg' service. + + .PARAMETER Session + The NetScaler session object. + + .PARAMETER Name + The name or names of the service to get the service member binding for. + + .PARAMETER MonitorName + Filters the returned monitors to only include the name specified + #> + [cmdletbinding()] + param( + $Session = $script:session, + + [parameter(Mandatory, ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName)] + [string[]]$Name, + + [parameter()] + [string]$MonitorName + ) + + begin { + _AssertSessionActive + } + + process { + try { + # Contruct a filter hash if we specified any filters + $Filters = @{} + if ($PSBoundParameters.ContainsKey('MonitorName')) { + $Filters['monitor_name'] = $MonitorName + } + _InvokeNSRestApiGet -Session $Session -Type service_lbmonitor_binding -Name $Name -Filters $Filters + } + catch { + throw $_ + } + } +} diff --git a/NetScaler/Public/New-NSLBService.ps1 b/NetScaler/Public/New-NSLBService.ps1 new file mode 100644 index 0000000..3a2d573 --- /dev/null +++ b/NetScaler/Public/New-NSLBService.ps1 @@ -0,0 +1,323 @@ +<# +Copyright 2019 Olli Janatuinen + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#> + +function New-NSLBService { + <# + .SYNOPSIS + Adds a load balancer service. + + .DESCRIPTION + Adds a load balancer service. + + .EXAMPLE + New-NSLBService -Name 'sg01' + + Creates a new service called 'sg01' + + .EXAMPLE + 'sg01' | New-NSLBService -ServiceType HTTP -Comment 'test service' + + Creates a new HTTP service called 'sg01' with a comment. + + .PARAMETER Session + The NetScaler session object. + + .PARAMETER Name + The name of the service to create. + + .PARAMETER ServerName + The name of the backend server. + + .PARAMETER ServiceType + Protocol used to exchange data with the service. + + .PARAMETER TrafficDomainId + Integer value that uniquely identifies the traffic domain in which you want to configure the entity. + If you do not specify an ID, the entity becomes part of the default traffic domain, which has an ID of 0. + + .PARAMETER Port + TCP port. + + .PARAMETER CacheType + Cache type supported by the cache server. + + .PARAMETER Cacheable + Use the transparent cache redirection virtual server to forward the request to the cache server. + Note: Do not set this parameter if you set the Cache Type. + Default value: NO + Possible values = YES, NO + + .PARAMETER State + Initial state of the service. + Default value: ENABLED + Possible values = ENABLED, DISABLED + + .PARAMETER HealthMonitor + Monitor the health of this service. + Available settings function as follows: + YES - Send probes to check the health of the service. + NO - Do not send probes to check the health of the service. + With the NO option, the appliance shows the service as UP at all times. + Default value: YES + Possible values = YES, NO + + .PARAMETER AppFlowLog + Enable logging of AppFlow information for the specified service. + Default value: ENABLED + Possible values = ENABLED, DISABLED + + .PARAMETER Comment + Any information about the service. + + .PARAMETER SureConnect + State of the SureConnect feature for the service. + Default value: OFF + Possible values = ON, OFF + + .PARAMETER SurgeProtection + Enable surge protection for the service. + Default value: OFF + Possible values = ON, OFF + + .PARAMETER UseProxyPort + Use the proxy port as the source port when initiating connections with the server. + With the NO setting, the client-side connection port is used as the source port for the server-side connection. + Note: This parameter is available only when the Use Source IP (USIP) parameter is set to YES. + Possible values = YES, NO + + .PARAMETER DownStateFlush + Flush all active transactions associated with all the services in the service whose state transitions from UP to DOWN. + Note: Do not enable this option for applications that must complete their transactions. + Default value: ENABLED + Possible values = ENABLED, DISABLED + + .PARAMETER UseClientIP + Use client's IP address as the source IP address when initiating connection to the server. + With the NO setting, which is the default, a mapped IP (MIP) address or subnet IP (SNIP) address + is used as the source IP address to initiate server side connections. + Possible values = YES, NO + + .PARAMETER ClientKeepAlive + Enable client keep-alive for the service. + Possible values = YES, NO + + .PARAMETER TCPBuffering + Enable TCP buffering for the service. + Possible values = YES, NO + + .PARAMETER HTTPCompression + Enable compression for the specified service. + Possible values = YES, NO + + .PARAMETER ClientIP + Insert the Client IP header in requests forwarded to the service. + Possible values = ENABLED, DISABLED + + .PARAMETER ClientIPHeader + Name of the HTTP header whose value must be set to the IP address of the client. + Used with the Client IP parameter. If client IP insertion is enabled, and the + client IP header is not specified, the value of Client IP Header parameter or the + value set by the set ns config command is used as client's IP header name. + Minimum length = 1 + + .PARAMETER MaxBandwithKbps + Maximum bandwidth, in Kbps, allocated for all the services in the service. + Minimum value = 0 + Maximum value = 4294967287 + + .PARAMETER MonitorThreshold + Minimum sum of weights of the monitors that are bound to this service. + Used to determine whether to mark a service as UP or DOWN. + Minimum value = 0 + Maximum value = 65535 + + .PARAMETER MaxRequests + Maximum number of requests that can be sent on a persistent connection to the service. + Note: Connection requests beyond this value are rejected. + Minimum value = 0 + Maximum value = 65535 + + .PARAMETER MaxClients + Maximum number of simultaneous open connections for the service. + Minimum value = 0 + Maximum value = 4294967294 + + .PARAMETER ClientIdleTimeout + Time, in seconds, after which to terminate an idle client connection. + Minimum value = 0 + Maximum value = 31536000 + + .PARAMETER ServerIdleTimeout + Time, in seconds, after which to terminate an idle server connection. + Minimum value = 0 + Maximum value = 31536000 + + .PARAMETER Passthru + Return the newly created service. + #> + [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='Low')] + param( + $Session = $script:session, + + [parameter(Mandatory, ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName = $true)] + [string[]]$Name = (Read-Host -Prompt 'LB service name'), + + [parameter(Mandatory, Position = 1)] + [string]$ServerName = (Read-Host -Prompt 'Server name'), + + [ValidateSet('ADNS','ADNS_TCP','ANY','DHCPRA','DIAMETER','DNS','DNS_TCP','DTLS','FTP','HTTP','MSSQL','MYSQL','NNTP','RADIUS','RDP','RPCSVR','RTSP','SIP_UDP','SNMP','SSL','SSL_BRIDGE','SSL_DIAMETER','SSL_TCP','TCP','TFTP','UDP')] + [Alias('Protocol')] + [string]$ServiceType = 'HTTP', + + [ValidateRange(0, 4094)] + [int]$TrafficDomainId, + + [ValidateRange(1, 65535)] + [int]$Port, + + [ValidateSet('SERVER', 'FORWARD', 'TRANSPARENT', 'REVERSE')] + [string]$CacheType, + + [ValidateSet('NO', 'YES')] + [string]$Cacheable = 'NO', + + [ValidateSet('ENABLED', 'DISABLED')] + [string]$State = 'ENABLED', + + [ValidateSet('NO', 'YES')] + [string]$HealthMonitor = 'YES', + + [ValidateSet('DISABLED', 'ENABLED')] + [string]$AppFlowLog = 'ENABLED', + + [ValidateLength(0, 256)] + [string]$Comment = [string]::Empty, + + [ValidateSet('ON', 'OFF')] + [string]$SureConnect = 'OFF', + + [ValidateSet('ON', 'OFF')] + [string]$SurgeProtection = 'OFF', + + [ValidateSet('YES','NO')] + [string]$UseProxyPort = 'YES', + + [ValidateSet('ENABLED','DISABLED')] + [string]$DownStateFlush = 'ENABLED', + + [ValidateSet('YES','NO')] + [string]$UseClientIP = 'NO', + + [ValidateSet('YES','NO')] + [string]$ClientKeepAlive = 'NO', + + [ValidateSet('YES', 'NO')] + [string]$TCPBuffering = 'NO', + + [ValidateSet('YES', 'NO')] + [string]$HTTPCompression = 'YES', + + [ValidateSet('ENABLED','DISABLED')] + [string]$ClientIP = 'DISABLED', + + [string]$ClientIPHeader, + + [ValidateRange(0, 4294967287)] + [int]$MaxBandwithKbps, + + [ValidateRange(0, 65535)] + [int]$MonitorThreshold, + + [ValidateRange(0, 65535)] + [int]$MaxRequests, + + [ValidateRange(0, 4294967294)] + [int]$MaxClients, + + [ValidateRange(0, 31536000)] + [int]$ClientIdleTimeout = 180, + + [ValidateRange(0, 31536000)] + [int]$ServerIdleTimeout = 360, + + [Switch]$PassThru + ) + + begin { + _AssertSessionActive + } + + process { + foreach ($item in $Name) { + if ($PSCmdlet.ShouldProcess($item, 'Create Service')) { + try { + $params = @{ + name = $item + servername = $ServerName + servicetype = $ServiceType + port = $Port + state = $State + comment = $Comment + cacheable = $Cacheable + healthmonitor = $HealthMonitor + appflowlog = $AppFlowLog + sc = $SureConnect + sp = $SurgeProtection + useproxyport = $UseProxyPort + downstateflush = $DownStateFlush + usip = $UseClientIP + cka = $ClientKeepAlive + tcpb = $TCPBuffering + cip = $ClientIP + clttimeout = $ClientIdleTimeout + svrtimeout = $ServerIdleTimeout + } + if ($PSBoundParameters.ContainsKey('HTTPCompression')) { + $params.Add('cmp', $HTTPCompression) + } + if ($PSBoundParameters.ContainsKey('TrafficDomainId')) { + $params.Add('td', $TrafficDomainId) + } + if ($PSBoundParameters.ContainsKey('CacheType')) { + $params.Add('cachetype', $CacheType) + } + if ($ClientIP -eq 'ENABLED') { + $params.Add('cipheader', $ClientIPHeader) + } + if ($PSBoundParameters.ContainsKey('MaxBandwithKbps')) { + $params.Add('maxbandwidth', $MaxBandwithKbps) + } + if ($PSBoundParameters.ContainsKey('MonitorThreshold')) { + $params.Add('monthreshold', $MonitorThreshold) + } + if ($PSBoundParameters.ContainsKey('MaxRequests')) { + $params.Add('maxreq', $MaxRequests) + } + if ($PSBoundParameters.ContainsKey('MaxClients')) { + $params.Add('maxclient', $MaxClients) + } + _InvokeNSRestApi -Session $Session -Method POST -Type service -Payload $params -Action add + + if ($PSBoundParameters.ContainsKey('PassThru')) { + return Get-NSLBService -Session $Session -Name $item + } + } catch { + throw $_ + } + } + } + } +} \ No newline at end of file diff --git a/NetScaler/Public/Remove-NSLBService.ps1 b/NetScaler/Public/Remove-NSLBService.ps1 new file mode 100644 index 0000000..bd2daf5 --- /dev/null +++ b/NetScaler/Public/Remove-NSLBService.ps1 @@ -0,0 +1,70 @@ +<# +Copyright 2019 Olli Janatuinen + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#> + +function Remove-NSLBService { + <# + .SYNOPSIS + Removes a load balancer service. + + .DESCRIPTION + Removes a load balancer service. + + .EXAMPLE + Remove-NSLBService -Name 'sg01' + + Removes the load balancer service named 'sg01'. + + .EXAMPLE + 'sg01', 'sg02' | Remove-NSLBService + + Removes the load balancer services named 'sg01' and 'sg02'. + + .PARAMETER Session + The NetScaler session object. + + .PARAMETER Name + The name or names of the load balancer service to get. + + .PARAMETER Force + Suppress confirmation when removing a load balancer service. + #> + [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='High')] + param( + $Session = $script:session, + + [parameter(Mandatory,ValueFromPipeline = $true, ValueFromPipelineByPropertyName)] + [Alias('servicename')] + [string[]]$Name = (Read-Host -Prompt 'LB service name'), + + [switch]$Force + ) + + begin { + _AssertSessionActive + } + + process { + foreach ($item in $Name) { + if ($Force -or $PSCmdlet.ShouldProcess($item, 'Delete Service')) { + try { + _InvokeNSRestApi -Session $Session -Method DELETE -Type service -Resource $item -Action delete + } catch { + throw $_ + } + } + } + } +} \ No newline at end of file diff --git a/NetScaler/Public/Remove-NSLBServiceMonitorBinding.ps1 b/NetScaler/Public/Remove-NSLBServiceMonitorBinding.ps1 new file mode 100644 index 0000000..b803b73 --- /dev/null +++ b/NetScaler/Public/Remove-NSLBServiceMonitorBinding.ps1 @@ -0,0 +1,75 @@ +<# +Copyright 2019 Olli Janatuinen + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#> + +function Remove-NSLBServiceMonitorBinding { + <# + .SYNOPSIS + Removes a monitor binding from a service. + + .DESCRIPTION + Removes a monitor binding from a service. + + .PARAMETER Session + The NetScaler session object. + + .PARAMETER Name + The name of the service to unbind the monitor. + + .PARAMETER MonitorName + The name of the monitor to unbind. + + .EXAMPLE + Remove-NSLBServiceMonitorBinding -Name 'sg01' -MonitorName 'mon01' + + Unbinds the monitor named 'mon01' from the service 'sg01'. + + .PARAMETER Force + Suppress confirmation when removing a responder action. + #> + [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] + param( + $Session = $script:session, + + [parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [alias('ServiceName')] + [string[]]$Name, + + [parameter(Mandatory = $true, ValueFromPipeline = $true)] + [string]$MonitorName, + + [switch]$Force + ) + + begin { + _AssertSessionActive + } + + process { + + $params =@{ + monitor_name = $MonitorName + } + foreach ($item in $Name) { + if ($Force -or $PSCmdlet.ShouldProcess($item, 'Delete Monitor Binding')) { + try { + _InvokeNSRestApi -Session $Session -Method DELETE -Type service_lbmonitor_binding -Resource $item -Arguments $params -Action delete + } catch { + throw $_ + } + } + } + } +} diff --git a/NetScaler/Public/Set-NSLBService.ps1 b/NetScaler/Public/Set-NSLBService.ps1 new file mode 100644 index 0000000..bbeb498 --- /dev/null +++ b/NetScaler/Public/Set-NSLBService.ps1 @@ -0,0 +1,253 @@ +<# +Copyright 2019 Olli Janatuinen + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#> + +function Set-NSLBService { + <# + .SYNOPSIS + Updates an existing load balancer virtual server. + + .DESCRIPTION + Updates an existing load balancer virtual server. + + .EXAMPLE + Set-NSLBService -Name 'sg01' -Comment 'This is a comment' + + Sets the comment for virtual server 'sg01'. + + .EXAMPLE + Set-NSLBService -Name 'sg01' HTTPCompression = 'ON' + + Enable the HTTP compression feature for service 'sg01'. + + .EXAMPLE + Set-NSLBService -Name 'sg01' MaxBandwithKbps 819200 + + Set the maximum bandwidth for service 'sg01' to 819200 Kbps. + + .PARAMETER Session + The NetScaler session object. + + .PARAMETER Name + The name or names of the services to update. + + .PARAMETER Cacheable + Use the transparent cache redirection virtual server to forward the request to the cache server. + + .PARAMETER HealthMonitor + Monitor the health of this service. + + .PARAMETER AppFlowLog + Enable logging of AppFlow information. + + .PARAMETER Comment + The comment associated with the virtual server. + + .PARAMETER SureConnect + State of the SureConnect feature. + + .PARAMETER SurgeProtection + Enable surge protection. + + .PARAMETER UseProxyPort + Use the proxy port as the source port when initiating connections with the server. + + .PARAMETER DownStateFlush + Flush all active transactions associated with all the services in the service whose state transitions from UP to DOWN. + + .PARAMETER UseClientIP + Use client's IP address as the source IP address when initiating connection to the server. + + .PARAMETER TCPBuffering + Enable TCP buffering for the service. + + .PARAMETER HTTPCompression + Enable compression. + + .PARAMETER ClientIP + Insert the Client IP header in requests forwarded to the service. + + .PARAMETER ClientIPHeader + Name of the HTTP header whose value must be set to the IP address of the client. + + .PARAMETER MaxBandwithKbps + Maximum bandwidth, in Kbps, allocated for all the services in the service. + + .PARAMETER MonitorThreshold + Minimum sum of weights of the monitors that are bound to this service. + + .PARAMETER MaxRequests + Maximum number of requests that can be sent on a persistent connection to the service. + + .PARAMETER MaxClients + Maximum number of simultaneous open connections for the service. + + .PARAMETER ClientIdleTimeout + Time, in seconds, after which to terminate an idle client connection. + + .PARAMETER ServerIdleTimeout + Time, in seconds, after which to terminate an idle server connection. + + .PARAMETER Force + Suppress confirmation when updating a service. + + .PARAMETER Passthru + Return the service object. + #> + [cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='Medium')] + param( + $Session = $script:session, + + [parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName)] + [Alias('ServiceName')] + [string[]]$Name = (Read-Host -Prompt 'LB service name'), + + [ValidateSet('NO', 'YES')] + [string]$Cacheable = 'NO', + + [ValidateSet('NO', 'YES')] + [string]$HealthMonitor = 'YES', + + [ValidateSet('DISABLED', 'ENABLED')] + [string]$AppFlowLog = 'ENABLED', + + [string]$Comment, + + [ValidateSet('ON', 'OFF')] + [string]$SureConnect = 'OFF', + + [ValidateSet('ON', 'OFF')] + [string]$SurgeProtection = 'OFF', + + [ValidateSet('YES','NO')] + [string]$UseProxyPort = 'YES', + + [ValidateSet('ENABLED','DISABLED')] + [string]$DownStateFlush = 'ENABLED', + + [ValidateSet('YES','NO')] + [string]$UseClientIP = 'NO', + + [ValidateSet('YES', 'NO')] + [string]$TCPBuffering = 'NO', + + [ValidateSet('YES', 'NO')] + [string]$HTTPCompression = 'YES', + + [ValidateSet('ENABLED','DISABLED')] + [string]$ClientIP = 'DISABLED', + + [string]$ClientIPHeader, + + [ValidateRange(0, 4294967287)] + [int]$MaxBandwithKbps, + + [ValidateRange(0, 65535)] + [int]$MonitorThreshold, + + [ValidateRange(0, 65535)] + [int]$MaxRequests, + + [ValidateRange(0, 4294967294)] + [int]$MaxClients, + + [ValidateRange(0, 31536000)] + [int]$ClientIdleTimeout = 180, + + [ValidateRange(0, 31536000)] + [int]$ServerIdleTimeout = 360, + + [Switch]$Force, + + [Switch]$PassThru + ) + + begin { + _AssertSessionActive + } + + process { + foreach ($item in $Name) { + if ($Force -or $PSCmdlet.ShouldProcess($item, 'Edit Service')) { + $params = @{ + name = $item + } + if ($PSBoundParameters.ContainsKey('Cacheable')) { + $params.Add('cacheable', $Cacheable) + } + if ($PSBoundParameters.ContainsKey('HealthMonitor')) { + $params.Add('healthmonitor', $HealthMonitor) + } + if ($PSBoundParameters.ContainsKey('AppFlowLog')) { + $params.Add('appflowlog', $AppFlowLog) + } + if ($PSBoundParameters.ContainsKey('Comment')) { + $params.Add('comment', $Comment) + } + if ($PSBoundParameters.ContainsKey('SureConnect')) { + $params.Add('sc', $SureConnect) + } + if ($PSBoundParameters.ContainsKey('SurgeProtection')) { + $params.Add('sp', $SurgeProtection) + } + if ($PSBoundParameters.ContainsKey('UseProxyPort')) { + $params.Add('useproxyport', $UseProxyPort) + } + if ($PSBoundParameters.ContainsKey('DownStateFlush')) { + $params.Add('downstateflush', $DownStateFlush) + } + if ($PSBoundParameters.ContainsKey('UseClientIP')) { + $params.Add('usip', $UseClientIP) + } + if ($PSBoundParameters.ContainsKey('TCPBuffering')) { + $params.Add('tcpb', $TCPBuffering) + } + if ($PSBoundParameters.ContainsKey('HTTPCompression')) { + $params.Add('cmp', $HTTPCompression) + } + if ($PSBoundParameters.ContainsKey('ClientIP')) { + $params.Add('cip', $ClientIP) + } + if ($ClientIP -eq 'ENABLED') { + $params.Add('cipheader', $ClientIPHeader) + } + if ($PSBoundParameters.ContainsKey('MaxBandwithKbps')) { + $params.Add('maxbandwitch', $MaxBandwithKbps) + } + if ($PSBoundParameters.ContainsKey('MonitorThreshold')) { + $params.Add('monthreshold', $MonitorThreshold) + } + if ($PSBoundParameters.ContainsKey('MaxRequests')) { + $params.Add('maxreq', $MaxRequests) + } + if ($PSBoundParameters.ContainsKey('MaxClients')) { + $params.Add('maxclient', $MaxClients) + } + if ($PSBoundParameters.ContainsKey('ClientIdleTimeout')) { + $params.Add('clttimeout', $ClientIdleTimeout) + } + if ($PSBoundParameters.ContainsKey('ServerIdleTimeout')) { + $params.Add('svrtimeout', $ServerIdleTimeout) + } + + _InvokeNSRestApi -Session $Session -Method PUT -Type service -Payload $params + + if ($PSBoundParameters.ContainsKey('PassThru')) { + return Get-NSLBService -Session $Session -Name $item + } + } + } + } +} \ No newline at end of file