Using PowerShell to prevent thinly provisioned NetApp LUNs from going offline – Part I


Happy Day-after Thanksgiving dear readers! I hope everyone is as satisfyingly full on food, friends, and family as I am.  As an early gift to myself, I’m writing a PowerShell script that utilizes NetApp’s PowerShell Toolkit.  The script will help me quickly determine current volume and LUN settings so I can see what LUNs are at risk of going offline due to out of space conditions.  In scripting tradition, I couldn’t find anything online that did exactly what I wanted so I rolled my own!

Here’s what the output looks like. The column names are abbreviated because I expect to have several more columns. The abbreviations are, Volume Thin Provisioning, Fractional Reserve, Snapshots, Volume AutoGrow, Snapshot AutoDelete.

The usefulness of the script can be seen in the highlighted output. The Exchange volumes are thin provisioned, Fractional Reserve is set to 0 for each, Snapshots are on, and space protection settings Volume AutoGrow and Snapshot AutoDelete are not turned on. This tells me I should investigate these volumes and LUNs to be sure they’re configured properly. I would likely want to, at a minimum, turn on Volume AutoGrow and Snapshot AutoDelete.

I expect this script to be extremely useful to our Managed Services team, in particular, as we take on more and more Managed Services clients.  We’ve been bitten more than once by out of space conditions even though we use OnCommand Unified Manager.  When run, the script will allow someone to see, at a glance, which settings are not set according to NetApp’s best practices.

This is Part I of several posts that will show the evolution of this script into its final form.  Earlier this week I brought the script into a minimally usable form which is enough to share with the community.  There’s plenty more to do, no doubt, though.  I have no LUN information, for example.  The sole function does not sanitize inputs, and I’m sure some of the logic could be optimized for speed.  It seems kind of slow right now and I’ve only been testing against FAS2240s.  Either way, here it is in all its glory! Please share your thoughts on how to improve it or perhaps share a script of your own.

In addition, I’ve of course used many ideas from the internets.  So if you see something in here that looks familiar, it’s probably yours 🙂 Thanks for letting me borrow it.

Requirements

  • NetApp PowerShell Toolkit
  • Data ONTAP 7-mode
  • Manually log into each controller using Connect-NaController
#$ErrorActionPreference = "SilentlyContinue"

Function IsSnapMirrorDest ($VolName,$Filer)
{
    #Returns $true or $false to the question
    #Is $VolName a VSM Destination?
    #VSM destination volumes don't handle Get-NaVolAutosize or
    #Get-NaSnapAutodelete well, so this function discovers
    #VSM destination volumes which allows the main function to 
    #avoid querying them for Volume AutoSize or Snapshot AutoDelete
    #which avoids errors

    #I don't need all these variables; some are left for reference, though
    #$SourceFiler = $null
    #$Source = $null
    $DestinationFiler = $null
    #$Destination = $null
    $Pair = $null
    $IsSnapMirrorDest = $null

    #Get the VSM status of the volume
    $Pair = Get-NaSnapmirror $VolName

    #If volume is not in a VSM relationship, the output of
    #the Get-NaSnapmirror function will return a null string
    #This if statement checks to see if the volume is in a VSM
    #relationship and falls into it if it is not
    if($Pair -ne $null)
    {
        #I ended up only needing the $DestinationFiler
        #for this function, but the others are left
        #for reference
        #$SourceFiler = ($Pair.Source.Split(":"))[0]
        #$Source = ($Pair.Source.Split(":"))[1]
        $DestinationFiler = ($Pair.Destination.Split(":"))[0]
        #$Destination = ($Pair.Destination.Split(":"))[1]

        #If this script is run on the destination controller of
        #this volume's VSM relationship, return $true
        if($Filer -eq $DestinationFiler)
        {
            $IsSnapMirrorDest = $true
            return $IsSnapMirrorDest
        }

        #If this script is run on the source controller of
        #this volume's VSM relationship, return $false
        $IsSnapMirrorDest = $false
        return $IsSnapMirrorDest
    }
    #This else condition is used when the volume is not part
    #of a VSM relationship at all
    else
    {
        $IsSnapMirrorDest = $false
        return $IsSnapMirrorDest
    }
}

#cls
$Vol = $null
$ObjVol = $null
$AutoSize = $null
$AutoDelete = $null

#Get controller name for comparison later
$Filer = (Get-NaSystemInfo).SystemName

#Create an empty collection of volumes
$ColVol = @()

#This script counts online and offline volumes for reference
$NumVols = (Get-NaVol).Count
$OnlineVols = 0

foreach($Vol in Get-NaVol)
{
    #Offline volumes cannot be queried for all conditions, so this
    #script avoids querying them at all to avoid unnecessary work
    #i.e. I'm lazy and didn't want to script for so many conditions
    if($Vol.State -eq "online")
    {
        $OnlineVols = $OnlineVols + 1

        #Look at each option name and decide if it's something
        #I want to query
	    foreach($Option in Get-NaVolOption $Vol.Name)
	    {
            #Create a set of properties for custom object assignment later
            $Properties = @{
                Name=$Vol.Name;
                VolTP=$ThinProvisioned;
                FR=$FractionalReserve;
                Snaps=$Snaps;
                VolAG=$AutoSize;
                SnapAD=$AutoDelete
            }
            #Look at each option name and decide if it's something
            #I want to query. Right now, the options are 
            #1. actual_guarantee
            #2. fractional_reserve
            #3. nosnap
            switch($Option.Name)
            {
                "actual_guarantee"
                    {
                        switch($Option.Value)
                        {
                            "volume" {$ThinProvisioned = "no"}
                            "file" {$ThinProvisioned = "file"}
                            "none" {$ThinProvisioned = "yes"}
                        }
                    }
                "fractional_reserve" {$FractionalReserve = $Option.Value}
                "nosnap"
                    {
                        if($Option.Value -eq "on")
                        {
                            $Snaps = "no"
                        }
                        else
                        {
                            $Snaps = "yes"
                        }
                    }
	        }
            #Create a new custom object for each volume and assign
            #the properties
            $ObjVol = New-Object -TypeName PSObject -Property $Properties
        }
        #keep track of offline volumes for reference
        $OfflineVols = $NumVols - $OnlineVols

        #If a volume is a VSM destination, don't query it 
        if((IsSnapMirrorDest $Vol.Name $Filer) -eq $false)
        {
            #Discover Volume AutoSize settings
            if((Get-NaVolAutosize $Vol).IsEnabled -eq "True")
            {
                $ObjVol.VolAG = "on"
            }
            else
            {
                $ObjVol.VolAG = "off"
            }
            #Discover Snapshot AutoDelete settings
            #GetValue(4) here gets the value of the 5th OptionName
            #(starts counting at 0) in the hash table
            $ObjVol.SnapAD = ((Get-NaSnapshotAutodelete $Vol).GetValue(4)).OptionValue
        }
        #This condition occurs when a volume is a VSM destination. Since
        #Volume AutoSize and Snapshot AutoDelete cannot be queried 
        #without errors, these settings will be called out
        #by "VSM dest," meaning the volume is a VSM destination.
        else
        {
            $ObjVol.VolAG = "VSM dest"
            $ObjVol.SnapAD = "VSM dest"
        }
        #After every pass of a volume, append the custom object to
        #the collection of objects
        $ColVol += $ObjVol    
    }
}
Write-Host "`n"
Write-Host "--------------------------------"
Write-Host "Controller: " $Filer
Write-Host "Online volumes: " $OnlineVols
Write-Host "Offline volumes: " $OfflineVols
Write-Host "--------------------------------"

$ColVol | Format-Table Name,VolTP,FR,Snaps,VolAG,SnapAD


One Comment on “Using PowerShell to prevent thinly provisioned NetApp LUNs from going offline – Part I”

  1. Arronaardy says:

    Hi,

    Really great script, we use the later version of netapp 8.3, and i just cannot get his to work.

    Could you please help me out..


Leave a comment

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |