This post has already been read 17492 times!
So, after a busy couple of weeks I have finally got the time to revisit my Octoblu NetScaler automation. In my last post I wrote about adding a server to a NetScaler using the NetScaler thing that Octoblu provide. I wanted to take this a step further and start to look at getting some information back from the NetScaler. This in itself would be of huge value if combined with configuring a NetScaler in the following scenario.
If you have a vServer that is showing as down in a certain datacenter, add additional servers to the load balancer in the other datacenter to cater for the incoming load.
So, here is how to get a vServer Status report from your NetScaler using Octoblu.
First you will have to add a Shell Connector to your Octoblu Account as we will be using powershell and NITRO API to execute the commands on the NetScaler. If you want some more information on how to create the connector please read my last article here.
Once you have added the connector configure it as shown below
NOTE: Make sure you put the FULL path to the powershell.exe file. This is because we will be adding functions to the global profile.ps1 file and you will want to ensure the correct version is used or the functions may be unavailable.
Next we will add the NetScaler Specific functions to the powershell instance on the Connector machine. On the machine that you installed the connector create a file called profile.ps1 in the SAME directory that you specified for your Octoblu connector. In this case c:\windows\system32\windowspowershell\v1.0
Copy and paste the following functions into the profile.ps1 file
Please note that the scripts do not currently have error checking in them as this is just the beginning of my Octoblu journey and also I have been using the excellent Github scripts available here to build out these functions
Function NS-Login($NSIP, $UserName, $Password) { $body = ConvertTo-JSON @{ "login"=@{ "username"=$UserName; "password"=$Password } } Invoke-RestMethod -uri "$NSIP/nitro/v1/config/login" -body $body -SessionVariable saveSession -Headers @{"Content-Type"="application/vnd.com.citrix.netscaler.login+json"} -Method POST $Global:nsSession = New-Object -TypeName PSObject $nsSession | Add-Member -NotePropertyName Endpoint -NotePropertyValue $NSIP -TypeName String $nsSession | Add-Member -NotePropertyName WebSession -NotePropertyValue $saveSession -TypeName Microsoft.PowerShell.Commands.WebRequestSession return $nsSession } Function NS-Logout($NSIP) { $logout = @{"logout" = @{}} $logoutJson = ConvertTo-Json $logout Invoke-RestMethod -uri "$NSIP/nitro/v1/config/logout" -body $logoutJson -WebSession $NSSession.WebSession -Headers @{"Content-Type"="application/vnd.com.citrix.netscaler.logout+json"} -Method POST Clear-Variable -Name NSSession return $nsSession } Function NS-GetLBVS-All($NSIP) { $Global:vServers = Invoke-RestMethod -uri "$NSIP/nitro/v1/stat/lbvserver" -WebSession $NSSession.WebSession -Method GET } Function NS-DisplaylbvServerStatus($NSIP) { NS-GetLBVS-All $NSIP foreach ($vServer in $vServers.lbvserver) { write-host "vServer Name:" $vServer.Name "is" $vServer.State } }
So there are 4 functions defined here, 1 to log into the NetScaler taking in a NSIP, User Name and Password, 1 to Log Out, 1 to get all the vServers defined on your NetScaler and 1 to Strip the vServer Name and State out of the array delivered.
To test everything is working as expected you can log into your Connector Server and run the following commands from powershell.
NS-Login <NSIP> nsroot <password>
NS-DisplaylbvServerStatus <NSIP>
NS-Logout <NSIP>
If all is working you should see the below (listing your own vServers)
Once working all we need to do is define our Octoblu flow to trigger these functions and send out the text/e-mail.
Switch back to your Octoblu Flow tool and create a flow that looks like the below
For the powershell Connector enter the 3 commands you want to execute (putting in your own NSIP and password)
For the Text Message and e-mail things set the message to the following
Save and Execute your flow.
Because I think its pretty cool I am going to execute the flow from my Apple Watch
Existing Trigger, executing and Firing
e-Mail report of the current status of my vServers
The actual vServer status on the NetScaler to show that it is getting live data
That’s it – how to get Octoblu to send you a status report of all your vServers on your NetScaler.
I will be posting more about this as I delve into IOT more with Octoblu.
Laters,
b@m
You don’t need PowerShell to do this.. There is a native Octoblu NetScaler connector. If what you need isn’t currently in the connector, ping the Octoblu guys and they will add it.
Hi Joe.
Yep, had a chat to the guys on the slack channel about that, realise there is a native connector and used that in my last post. Just experimenting with what’s possible around NITRO.
I think being able to monitor the NetScalers and react based on load / failed vServers etc would be a powerful thing for Octoblu.
Will reach out on Slack again.
Pingback: EUC Weekly Digest – July 23, 2016 – Carl Stalhood
Pingback: Using Octoblu to generate a Citrix NetScaler vServer Status Report using NITRO API
Pingback: Managing Citrix NetScaler by email with Octoblu and NITRO | bretty.me.uk