How to Use PowerShell to Health Check AutoSupport in Clustered ONTAP

The following script is something I’ve knocked up to Health Check AutoSupport in Clustered ONTAP. The idea of the script is that it’s a set of functions you can use in a much larger health check script. To show it working though, I’ve included a basic output function.

Example Output

To connect to the cluster we’re using the PowerShell Connections and Secure Credentials Manager Function from these two posts: Part 1 and Part 2. The outputs are obtained with different ASUP settings being applied to the cluster.

PS C:> cot NACLU5
PS C:> . .\checkAutoSupport.ps1

PS C:> HC-BasicOutput
NACLU5N1
ASUP Not Enabled!
NACLU5N2
ASUP Not Enabled!

PS C:> HC-BasicOutput
NACLU5N1
ASUP Enabled
ASUP to Support Not Enabled!
NACLU5N2
ASUP Enabled
ASUP to Support Not Enabled!

PS C:> HC-BasicOutput
NACLU5N1
ASUP Enabled
ASUP to Support Enabled
ASUP Transmission Failed!
NACLU5N2
ASUP Enabled
ASUP to Support Enabled
ASUP Transmission Failed!

Note: This output is from a lab hence have not shown an “ASUP Sent Successful” result

The Script

Note: As always, leading tabs have been removed to make this display better in Blogger.

##################################################################
# Clustered ONTAP: PowerShell ASUP Health Checking Functions     #
# ============================================================== #
# function HC-AsupEnabled + {Node Name}                          #
# function HC-AsupSupportEnabled + {Node Name}                   #
# function HC-AsupSent + {Node Name}                             #
# + function HC-BasicOutput (example function to display output) #
##################################################################

############################################
# Function to find out if ASUP is enabled. #
############################################

function HC-AsupEnabled { # args[0]=NodeName

$attributes = Get-NcAutoSupportConfig -Template
$attributes.IsEnabled = ""
$getAsupConf = Get-NcAutoSupportConfig -Node $args[0] -Attributes $attributes

If ($getAsupConf.IsEnabled -eq "true"){return "true"}
return $null # false
      
}

##############################################################
# Function to find out if ASUP to NetApp support is enabled. #
##############################################################

function HC-AsupSupportEnabled { # args[0]=NodeName

$attributes = Get-NcAutoSupportConfig -Template
$attributes.IsSupportEnabled = ""
$getAsupConf = Get-NcAutoSupportConfig -Node $args[0] -Attributes $attributes

If ($getAsupConf.IsSupportEnabled -eq "true"){return "true"}
return $null # false

}

###################################################################################
# Function to find out if ASUP has been successfully sent.                        #
# Possible history status =                                                       #
# collection-in-progress, ignore, sent-successful, re-queued, transmission_failed #
###################################################################################

function HC-AsupSent { # args[0]=NodeName

$nodeName = $args[0]
$attributes = Get-NcAutoSupportConfig -Template
$attributes.Transport = ""
$getAsupConf = Get-NcAutoSupportConfig -Node $nodeName -Attributes $attributes
$transport = $getAsupConf.transport

If ($transport -eq "https"){ $transport = "http"}

$attributes = Get-NcAutoSupportHistory -Template
$attributes.Status = ""   
$query = Get-NcAutoSupportHistory -Template
$query.Destination = $transport
$query.NodeName = $nodeName
      
$getAsupHistory = Get-NcAutoSupportHistory -Attributes $attributes -Query $query
$asupHistoryCount = $getAsupHistory.count

if ($asupHistoryCount -eq 0){return $null} # no history

$i = $asupHistoryCount - 1

do {
$line = $getAsupHistory[$i]
if ($line.status -eq "transmission_failed"){return $null} # failed
if ($line.status -eq "sent-successful"){return "success"}
$i--
} while ($i -ge 0)

return $null # failed
      
}

##############################################################################
# The next two functions are only included for simple basic output purposes. #
# The idea is that the functions above get the data,                         #
# and then we can later output the data in whatever way we choose!           #
##############################################################################

function HC-BasicOutput {

# Get the list of nodes in the cluster
$attributes = Get-NcNode -Template
$attributes.Node = ""
$nodes = Get-NcNode -Attributes $attributes

# For each node get and output ASUP information
foreach ($node in $nodes){
      
$nodeName = $node.Node
"$nodeName"
HC-BasicOutputDisplay $nodeName

}

}

function HC-BasicOutputDisplay { # args[0]=NodeName

$nodeName = $args[0]
$asupEnabled = HC-AsupEnabled $nodeName
$asupSupportEnabled = HC-AsupSupportEnabled $nodeName
$asupDelivered = HC-AsupSent $nodeName

If (!$asupEnabled){"ASUP Not Enabled!";return}
"ASUP Enabled"

If (!$asupSupportEnabled){"ASUP to Support Not Enabled!";return}
"ASUP to Support Enabled"

If (!$asupDelivered){"ASUP Transmission Failed!";return}
"ASUP Sent Successful"

}

#################
# END OF SCRIPT #
#################

Comments