Ping All LIFs on My Cluster Tool

Ping All LIFs on My NetApp Clustered Data ONTAP Cluster Tool

Back in April I wrote Multiple Pings Testing Tool. It occurred to me that with a little bit of work it could be used as a “Ping All LIFs on My Cluster!” tool. Of course, we won’t ping cluster role LIFs (on the private and un-routable cluster backbone network), and all the LIFs would need to be routable to the client doing the ping test (if you’re using IPSpaces beyond just the default, this may be impossible.)

Image: Example output from test cluster

A good idea to expand the tool would be to include service-processors also.

Copy and paste the below script into a text file and save as say PingAllLifs.ps1. Then run as:

PS C:\ > .\PingAllLifs.ps1 -Cluster ClusterName -Username UserName

You will be prompted for the cluster password.

The Script

###################################################
# PingAllLifs.ps1 or Ping All LIFs On My Cluster! #
###################################################

Param(
  [Parameter(Mandatory=$true)][String]$Cluster,
  [Parameter(Mandatory=$true)][String]$Username,
  [Int]$w = 50
)

FUNCTION Wr {
  Param([String]$ToDisplay,[String]$ForegroundColor,[String]$BackgroundColor)
  If(!$ToDisplay){ Write-Host; RETURN    }
  If($BackgroundColor){ Write-Host $ToDisplay -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -NoNewLine; RETURN }
  If($ForegroundColor){ Write-Host $ToDisplay -ForegroundColor $ForegroundColor -NoNewLine; RETURN }
  Write-Host $ToDisplay -ForegroundColor White 
}

## LOAD THE DATA ONTAP POWERSHELL TOOLKIT ##

[Void](Import-Module DataONTAP -ErrorAction SilentlyContinue)
If(!(Get-Module DataONTAP)){ Wr "Unable to load the DataONTAP PowerShell Toolkit - exiting!" Red; Wr; EXIT }
Wr "Loaded the Data ONTAP PowerShell Toolkit!" Green; Wr

## GET CREDENTIALS ##

Wr "Password: " Cyan; $Password = Read-Host -AsSecureString
$SecureString = $Password | ConvertFrom-SecureString
$Credential = New-Object System.Management.Automation.PsCredential($Username,$Password)

## TEST CREDENTIALS AND ACQUIRE LIFS ##

Wr "Checking connection to " Cyan; Wr $Cluster Yellow; Wr " ..." Cyan; Wr
If ( !(Connect-NcController -Name $Cluster -Credential $Credential -Timeout 20000 -ErrorAction SilentlyContinue) ){
  Wr "Unable to connect to " Red; Wr $Cluster Yellow; Wr " with provided credentials - exiting!" Red; Wr; EXIT
} else { Wr "Successfully connected to " Green; Wr $Cluster Yellow; Wr }
      
$Attrs = Get-NcNetInterface -Template
$Attrs.role = ""
$Attrs.address = ""
$Attrs.interfacename = ""
$LIFs = Get-NcNetInterface -Attributes $Attrs

[System.Object]$targets = @{}
[Int]$count = 0
$LIFs | Foreach{
  If ($_.role -ne "cluster"){
    $count++
    [System.Object]$targets.$count = @{}
    [String]$targets.$count.address = $_.address
    [String]$targets.$count.interfacename = $_.interfacename
  }
}     

If($count -eq 0){ Wr "No targets to ping - exiting!" Red; Wr; EXIT }

## PING ALL NON-CLUSTER LIFS ##

[System.Array]$status = "" # $status[0] is unused
For($i = 1; $i -le $count; $i++){ $status += "Unitialized" }

Function PrintStatus{
  Param([Int16]$pointer)
  If ($pointer -eq $count){ $pointer = 1}
  else { $pointer ++ }    
  cls
  For($j = 1; $j -le $count; $j++){
    If ($pointer -eq $j){ [String]$Display = " * " } else { [String]$Display = "   " }
    $Display += $Cluster + " : " + $targets.$j.interfacename + " : " + $targets.$j.address
    If ($status[$j] -eq "UP"){ Wr ($Display.PadRight($w).Substring(0,$w)) BLACK GREEN; Wr }
    elseif ($status[$j] -eq "DOWN"){ Wr ($Display.PadRight($w).Substring(0,$w)) WHITE RED; Wr }
    else { Wr ($Display.PadRight($w).Substring(0,$w)) BLACK GRAY ; Wr }
  }
}

Function GetResult{
  For($i = 1; $i -le $count; $i++){
    [Boolean]$Result = Test-Connection -ComputerName $targets.$i.address -Count 1 -Quiet
    If ($Result){ $status[$i] = "UP" }
    If(!$Result){ $status[$i] = "DOWN" }
    PrintStatus $i
  }
}

While ($true){ GetResult }

Comments