Microsoft Virtualization Discussions

Powershell Lag Time

JGPSHNTAP

So, i'm new to the whole powershell on Netapp, but I'm looking for a way to query a bunch of filers and report on snapmirror lag time.    I'm a Vbscript guy, so go easy on me as im just starting to learn powershell.

32 REPLIES 32

JGPSHNTAP

Wow - this thread is old... And how i've progressed in such a year...

Anything's possible.. that's sort of what we do

JGPSHNTAP

I've adjusted the log file.  I didn't quite like using sc $outfile to xls. 

added out-string -width 4096 | out-file $outfile.

I had to use out-string b/c my volumes kept getting truncated b/c they were too long.  I had to change the default behavior of the display window.  Just make sure you adjust $ext to $ext = ".log"

steve4

Is it possible to add threshold logic and also e-mail if over a threshold.  i.e.: send the daily report of all SV relationships to a general distro list, and ALSO send an "alert" e-mail to a NOC if LAG is over a defined threshold?

Thanks!

Steve

JGPSHNTAP

Clinton,

I've been playing along with Add-nacredential.  Seems pretty cool.  Currently, the set of filers that i'm thinking about are not in the domain so that's why I am using -cred root.    I assume if I add the credentials to each filer on the local cache I need to use -systemscope especially if I am going to schedule the job as Local system in task manager.    The only bothering thing is that we need to update this when the root password changes.. Ugg..

Oh well, thx for the continued tips..

JGPSHNTAP

I forgot to mention that i keep getting this trailing errror.  I made sure the input file had no trailing spaces and I can't figure out where it's coming from.. a bit of annoying

ERROR: ConvertTo-Csv : Cannot bind argument to parameter 'InputObject' because it is null.

ERROR: At C:\temp\good\good\lagtime2.ps1:68 char:44

ERROR: + $dataToWrite = $snapMirrors | convertTo-Csv <<<<  -delimiter $delim -noType

ERROR:     + CategoryInfo          : InvalidData&colon; (:) [ConvertTo-Csv], ParameterBindingValidationException

ERROR:     + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToCsvCommand

ERROR:

timothyn

Hi Josh,

I'd recommend "Add-NaCredential -SystemScope" for managing the creds.  Simply connect to your controller at the console and then call that cmdlet.  Then in your script, don't specify credentials at all, and the machine encrypted values you entered earlier will be used automatically!

You shouldn't be using FT/Format-Table to send data to CSV.  Format-Table is really for sending data to the screen/console.  Instead, just use "Select-Command" like you are doing which builds PSObjects.  Note that you can pass expressions like "@{Name=SomeField;Expression={$Some[Value]}}" to the select cmdlet.

The Exception you mention is probably from a controller with no out-of-date mirrors.  In that case PowerShell is going to push a $null onto your $snapMirrors list.  You can easily filter those out like this:

$snapMirrors | where {$_} | convertTo-Csv -delimiter $delim -noType

Cheers!

Eric

abhishekrana

Hi Eric,

I had similar requirement, i.e i want lag time of only specific volumes, and want output directly on email.

i have modified the script but i am not able to get specific volume, can you please advice me on this.

### Mail "constants"

      $sendMailAs    = ""

       $recipients    = ""

       $subjectLine = ""

       $mailMessage = ""

       $smtpServer = ""

       $priority = "high"

### Import Data OnTap Module

    # Check toolkit version

    try

    {

        if (-Not (Get-Module DataONTAP))

        {

            Import-Module DataONTAP -EA 'STOP' -Verbose:$false

        }

        if ((Get-NaToolkitVersion).CompareTo([system.version]'1.7') -LT 0) { throw }

    }

    catch [Exception]

    {

        Write-Warning "This script requires Data ONTAP PowerShell Toolkit 1.7 or higher."

        return;

    }

### Define Lag time

$lagtimeseconds = "3600" #One hour lagtime

### Input File properties

$hostfile = "C:\Powershell Script\hosts.txt"

$accnt = ""

$filerpassw = ""

$password = ConvertTo-SecureString $filerpassw -AsPlainText –Force 

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $accnt,$password 

$snapMirrors = @()

gc $hostfile | % {

  $C = Connect-NaController -credential $cred $_

  $snapMirrors +=  Get-NaSnapmirror | where-object {$_.lagTime -gt $lagTimeSeconds} | Select SourceLocation ,DestinationLocation,Status,State,LagtimeTS # |  ft @{expression={$c};Label="Filer name";width=20},@{expression={$_.SourceLocation};Label="Source";Width=40},@{Expression={$_.DestinationLocation};Label="Destination";Width=40},@{expression={$_.status};Label="status";width=20},@{Expression={$_.state};Label="state";width=20},@{Expression={$_.lagtimets};label="lag time";width=20}

 

}

$dataToWrite = $snapMirrors | out-string -width 4096

 

## Send Email

Send-MailMessage -To $recipients -From $sendMailAs -Subject $subjectLine -Body $dataToWrite -Priority $priority -SmtpServer $smtpServer

exit 4

#####

JGPSHNTAP

You gotta give me a little more information here....   You can query based on volume name if you want, but do all your filers that you want have the same name.

You can do something like

get-navol | ? {$_.name -like "*nameyouwant*"} | get-nasnapmirror

Or you can filter get-nasnapmirror or you can do a where-object on $_.destination ..

abhishekrana

Hi,

seems its working now with below script.

still i am not able to figure out 1) in output i want name of the volume and 2) lag time in minutes.

can you please let me know how can i get this.

### Mail "constants"

      $sendMailAs    = ""

       $recipients    = ""

       $subjectLine = ""

       $mailMessage = ""

       $smtpServer = ""

       $priority = ""

### Import Data OnTap Module

    # Check toolkit version

    try

    {

        if (-Not (Get-Module DataONTAP))

        {

            Import-Module DataONTAP -EA 'STOP' -Verbose:$false

        }

        if ((Get-NaToolkitVersion).CompareTo([system.version]'1.7') -LT 0) { throw }

    }

    catch [Exception]

    {

        Write-Warning "This script requires Data ONTAP PowerShell Toolkit 1.7 or higher."

        return;

    }

### Define Lag time

$lagtimeseconds = "3600" #One hour lagtime

### Input File properties

$hostfile = "C:\Powershell Script\hosts.txt"

$accnt = ""

$filerpassw = ""

$password = ConvertTo-SecureString $filerpassw -AsPlainText –Force 

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $accnt,$password 

$snapMirrors = @()

gc $hostfile | % {

  $C = Connect-NaController -credential $cred $_

  $snapMirrors +=   Get-NaSnapmirror | where-object {$_.destination -like "name"} | Select SourceLocation,DestinationLocation,Status,LagtimeTS  |  ft -AutoSize @{expression={$_.SourceLocation};Label="Source";Width=40},@{Expression={$_.DestinationLocation};Label="Destination";Width=40},@{expression={$_.status};Label="status";width=20},@{Expression={$_.lagtimets};label="lag time";width=20}

 

}

$dataToWrite = $snapMirrors | out-string -Width 4096

#$dataToWrite | sc $outfile

 

## Send Email

Send-MailMessage -To $recipients -From $sendMailAs -Subject $subjectLine -Body $dataToWrite -Priority $priority -SmtpServer $smtpServer

exit 4

#####

JGPSHNTAP

Well you can use the below.. This is what i use as of today

gc $hostfile | % {

    $C = Connect-NaController  $_

    $snapMirrors = Get-NaSnapmirror | Where-Object {$_.lagTime -gt $lagtimeseconds}

    if ($snapMirrors -ne $null)

    {

     $snapMirrors | ft @{expression={$C};Label="Filer";Width=10},@{expression={$_.sourcelocation};Label="Source";Width=20}`

    ,@{expression={$_.destinationlocation};Label="Destination Location";Width=20},@{expression={$_.state};Label="Current State";Width=20}`

    ,@{N='Current Lag Time';E={'{0} days, {1} hrs, {2} mins, {3} secs' -f $_.LagTimeTS.days, $_.LagTimeTS.Hours, $_.LagTimeTS.Minutes, $_.LagTimeTS.Seconds}}`

    ,@{expression={ConvertTo-FormattedNumber $_.transferprogress DataSize "0.0"};Label="Current Progress";Width=20}`

    ,@{expression={ConvertTo-FormattedNumber $_.lasttransfersize Datasize "0.0"};Label="Last Transfer size";Width=20} -autosize `

    |  Out-String -Width 4096 | Out-File $totaloutfile -append

}

}

abhishekrana

Script you mentioned is not working.

i am using below script and its working fine though i need some modification in it.

1) i am able to filter 1 volume using query but i want to filter list of volumes which are mentioned in file.

2) lag time should be only in minutes.

3) i want name of volume in output which is not happening.

$snapMirrors = @()

gc $hostfile | % {

  $C = Connect-NaController -credential $cred $_

    $snapMirrors +=   Get-NaSnapmirror | where-object {$_.destination -like } | Select VOLNAME,DestinationLocation,Status,LagtimeTS  |  ft -AutoSize @{expression={$_.VOLNAME};Label="Volume";Width=40},@{Expression={$_.DestinationLocation};Label="Destination";Width=40},@{expression={$_.status};Label="status";width=20},@{expression={$_.lagtimets};Label="lagtime";width=20}

}

Thanks in advance.

JGPSHNTAP

Ok, I didn't post the entire script, just a snippet... 

What I posted is exactly what your looking for...

abhishekrana

I am new to scripting so if you can post entire script it would be great.

abhishekrana

Hi,

i want output only from destination filer and there is only 1 destination filer.

i want only specific volumes in the list. i will try the query you have given.

Also i am facing 1 problem, in output all the volumes are not getting displayed, there are certain volumes which are not displayed.

Thanks

JGPSHNTAP

Eric,

Thanks for the points,  I will review the add-nacredential cmdlet.   I still don't understand how that will work in an automated script job.. It can't prompt me for passwords.   Will review this weekend.

I will check out adjusting thta line to handle any Null values..

More to come next week.

cknight

Josh, Add-NaCredential securely stores controller credentials in a local cache file.  If you don't explicitly provide credentials or specify -RPC, Connect-NaController consults the cache and uses any credentials found there.  So it's a great way to keep from having to prompt for credentials in an automated script job.  Like Eric said, if your automated job runs in a Windows user context other than your own, use "Add-NaCredential -SystemScope" to ensure other authenticated users on the local host can access the credentials store.

JGPSHNTAP

Clinton,

Here's what I have so far.. There are a few flaws that I want to work on.  I would rather not put the password stored in the script.  I can compile it, but i was wondering if there is a better way to do this

Also, i had to abandon the Format-table command b/c I couldn't figure out how to format-table and then dump to csv.  Also, the way we are dumping to CSV is kind of lame.  I would like to use native Excel API, but i know this is a lot more challenging and i'm not sure i'm ready for it.  But basically this gets the job done for now.  It's ugly but it works. 

Improvements, comments, suggestions are welcome and appreciated.

### Mail "constants"

      $sendMailAs    = "xx"

       $recipients    = "x

       $subjectLine = "Daily Exchange VSM LAG TIME"

       $mailMessage = "Daily Exchange VSM Lag time"

       $smtpServer = "x"

       $priority = "high"

### File Constants

    $date = (get-date).toString('dd-MMM-yyyy_h-mm-ss')

    $ext = ".xls"

    $outfile = "Exchange_VSM_Lag_" + $date + $ext

    $delim = "`t"

### Import Data OnTap Module

    # Check toolkit version

    try

    {

        if (-Not (Get-Module DataONTAP))

        {

            Import-Module DataONTAP -EA 'STOP' -Verbose:$false

        }

        if ((Get-NaToolkitVersion).CompareTo([system.version]'1.7') -LT 0) { throw }

    }

    catch [Exception]

    {

        Write-Warning "This script requires Data ONTAP PowerShell Toolkit 1.7 or higher."

        return;

    }

### Define Lag time

$lagtimeseconds = "86400" #24 hour lagtime

### Input File properties

$hostfile = "hosts.txt"

$accnt = "xx"

$filerpassw = "xxx"

$password = ConvertTo-SecureString $filerpassw -AsPlainText –Force 

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $accnt,$password 

$snapMirrors = @()

gc $hostfile | % {

    $C = Connect-NaController -credential $cred $_

    $snapMirrors +=  Get-NaSnapmirror | where-object {$_.lagTime -gt $lagTimeSeconds} | Select SourceLocation,DestinationLocation,Status,State,LagtimeTS # |  ft @{expression={$c};Label="Filer name";width=20},@{expression={$_.SourceLocation};Label="Source";Width=40},@{Expression={$_.DestinationLocation};Label="Destination";Width=40},@{expression={$_.status};Label="status";width=20},@{Expression={$_.state};Label="state";width=20},@{Expression={$_.lagtimets};label="lag time";width=20}

}

$dataToWrite = $snapMirrors | convertTo-Csv -delimiter $delim -noType

$dataToWrite | sc $outfile

## Send Email

Send-MailMessage -To $recipients -From $sendMailAs -Attachments $outfile -Subject $subjectLine -Body $mailMessage -Priority $priority -SmtpServer $smtpServer

#####

JGPSHNTAP

It would be cool if i knew a way to convert 3.05:14:59 to days, hours, minutes, seconds.  So, like 3days,5hours,15minutes,59seconds  Is that a powershell expression that needs to happen?

cknight

Trivial:

PS C:\> $ts

Days              : 450

Hours             : 20

Minutes           : 26

Seconds           : 29

Milliseconds      : 0

Ticks             : 389535890000000

TotalDays         : 450.851724537037

TotalHours        : 10820.4413888889

TotalMinutes      : 649226.483333333

TotalSeconds      : 38953589

TotalMilliseconds : 38953589000

PS C:\> [String]::Format("{0} days, {1} hours, {2} minutes, {3} seconds", $ts.days, $ts.Hours, $ts.Minutes, $ts.Seconds)

450 days, 20 hours, 26 minutes, 29 seconds

JGPSHNTAP

Clinton,

Now i'm sort of getting somewhere

I took your advice from the other thread and have come up with this

"

gc $hostfile | % { $c = Connect-NaController -credential $cred $_; Write-Host "`nController: $c`n"; Get-NaSnapmirror | where-object {$_.LagTime -gt $LagTimeSeconds}  }

"

A few things i'm noticing.  As the script loops through it strips out the headers on each loop.  so for the first example it only lists

Controller: filera

Source                               Destination                          Status         State                LagTimeTS

------                               -----------                          ------         -----                ---------

Also, what is the best way to write the host name like we are and then if it doesn't meet the criteria to write "no snapmirror lag issue"

I was thinking along the lines of

$lag = Get-NaSnapmirror | where-object {$_.LagTime -gt $LagTimeSeconds

Am i totally off base?

I'm also noticing the built in formatting is not big enough for some of our volume names.  I am going to work on that with the expression statements like you did in the other post.  I will re-post when im done.

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

Public