My first attempt at this worked out pretty well, but I’ve been looking into PoshOnTap, and come up with a more efficient script. PoshOnTap is really something to look at if you have a NetApp, and are getting deeper into using Powershell.
To get started, download PoshOnTap from http://poshontap.codeplex.com/, and install it.
Once PoshOnTap is installed, to use the cmdlets, it must be imported into your Powershell session using Import-Module PoshOnTap
Now to connect to my second filer, the one that is performing the SnapMirror role, I need to connect to it. This is done with Connect-NaServer -Filer filername -UserName user -Password password. I’ve omitted the username and password, as my Filer is joined to my Active Directory Domain. My Powershell session is being run from an account which is part of the domain.
In my previous post, I had to remotely execute a “snapmirror status” command using ssh through plink. Not very elegant. From the command line, “snapmirror status”, will only show Source, Destination, State, Lag, and Status.
Using Powershell I can execute the same type command, and actually get more information. Information like:
- BaseTimeStamp (time of the last update)
- BaseSnaphot (name of the Snapshot on the destination filer)
- ContentState
- CurrentTransferSize (showing the size of a current transfer)
- CurrentTransferType
- LastTransferSize (how many bytes were transferred)
- LastTransferDuration (how long the last SnapMirror took)
- LastTransferType (Did an initialization occur? Did an update take place?)
So how would I get the same information through Powershell?
Get-NaSnapMirror by itself will show the same information as snapmirror status does, albeit in a different order.
Now, if we change the output format from Format-Table (default) to Format-List (or FL) we will see some very different output.
Now to use some of that output for our monitoring. I created the following script to pull more information than my last script
#Load the PoshOnTap Module Import-Module PoshOnTap #Connect to the Filer Connect-NaServer -Filer netapp2 #Pull Our Data get-NaSnapMirror|select Source,Destination,Status,State,Lag,LastTransferSize,LastTransferDurration|ft
Which returns
Now, to get the output into e-mail, I’m going to have to massage the output a little bit. Here’s the resulting script:
#Load the PoshOnTap Module Import-Module PoshOnTap #Connect to the Filer Connect-NaServer -Filer netapp2 #Pull The Data $body = Get-NaSnapMirror|Select Source,Destination,Status,State,Lag,LastTransferSize,LastTransferDurration|Out-String #Send e-mail Send-MailMessage -From "user@yourdomain.com" -To "user@yourdomain" -Subject "NetApp Replication Script" -SmtpServer mail.domain.com -Body $body
Which will give an output something like this:
Pretty cool how Powershell will let us use less code, and get more done.
I can add “Where-Object { $_.Lag -gt “01:0:00″} |” between “Get-NaSnapMirror |” and “Select Source,” to only show the volumes that have a lag greater than 1 hour. Again, pretty flexible.
Now I’m off to work on Part 3, where I post this information to a SQL database for historical purposes.
Jase,
This is great what you have done. I was able to get LastTransferSize using the Get-NaSnapMirror command you’ve shown. I have one issue. I am trying to get this information from a vfiler. What commands is need to see the vfiler as the physical filer does not have a value for LastTransferSize (only at the vfiler level).
Thanks,
Ken
Ken,
Hmm, I haven’t tried it against a vFiler as of yet. I’ll see it I can find one to test it out against.
Thanks,
Jase
Hi ,
From the command line, “snapmirror status”, will only show Source, Destination, State, Lag, and Status.
just want to know about Lag value. what is Lag value in snapmirror status.
regards
VINAY