Software Development Kit (SDK) and API Discussions

7-Mode Missing Snapshot Alert

ahmada
1,299 Views

Greetings,

 

The attached powershell script checks the volumes of your 7-mode systems and create a list of volumes which didn't take a snapshot yesterday in a xls format then sending as an email.

 

I am assuming that the snapshot name is hourly.0 and for snapvault, snapvault_hourly.0 you can change them to your naming convent here : -

$snapName = "hourly.0"
$vaultSnap = "snapvault_hourly.0"

Create a txt file containing the list of your 7-mode systems and put it on the same location as the script. The file name should be : -

$netappFile = "7netapp.txt"

In case you want to exclude few volumes form the script, create a file and name it Ignore.txt and add the volumes there, one in each line : -

Select-String -Path "Ignore.txt" -CaseSensitive -Pattern "^$($_.Name)$"

The below portion is for sending an email with the list, you can modify it to has the emails you want : -

#Send the output as an attachment 
$smtpTo = "email1@domain.com, email2@domain.com"
$smtpServer = "exchange.domain.com"
$smtpFrom = "SnapShotsScript@domain.com"
$messageSubject = "SnapShots Script (7-Mode)"


#create new message to send
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.ReplyTo = $smtpTo
$message.IsBodyHTML = $true
$message.Attachments.Add($outputFile)

#define message body
$message.Body = “Attached is a list of volumes which didn't take a snapshot last night.”

#send the message
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
$message.Dispose() 

Below is the full script : -

Clear

# the reference time which we want to have a snapshot taken at
# this will return an object referencing yesterday and named hourly.0 or snapvault_hourly.0
$refTime = [DateTime]::Today.AddDays(-1)
$snapName = "hourly.0"
$vaultSnap = "snapvault_hourly.0"
$outputFile = "No Snapshots.xls"
Out-File $outputFile


#Getting Netapp Filers List from a file called 7netapp.txt
$netappFile = "7netapp.txt"
$netappList = Get-Content $netappFile


foreach ($netapp in $netappList){

    Write-Host -ForegroundColor Yellow "`nConnecting to $netapp"
    Add-Content $outputFile "`n***********************"
    Add-Content $outputFile $netapp
    
    try{
     Connect-NaController $netapp -RPC
     Add-Content $outputFile "***********************"
        
        #Snapshots Filtering Logic Starts...
        Get-NaVol| ForEach-Object {

        #Check the ignore list
        if(Select-String -Path "Ignore.txt" -CaseSensitive -Pattern "^$($_.Name)$"){
            Write-Host -ForegroundColor Magenta "Ignoring volume $($_.Name) as it is part of the ignore list"
            } 

        # get snapshots for the volume which match the references
        elseif ( ($_ | Get-NaSnapshot | Where-Object { $_.AccessTimeDT -gt $refTime -and ($_.Name -eq $snapName -or $_.Name -eq $vaultSnap) }).count -ne 1) {

                # if there wasn't one returned, state so in red
                Write-Host -ForegroundColor Red "Volume $($_.Name) does not have a snapshot at the reference time" 
                Add-Content $outputFile $_.Name

                }
        else
            {

                # there was one returned, say so in green
                Write-Host -ForegroundColor Green "Volume $($_.Name) has a snapshot at the reference time"

                }
        }

        #Snapshots Filtering Logic Ends...
        Write-Host -ForegroundColor Yellow "Done from $netapp"

    }
    catch{
           
            Write-Host -ForegroundColor Yellow "Failure on $netapp"
            Add-Content $outputFile "Can't connect to $netapp"
               write-host $_.Exception.ToString()
               #exit 1
            }
}

#Send the output as an attachment 
$smtpTo = "email1@domain.com, email2@domain.com"
$smtpServer = "exchange.domain.com"
$smtpFrom = "SnapShotsScript@domain.com"
$messageSubject = "SnapShots Script (7-Mode)"


#create new message to send
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.ReplyTo = $smtpTo
$message.IsBodyHTML = $true
$message.Attachments.Add($outputFile)

#define message body
$message.Body = “Attached is a list of volumes which didn't take a snapshot last night.”

#send the message
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
$message.Dispose() 

 

0 REPLIES 0
Public