Created
February 24, 2015 08:41
-
-
Save nmanzi/ba2f13dc184a82e6f0e9 to your computer and use it in GitHub Desktop.
NetApp-ActiveDedupAlert.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Help | |
# ---------- | |
<# | |
.SYNOPSIS | |
NetApp-ActiveDedupAlert.ps1 will send an email to a specified address if it detects a running SIS process on | |
any volume belonging to specified controllers. | |
Highlights: | |
o Creates a plain but detailed and user-friendly HTML report which is compatible with all modern browsers. | |
Version History: | |
[x] Version 1.0 (Release) - 24/02/15 | |
Requirements: | |
o NetApp DataONTAP Powershell Module | |
.DESCRIPTION | |
NetApp-ActiveDedupAlert.ps1 will send an email to a specified address if it detects a running SIS process on | |
any volume belonging to specified controllers. | |
.PARAMETER Controllers | |
One or more NetApp Data ONTAP 7-mode controllers specified by IP or hostname. | |
.PARAMETER Username | |
Local admin username for the specified controller(s). | |
.PARAMETER Password | |
Password for specified username. | |
.PARAMETER SendMail | |
Send e-mail option ($true/$false). The default value is "$fale". | |
.PARAMETER SMTPServer | |
Mail server address. | |
.PARAMETER SMTPPort | |
Mail server port. The default value is "25". | |
.PARAMETER MailTo | |
A single mail recipient or an array of mail recipients. | |
.PARAMETER MailFrom | |
Mail sender address. | |
.PARAMETER MailFromPassword | |
Mail sender password for SMTP authentication. | |
.PARAMETER SMTPServerTLSorSSL | |
SMTP TLS/SSL option ($true/$false). The default value is "$fale". | |
.EXAMPLE | |
Check controllers controller1 and controller2 for running SIS processes, and email alert. | |
.\NetApp-ActiveDedupeAlert.ps1 -Controller controller1,controller2 -Username <user> -Password <"pass"> -SMTPServer <server> -MailFrom <Email From> -MailTo <Email To> | |
.INPUTS | |
None | |
.OUTPUTS | |
None | |
.NOTES | |
Author: Nathan Manzi | |
Website: http://nmanzi.com | |
Email: [email protected] | |
Date created: 24/02/15 | |
Last modified: 24/02/15 | |
Version: 1.0 | |
Thanks to http://www.serhatakinci.com for the Hyper-V report the script was based on. | |
.LINK | |
http://nmanzi.com | |
#> | |
#endregion Help | |
#region Script Parameters | |
# ----------------------- | |
[CmdletBinding(SupportsShouldProcess=$True)] | |
Param ( | |
[parameter( | |
Mandatory=$true, | |
HelpMessage='NetApp Controller name/IPs separated by commas (like netapp01,netapp02 or 192.168.1.1,192.168.1.2)')] | |
[string[]]$Controllers, | |
[parameter( | |
Mandatory=$true, | |
HelpMessage='Username for NetApp Controllers')] | |
[string]$Username, | |
[parameter( | |
Mandatory=$true, | |
HelpMessage='Password to suit username provided')] | |
[string]$Password, | |
[parameter( | |
Mandatory=$false, | |
HelpMessage='Enable Send Mail (This is just a switch, value can not be assigned)')] | |
[bool]$SendMail = $false, | |
[parameter( | |
Mandatory=$false, | |
HelpMessage='SMTP Server Address (Like IP address, hostname or FQDN)')] | |
[string]$SMTPServer, | |
[parameter( | |
Mandatory=$false, | |
HelpMessage='SMTP Server port number (Default 25)')] | |
[int]$SMTPPort = "25", | |
[parameter( | |
Mandatory=$false, | |
HelpMessage='Mail To (Recipient e-mail address)')] | |
[array]$MailTo, | |
[parameter( | |
Mandatory=$false, | |
HelpMessage='Mail From (Sender e-mail address)')] | |
[string]$MailFrom, | |
[parameter( | |
Mandatory=$false, | |
HelpMessage='For SMTP Authentication (Sender e-mail address password)')] | |
[string]$MailFromPassword, | |
[parameter( | |
Mandatory=$false, | |
HelpMessage='SMTP TLS/SSL option ($true/$false). The default is "$fale".')] | |
[bool]$SMTPServerTLSorSSL = $false | |
) | |
Import-Module DataONTAP | |
#endregion | |
#region Functions | |
#---------------- | |
Function getCredObject { | |
$strPass = ConvertTo-SecureString -String $Password -AsPlainText -Force | |
$objCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($Username, $strPass) | |
return $objCred | |
} | |
#endregion | |
#region Program | |
#-------------- | |
$htmlEmailHead = " | |
<head> | |
<style> | |
body{ | |
width:100%; | |
min-width:1024px; | |
font-family: Verdana, sans-serif; | |
font-size:14px; | |
/*font-weight:300;*/ | |
line-height:1.5; | |
color:#222222; | |
background-color:#fcfcfc; | |
} | |
p{ | |
color:222222; | |
} | |
strong{ | |
font-weight:600; | |
} | |
h1{ | |
font-size:30px; | |
font-weight:300; | |
} | |
h2{ | |
font-size:20px; | |
font-weight:300; | |
} | |
#ReportBody{ | |
width:95%; | |
height:500; | |
/*border: 1px solid;*/ | |
margin: 0 auto; | |
} | |
table{ | |
width:100%; | |
min-width:1010px; | |
/*table-layout: fixed;*/ | |
border-collapse: collapse; | |
border: 1px solid #ccc; | |
/*margin-bottom:15px;*/ | |
} | |
table tr:nth-child(odd){ | |
background:#F9F9F9; | |
} | |
/*Row*/ | |
tr{ | |
font-size: 12px; | |
} | |
/*Column*/ | |
td { | |
padding:10px 8px 10px 8px; | |
font-size: 12px; | |
border: 1px solid #ccc; | |
text-align:center; | |
vertical-align:middle; | |
} | |
/*Table Heading*/ | |
th { | |
background: #f3f3f3; | |
border: 1px solid #ccc; | |
font-size: 14px; | |
font-weight:normal; | |
padding:12px; | |
text-align:center; | |
vertical-align:middle; | |
} | |
</style></head> | |
<h1>NetApp Deduplication Running Alert</h1> | |
<hr/> | |
<h2>Deduplication is still running on the following controller(s)/volume(s)</h2>" | |
$htmlEmailTableHead = " | |
<table> | |
<tbody> | |
<tr> | |
<th><p>Controller</p></th> | |
<th><p>Volume</p></th> | |
<th><p>Status</p></th> | |
<th><p>Progress</p></th> | |
</tr>" | |
$htmlEmailContent = $null | |
$htmlEmailFooter = "</tbody></table>" | |
$htmlEmail = $null | |
foreach ($Controller in $Controllers) { | |
$CurrentController = Connect-NaController -Name $Controller -Credential (getCredObject) | |
$SisVolList = Get-NaVol -Controller $CurrentController | Where-Object {$_.Sis -notlike $null -and $_.Sis -notlike "idle"} | |
if ($SisVolList) { | |
foreach ($SisVol in $SisVolList) { | |
$VolSisName = $SisVol.Name | |
$SisVolStats = Get-NaVolSis -Path $VolSisName | |
$VolSisStatus = $SisVolStats.Status | |
$VolSisProgress = $SisVolStats.Progress | |
$htmlEmailContent += "<tr><td><p>$Controller</p></td><td><p>$VolSisName</p></td><td><p>$VolSisStatus</p></td><td><p>$VolSisProgress</p></td></tr>" | |
} | |
} else { | |
Write-Debug "No volumes with running SIS found on controller $Controller" | |
} | |
} | |
if ($htmlEmailContent) { | |
$htmlEmail = $htmlEmailHead + $htmlEmailTableHead + $htmlEmailContent + $htmlEmailFooter | |
Write-Debug "Volumes running SIS, sending report" | |
} else { | |
Write-Debug "Nothing to report on, so I'm exiting" | |
Break | |
} | |
#endregion | |
#region Send Mail | |
#--------------- | |
if ($SendMail -or $SMTPServer) | |
{ | |
if ($SMTPServer -and $MailFrom -and $MailTo -and $htmlEmail) | |
{ | |
$subject = "Deduplication Running Alert" | |
$MailTo = ($MailTo -join ',').ToString() | |
$mailMessage = New-Object System.Net.Mail.MailMessage | |
$mailMessage.subject = $subject | |
$mailMessage.to.add($MailTo) | |
$mailMessage.from = $MailFrom | |
$mailMessage.body = $htmlEmail | |
$mailMessage.IsBodyHtml = $true | |
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort); | |
if ($MailFromPassword) | |
{ | |
$smtp.UseDefaultCredentials = $false | |
$smtp.Credentials = New-Object System.Net.NetworkCredential($MailFrom, $MailFromPassword); | |
} | |
if ($SMTPServerTLSorSSL) | |
{ | |
$smtp.EnableSSL = $true | |
} | |
$smtpSendResult = 1 | |
Try | |
{ | |
$smtp.send($mailMessage) | |
} | |
Catch | |
{ | |
Write-Error -Message "E-Mail could not be sent" | |
$smtpSendResult = 0 | |
} | |
if ($smtpSendResult -eq 1) | |
{ | |
Write-Debug -Message "E-mail has been sent to the address(es): $MailTo" | |
} | |
Remove-Variable -Name smtp | |
Remove-Variable -Name MailFromPassword | |
} | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment