Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Written by David Ott
- This script requires the Nitro API for C#. This is my first powershell script messing with the netscaler. It will report
- all netscalers in HA with status - up or down (if you have HA enabled), all vservers up/down/degraded (if degraded will tell you
- which service is down). All netscaler gateways - up/down, and all ica connections (also whether or not they are using the new
- Framehawk protocol - need NS 11.0 62.10 or above)
- credit to Ajené Hall Barrett (http://blogs.citrix.com/2014/05/29/powershell-nitro-api-and-html-load-balancing-virtual-servers/)
- search for ##### for fields you will want to edit
- #>
- function check-downvserver($v){
- if ($v.totalservices -eq "0" -and ($v.redirurl).length -ne "0") {
- $r = "0"
- } else {
- $r = "1"
- }
- return $r
- }
- function check-upvserver($v) {
- if ($v.totalservices -eq $v.activeservices) {
- $r = "0"
- } else {
- $r = "1"
- }
- return $r
- }
- function check-gw($v) {
- if ($v.curstate -eq "UP") {
- $r = "0"
- } else {
- $r = "1"
- }
- return $r
- }
- <##### You can use your nsip instead of a snip with gui management enabled, BUT if that nsip happens to be a netscaler
- that is down the whole script will fail. If you use a snip with gui management enabled it will hit any ha netscaler that is up. #####>
- $snip = "internal snip with gui management enabled"
- $user = "nsroot"
- $pass = "nsroot" ##### nsroot password (nsroot = default)
- <##### You need the C# nitro api (download from your netscaler), extract it all, and change $path1 and $path2 below to match your system #####>
- $path1 = "C:\ns_nitro-csharp_ion_62_10\lib\Newtonsoft.Json.dll"
- $path2 = "C:\ns_nitro-csharp_ion_62_10\lib\nitro.dll"
- $O = [System.Reflection.Assembly]::LoadFile($path1)
- $O = [System.Reflection.Assembly]::LoadFile($path2)
- $nitrosession = new-object com.citrix.netscaler.nitro.service.nitro_service($snip,"http")
- $session = $nitrosession.login($user,$pass)
- $HA = [com.citrix.netscaler.nitro.resource.config.ha.hanode]::get($nitrosession)
- $AllLBvServers = [com.citrix.netscaler.nitro.resource.config.lb.lbvserver]::get($nitrosession)
- $Gateways = [com.citrix.netscaler.nitro.resource.config.vpn.vpnvserver]::get($nitrosession)
- if (($HA | Measure-Object).Count -gt "1") {
- Write-Host "Netscaler HA" -ForegroundColor Gray
- foreach ($h in $HA) {
- if ($h.hastatus -ne "UP") {
- Write-Host "Netscaler"$h.ipaddress "DOWN" -ForegroundColor Red
- } else {
- Write-Host "Netscaler"$h.ipaddress "UP" -ForegroundColor Green
- }
- }
- Write-Host "`r`n"
- }
- if (($AllLBvServers | Measure-Object).count -gt "0") {
- Write-Host "Load Balancing Virtual Servers" -ForegroundColor Gray
- foreach ($lbvserver in $AllLBvServers) {
- if ($lbvserver.effectivestate -eq "down") {
- $dchk = check-downvserver -v $lbvserver
- if ($dchk -eq "0") {
- write-host $lbvserver.name $lbvserver.ipv46 "OK" -ForegroundColor Green
- } else {
- Write-Host $lbvserver.name $lbvserver.ipv46 "DOWN" -ForegroundColor Red
- }
- } else {
- $uchk = check-upvserver -v $lbvserver
- if ($uchk -eq "0") {
- Write-Host $lbvserver.name $lbvserver.ipv46 "OK" -ForegroundColor Green
- } else {
- Write-Host $lbvserver.name $lbvserver.ipv46 "DEGRADED" -ForegroundColor Yellow
- [com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding]::get($nitrosession,$lbvserver.name) | %{
- if ($_.curstate -ne "UP") {
- Write-Host " "$_.servicename $_.vsvrbindsvcip $_.curstate -ForegroundColor DarkRed
- }
- }
- }
- }
- }
- Write-Host "`r`n"
- }
- if (($Gateways | Measure-Object).count -gt "0") {
- Write-Host "Netscaler Gateways" -ForegroundColor Gray
- foreach ($gw in $gateways) {
- $gchk = check-gw -v $gw
- if ($gchk -eq "0") {
- Write-Host $gw.name $gw.ipv46 "OK" -ForegroundColor Green
- } else {
- Write-Host $gw.name $gw.ipv46 $gw.curstate -ForegroundColor Red
- }
- }
- Write-Host "`r`n"
- }
- if (([com.citrix.netscaler.nitro.resource.config.vpn.vpnicaconnection]::get($nitrosession) | Measure-Object).count -gt "0") {
- Write-Host "Current XD/XA Connections" -f Gray
- [com.citrix.netscaler.nitro.resource.config.vpn.vpnicaconnection]::get($nitrosession) | %{
- $n = $null
- $n = $_.username
- if ([com.citrix.netscaler.nitro.resource.config.vpn.vpnicadtlsconnection]::get($nitrosession) | ?{$_.username -eq $n}) {
- Write-Host $_.username "Framehawk:True"
- } else {
- Write-Host $_.username "Framehawk:False"
- }
- }
- }
- $nitrosession.logout() | Out-Null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement