NetApp SnapMirror Monitor Script – Part 1

By | January 25, 2010

When I designed a DR solution a while back, I knew what I needed to do, what the software/hardware involved would do, but wasn’t sure about a couple things, including how to monitor it.

I did a Google search on NetApp SnapMirror Monitoring, and didn’t find much, given the route I chose to take, a Windows system running Snap Manager for Virtual Infrastructure (SMVI). I chose to have this system report the SnapMirror status.

It didn’t make sense to me to use a Linux/Unix system to handle this role (as I don’t have many of these systems). It did make sense to me to have my system running SMVI to perform the task.

I started by using plink.exe to execute the “snapmirror status” command on my remote Filer. I like plink, because it can execute a ssh command remotely, and can be scripted.

To make plink.exe execute a remote snapmirror status command, the syntax would be something like this:

plink user@filername_or_ip -pw password “snapmirror status”

I will admit, it isn’t the best method to use a clear password in a script. I don’t. I generated an ssh key and included it in my authorized_keys on my target Filer. I’m not going to go into that process in this post.

Now, the next step, is to be able to grab the information that the target filer responds with. This information would look something like this:

Snapmirror is on.
Source Destination State Lag Status
sourcefiler:/vol/nfs_volume/nfs_volume destfiler:/vol/nfs_volume_dr/nfs_volume Snapmirrored 02:09:16 Idle

Let me go into a little detail on the way the volumes are configured. On both Filers, there is a volume presented as NFS to ESX named nfs_volume. Also, there is a qtree named nfs_volume within the volume (nfs_volume).

Confusing? A little bit.
The reason I created qtrees with the same name, is because I’m doing SnapMirror replication at the qtree level, and not at the volume level. This is because to successfully replicate from volume to volume, the two Filers have to be running the same version of ONTAP. I cannot always be sure that both Filers will be at the same version (or revision), so I decided to replicate at the qtree level. Replication of qtrees does not require the Filers to be on the same version of ONTAP.

The hard part
Plink very easily returns data back from a command line. That is unless you want to pipe that to a file. And when you grab that information, how do you get it in a tangible medium.

My first script
Here is a copy of my first script. It is pretty rudimentary, but it was a start.

‘*************************************************
‘* NetApp SnapMirror Monitoring Script version 0.1
‘* October 2009
‘* Jase McCarty
‘*************************************************

‘Set our output file
outFile = “C:pathplinkout.TXT”
‘Set our Mail Server’s DNS Name
SMTPServer = “mail.domain.com”

‘Setup a Wscript Shell Object so we can execute a command line instruction
set objShell = wscript.createObject(“wscript.shell”)

‘Run the command
iReturn = objShell.Run(“CMD /C plink.exe user@netapp.domain.com -pw password ” & CHR(34) & “snapmirror status” & CHR(34) & ” > ” & outFile & ” 2>>&1 “, , True)

‘ Set a File System Object, so we can read the created file
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

‘Check for the file, and read it if it is present
If objFSO.FileExists(outFile) Then

‘Start Reading the File and Loop through it
Set objFile = objFSO.OpenTextFile(outFile, 1)
Do While Not objFile.AtEndOfStream

sText = objFile.ReadLine
sMessage = sMessage & sText & VbCrLf

Loop

‘Rename the file with the current date time
objFSO.MoveFile outFile, “c:pathreplication-” & Now() & “.log”
objFile.Close

‘Log a success and the message content to the Event log
objShell.LogEvent EVENTLOG_INFORMATION, sMessage

sSubject = “NetApp Replication Status as of ” & Now()

‘If the file isn’t present, there was a problem
Else

sSubject = “NetApp Replication Status Script Error”
sMessage = “NetApp Replication Status Script Encountered an error with the file ” & outFile

‘Log a failure and the message content to the Event log
objShell.LogEvent EVENTLOG_ERROR, sMessage

End If

‘Send an e-mail with the Replication status
SendEMail sSubject,sMessage

Sub SendEmail(sSubject,sMessage)

Set objMessage = CreateObject(“CDO.Message”)
objMessage.From = “SMVI@domain.com”
objMessage.To = “user@domain.com”
objMessage.Subject = sSubject
objMessage.Textbody = sMessage

‘This section provides the configuration information for the remote SMTP server.
‘Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = SMTPServer

‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25

objMessage.Configuration.Fields.Update

‘End remote SMTP server configuration section

objMessage.Send

End Sub

Not too bad for a rough draft
The script executes plink, and outputs the data to a file. The script then checks to make sure the file was created properly and collects the contents to be e-mailed. It also renames the file according to the time of execution, so a “physical” history of the results can be referred to later. This script can then be run as a Windows scheduled task to execute at desired intervals.

I have modified the script a little more extensively, including things like posting the results to a database as well as some replication lag alerting. Look for more information about how to do this in some followup posts.

6 thoughts on “NetApp SnapMirror Monitor Script – Part 1

  1. Pingback: Jase's Place » NetApp SnapMirror Monitor Script – Part 2 using PoshOnTap

  2. Steve Francis

    Just a note – if you did want a commercial solution to give your time back, LogicMonitor.com will detect whether a NetApp has snapmirror configured, and automatically monitor every snap mirror for lag and status, and alerts about issues.
    (Of course, it monitors everything else in a Netapp too, like each volumes latency, disks per aggregate, CPU, IOps per volume, HBA throughput, etc). And can the same for other non-NetApp devices (linux, windows, MySQL, etc.)
    Always keeps its monitoring current.

    Reply
    1. Jase Post author

      Thanks for recommending the commercial solution. I’ll have to take a look at it.

      Thanks,
      Jase

      Reply
  3. Kamalk

    Hello

    Nice script 🙂 , but i get an error when it try to renamme the file

    to monitor SnapMirror Job you can also use a product from Netapp “Protection Manager” coupled with “Operation Manager”

    Reply
  4. Jase Post author

    @Kamalk
    It sounds like you are having a problem getting the date/time in the rename process.

    Remember, renaming the file is not necessary. I only did it for a historical purpose.

    Using Protection Manager and Operations Manager to perform a similar function is definitely an alternative, but has some additional costs involved, as well as being a little more complicated.

    The purpose of the script was simply to provide a quick, easy, and simple way of getting this information.

    Reply
  5. Pingback: How do I get my code to loop in order to continuously monitor the event logs?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.