Skip to content

Commit a2df8e8

Browse files
committed
Merge pull request #5 from dbroeglin/feature/new-nsresponderaction
Added Get/New/Set/Remove-NSResponderAction
2 parents aae1f26 + 2373389 commit a2df8e8

6 files changed

Lines changed: 471 additions & 1 deletion

File tree

NetScaler/NetScaler.psd1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ FunctionsToExport = @(
109109
'Get-NSLBStat',
110110
'Get-NSLBVirtualServer',
111111
'Get-NSLBVirtualServerBinding',
112+
'Get-NSResponderAction',
112113
'Get-NSMode',
113114
'Install-NSLicense',
114115
'Invoke-Nitro',
@@ -117,17 +118,20 @@ FunctionsToExport = @(
117118
'New-NSLBServiceGroup',
118119
'New-NSLBServiceGroupMember',
119120
'New-NSLBVirtualServer',
121+
'New-NSResponderAction',
120122
'Remove-NSLBMonitor',
121123
'Remove-NSLBServer',
122124
'Remove-NSLBServiceGroup',
123125
'Remove-NSLBVirtualServer',
124126
'Remove-NSLBVirtualServerBinding',
127+
'Remove-NSResponderAction',
125128
'Restart-NetScaler',
126129
'Save-NSConfig',
127130
'Set-NSHostname',
128131
'Set-NSLBServer',
129132
'Set-NSLBServiceGroup',
130133
'Set-NSLBVirtualServer',
134+
'Set-NSResponderAction',
131135
'Set-NSTimeZone'
132136
)
133137

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<#
2+
Copyright 2016 Dominique Broeglin
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#>
16+
17+
function Get-NSResponderAction {
18+
<#
19+
.SYNOPSIS
20+
Gets the specified responder action object.
21+
22+
.DESCRIPTION
23+
Gets the specified responder action object.
24+
25+
.EXAMPLE
26+
Get-NSResponderAction
27+
28+
Get all responder action objects
29+
30+
.EXAMPLE
31+
Get-NSReponderAction -Name 'act-redirect'
32+
33+
Get the responder action named act-redirect.
34+
35+
.EXAMPLE
36+
Get-NSReponderAction -Name /redir/
37+
38+
Get all the responder actions whose name matches '.*redir.*' (NS treats this as a regex).
39+
40+
.PARAMETER Session
41+
The NetScaler session object.
42+
43+
.PARAMETER Name
44+
A filter to apply to the responder action name value.
45+
46+
.PARAMETER Type
47+
A filter to apply to the responder action type value.
48+
49+
.PARAMETER Target
50+
A filter to apply to the responder action target (expression) value.
51+
52+
.PARAMETER HtmlPage
53+
A filter to apply to the responder action html page value.
54+
55+
.PARAMETER ResponseStatusCode
56+
A filter to apply to the responder action response status code value.
57+
58+
.PARAMETER Hits
59+
A filter to apply to the responder action hits value.
60+
61+
.PARAMETER UndefHits
62+
A filter to apply to the responder action undefined hits value.
63+
64+
.PARAMETER ReferenceCount
65+
A filter to apply to the responder action reference count value.
66+
67+
#>
68+
[cmdletbinding()]
69+
param(
70+
$Session = $script:session,
71+
72+
[Parameter(Position=0)]
73+
[string]$Name,
74+
75+
[string]$Type,
76+
77+
[Alias('Expression')]
78+
[string]$Target,
79+
80+
[string]$HtmlPage,
81+
82+
[string]$ResponseStatusCode,
83+
84+
[string]$Hits,
85+
86+
[Alias('UndefinedHits')]
87+
[string]$UndefHits,
88+
89+
[string]$ReferenceCount
90+
)
91+
92+
begin {
93+
_AssertSessionActive
94+
$response = @()
95+
}
96+
97+
process {
98+
# Contruct a filter hash if we specified any filters
99+
$filters = @{}
100+
"Name","Type","Target","HtmlPage","ResponseStatusCode","Hits","UndefHits","ReferenceCount" | ForEach {
101+
if ($PSBoundParameters.ContainsKey($_)) {
102+
$filters[$_.ToLower()] = (Get-Variable -Name $_).Value
103+
}
104+
}
105+
106+
$response = _InvokeNSRestApi -Session $Session -Method Get -Type responderaction -Action Get -Filters $filters
107+
if ($response.errorcode -ne 0) { throw $response }
108+
if ($response.psobject.properties | where name -eq responderaction) {
109+
return $response.responderaction
110+
}
111+
}
112+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<#
2+
Copyright 2016 Dominique Broeglin
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#>
16+
17+
function New-NSResponderAction {
18+
<#
19+
.SYNOPSIS
20+
Adds a responder action.
21+
22+
.DESCRIPTION
23+
Adds a responder action.
24+
25+
.EXAMPLE
26+
New-NSResponderAction -Name 'act-redirect' -Type Redirect `
27+
-Target '"https://" + HTTP.REQ.HOSTNAME.HTTP_URL_SAFE + "/test/"' -ResponseStatusCode 302
28+
29+
Creates a new responder action which redirects to /test
30+
31+
.PARAMETER Session
32+
The NetScaler session object.
33+
34+
.PARAMETER Name
35+
The name of responder action.
36+
37+
.PARAMETER Type
38+
The type of responder action to create.
39+
40+
Default value: NOOP
41+
Possible values = NOOP, Redirect, RespondWith, RespondWithSQLOK, RespondWithSQLError, RespondWithHTMLPage
42+
43+
.PARAMETER Target
44+
The target expression for the responder action.
45+
Valid only for types NOOP, Redirect and RespondWith.
46+
47+
.PARAMETER ResponseStatusCode
48+
The HTTP response status code returned by the responder action.
49+
Valid only for types Redirect, RespondWith, RespondWithSQLOK and RespondWithSQLError.
50+
51+
Range: 100 - 599
52+
53+
.PARAMETER ReasonPhrase
54+
The Reason Phrase returned with the HTTP status code.
55+
Valid only for types Redirect, RespondWith, RespondWithSQLOK and RespondWithSQLError.
56+
57+
Minimum length: 0
58+
Maximum length: 8191
59+
60+
.PARAMETER HtmlPage
61+
The name of the HTML page to respond with.
62+
63+
Valid only for type RespondWithHTMLPage.
64+
65+
.PARAMETER Comment
66+
Any information about the responder action.
67+
68+
Minimum length: 0
69+
Maximum length: 256
70+
71+
.PARAMETER Passthru
72+
Return the newly created responder action.
73+
#>
74+
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='Low')]
75+
param(
76+
$Session = $script:session,
77+
78+
[parameter(Mandatory, ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
79+
[string[]]$Name,
80+
81+
[ValidateSet('NOOP','Redirect','RespondWith', 'RespondWithSQLOK','RespondWithSQLError','RespondWithHTMLPage')]
82+
[string]$Type = 'NOOP',
83+
84+
[ValidateLength(0, 8191)]
85+
[Alias('Expression')]
86+
[string]$Target = [string]::Empty,
87+
88+
[ValidateRange(100, 599)]
89+
[int]$ResponseStatusCode,
90+
91+
[ValidateLength(0, 8191)]
92+
[string]$ReasonPhrase = [string]::Empty,
93+
94+
[ValidateLength(0, 256)]
95+
[string]$Comment = [string]::Empty,
96+
97+
[Switch]$PassThru
98+
)
99+
100+
begin {
101+
_AssertSessionActive
102+
}
103+
104+
process {
105+
foreach ($Item in $Name) {
106+
if ($PSCmdlet.ShouldProcess($Item, 'Create responder action')) {
107+
try {
108+
$NitroType = $(
109+
switch ($Type) {
110+
"RespondWithSQLOK" { "sqlresponse_ok" }
111+
"RespondWithSQLError" { "sqlresponse_error" }
112+
"RespondWithHTMLPage" { "respondwithhtmlpage"}
113+
default { $Type.ToLower() }
114+
}
115+
)
116+
117+
$params = @{
118+
name = $Item
119+
type = $NitroType
120+
comment = $Comment
121+
}
122+
switch -regex ($Type) {
123+
"^(noop|redirect|respondwith)$" {
124+
if ($PSBoundParameters.ContainsKey('Target')) {
125+
$params.Add('target', $Target)
126+
} else {
127+
throw "Target is mandatory if type is NOOP, Redirect or RespondWith"
128+
}
129+
}
130+
"^(redirect|sqlresponse_ok|sqlresponse_error|respondwithhtmlpage)$" {
131+
if ($PSBoundParameters.ContainsKey('ResponseStatusCode')) {
132+
$params.Add('responsestatuscode', $ResponseStatusCode)
133+
}
134+
if ($PSBoundParameters.ContainsKey('ReasonPhrase')) {
135+
$params.Add('reasonphrase', $ReasonPhrase)
136+
}
137+
}
138+
"respondwithhtmlpage" {
139+
if ($PSBoundParameters.ContainsKey('HtmlPage')) {
140+
$params.Add('htmlpage', $HtmlPage)
141+
}
142+
}
143+
}
144+
_InvokeNSRestApi -Session $Session -Method POST -Type responderaction -Payload $params -Action add
145+
146+
if ($PSBoundParameters.ContainsKey('PassThru')) {
147+
return Get-NSResponderAction -Session $Session -Name $Item
148+
}
149+
} catch {
150+
throw $_
151+
}
152+
}
153+
}
154+
}
155+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<#
2+
Copyright 2016 Dominique Broeglin
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#>
16+
17+
function Remove-NSResponderAction {
18+
<#
19+
.SYNOPSIS
20+
Removes a responder action.
21+
22+
.DESCRIPTION
23+
Removes a responder action.
24+
25+
.EXAMPLE
26+
Remove-NSResponderAction -Name 'act-redirect'
27+
28+
Removes the responder action named 'act-redirect'.
29+
30+
.EXAMPLE
31+
'act-1', 'act-2' | Remove-NSResponderAction
32+
33+
Removes the responder action named 'act-1' and 'act-2'.
34+
35+
.PARAMETER Session
36+
The NetScaler session object.
37+
38+
.PARAMETER Name
39+
The name or names of the responder actions to remove.
40+
41+
.PARAMETER Force
42+
Suppress confirmation when removing a responder action.
43+
#>
44+
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='High')]
45+
param(
46+
$Session = $script:session,
47+
48+
[parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
49+
[string[]]$Name,
50+
51+
[switch]$Force
52+
)
53+
54+
begin {
55+
_AssertSessionActive
56+
}
57+
58+
process {
59+
foreach ($item in $Name) {
60+
if ($Force -or $PSCmdlet.ShouldProcess($item, 'Delete Responder Action')) {
61+
try {
62+
_InvokeNSRestApi -Session $Session -Method DELETE -Type responderaction -Resource $item -Action delete
63+
} catch {
64+
throw $_
65+
}
66+
}
67+
}
68+
}
69+
}

NetScaler/Public/Set-NSLBServer.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Set-NSLBServer {
4545
The comment associated with the load balancer server.
4646
4747
.PARAMETER Force
48-
Suppress confirmation when updating an load balancer server.
48+
Suppress confirmation when updating a load balancer server.
4949
5050
.PARAMETER Passthru
5151
Return the load balancer server object.

0 commit comments

Comments
 (0)