devblackops / NetScaler

PowerShell module for interacting with Citrix NetScaler via the Nitro API
Apache License 2.0
69 stars 32 forks source link

Update action error #16

Closed iainbrighton closed 8 years ago

iainbrighton commented 8 years ago

When attempting to call Set-NSHostname (or Set-NSTimezone) an error is returned by the Nitro API. I can't find anything concrete, but the API implementation must have changed as I'm sure this used to work? There may be other API calls that are impacted too.

Current Behavior

PS C:\> $ns = Connect-NetScaler -IPAddress 10.200.0.100 -Credential nsroot -PassThru
PS C:\> Set-NSHostname -Session $ns -Hostname ns1.lab.local -Verbose -Force

VERBOSE: URI: http://10.200.0.100/nitro/v1/config/nshostname?action=update
VERBOSE: JSON Payload:
{
    "params":  {
                   "onerror":  "EXIT",
                   "warning":  "NO"
               },
    "nshostname":  {
                       "hostname":  "ns1.lab.local"
                   }
}
Invoke-RestMethod : { "errorcode": 1240, "message": "Invalid nitro action or operation", "severity": "ERROR" }
At C:\Program Files\WindowsPowerShell\Modules\netscaler\Private\_InvokeNSRestApi.ps1:144 char:21
+         $response = Invoke-RestMethod @restParams
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Possible Solution

Removing the -Action update from https://github.com/devblackops/NetScaler/blob/master/NetScaler/Public/Set-NSHostname.ps1#L67 (and https://github.com/devblackops/NetScaler/blob/master/NetScaler/Public/Set-NSTimeZone.ps1#L76) resolves the issue, for example:

_InvokeNSRestApi -Session $Session -Method PUT -Type nshostname -Payload $params # -Action update

Your Environment

iainbrighton commented 8 years ago

I'm happy to submit a PR for this if you want me to? I'm just not sure what the impact is and what else might be affected..

iainbrighton commented 8 years ago

@devblackops Doing some additional testing and it appears that later versions of the API complain about the standard -Action add, -Action delete and -Action update requests. The API uses the standard PUT, POST and DELETE HTTP verbs for these actions and only the likes of -Action unset are actually required in the request.

It looks like the older versions of the API just ignored the extraneous actions - hence why this has only just come to light. The API hasn't changed.