2 Replies Latest reply on Aug 8, 2019 5:28 AM by mimo974

    Create alarm by mail for snapshot

    mimo974 Lurker

      Hello,

       

      Its possible to create an alarm on vcenter 6.0 for snapshot when still have it on VM more 2 days. I tried to find on vcenter alarm default but cant find it.

       

      Do you think can make an alarm for snapshot ?

       

      Thank you for your helps.

       

      Francois.

        • 1. Re: Create alarm by mail for snapshot
          HassanAlKak88 Expert
          vExpert

          Hello,

           

          On the vCenter you can create alarms that are based on 3 types of triggers: event, metric and state. The age of a snapshot doesn't fall under any of these triggers I'm afraid.

           

          Kindly check the following a script to manage your request, maybe it will be helpful: PowerCLI Scripting - SnapShot Create Date is older than 3 days

          • 2. Re: Create alarm by mail for snapshot
            mimo974 Lurker

            Hello,

             

            Thank for your help. Im not an expert with PowerCLI and have some parts on this script im not sure.

             

            1/ When the script is ready i just need to open a vmware powerCLI and start the script ?

            2/ I can let the script in mu computer on C:\ ?

            3/ I put on red some lines i not sure

             

            # PowerShell script to check for VM snapshots and send Email report

            add-pssnapin VMware.VimAutomation.Core

            Connect-VIServer -Server <ip-or-host> -User <username> -Password <password> (I need to let -Server -User and -Password ? and i need to right in clear my password ?)

             

            # HTML formatting

            $a = "<style>"

            $a = $a + "BODY{background-color:white;}"

            $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"

            $a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: LightBlue}"

            $a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: white}"

            $a = $a + "</style>"

             

            # Main section of check

            Write-Host "Checking VMs for for snapshots"

            $date = get-date

            $datefile = get-date -uformat '%m-%d-%Y-%H%M%S'

            $filename = "c:\dir\Snapshots_" + $datefile + ".htm" (Its directory of my computer ?)

             

            # Get list of VMs with snapshots

            # Note:  It may take some time for the  Get-VM cmdlet to enumerate VMs in larger environments

            $ss = Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-3)}

            Write-Host "   Complete " -ForegroundColor Green

            Write-Host "Generating VM snapshot report"

            #$ss | Select-Object vm, name, SizeGB, Created, powerstate | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report</H2>"| Out-File $filename

             

            $ss | Select-Object vm, name, SizeGB, Created, powerstate | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report </H2>"| Out-File $filename

            Write-Host "   Complete " -ForegroundColor Green

            Write-Host "Your snapshot report has been saved to:" $filename

             

            $SMTPServer = <smtp_server>

            $SMTPPort = 587

            $Username = "email@email.com"

             

            #Define the receiver of the report

            $to = "recipient.email@email.com"

            $subject = "VM Snapshot Report"

            $body = "VM Snapshot Report"

            $attachment = new-object Net.Mail.Attachment($filename)

             

            $message = New-Object System.Net.Mail.MailMessage

            $message.subject = $subject

            $message.body = $body

            $message.to.add($to)

            $message.from = $username

            $message.attachments.add($attachment)

             

            $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);

            $smtp.EnableSSL = $true

            #$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);

            $smtp.send($message)

            write-host "Mail Sent"