Einfaches Monitoring von einer Exchange-Umgebung ( Jetzt auch für Exhcange 2013/6 )
Folgendes wird überprüft:
- Dienst die auf Automatisches Starten eingestellt sind
- Festplatten (leerer Speicherplatz)
- Queues
- Clusterresourcen
- Dieser Test wird nur noch durchgeführt, wenn die entsprechende Rolle auf dem lokalem System installiert ist.
- Zertifikate (Ablaufdatum)
In den Zeilen 19 – 23 müssen entsprechende Anpassungen vorgenommen werden!
############################################################################### ### Überwachungs-Script für Exchange 2010 / 2013 ### Überwacht werden Dienste, HDDs, Queues und Cluster-Resourcen ### ### Autor: Robert Rasp, 26.08.2011 ### Historie ### 04.03.2015: ### Prüfen der Zertifikate ### Checks per Commandline abschaltbar ### Verbesserter HTML-Code ### 27.07.2015: ### Prüfen ob Failover-Cluster installiert ist ### 10.01.2017: ### Automatische Erkennung von Exchange ### Automatische Erkennung Cluster ### Dieste ausgeschlossen die bei SRV2016 und EX2016 selbstständig gestoppt werden ### MX automatisiert ############################################################################### ############################################################################### ### Definitions ############################################################################### param ( [switch]$DEBUG, [string]$smtphost, [string]$from = "$env:computername@powershell.pub", [string]$to = "admins@powershell.pub", [string]$subject = "Service Monitor", [int]$HDDmin = 15, # Minimal free space on HDD in % [int]$QueueLimit = 20, # How many MSG's are allowed per Queue [int]$CertExpiringInDays = 15, [switch]$CheckServices = $true, [switch]$CheckHDD = $true, [switch]$CeckCerts = $true, [switch]$Exchange = $true, [switch]$CheckQueue = $true, [switch]$CheckCluster = $true, [switch]$SVCstart = $true # Try to start stoped services (selfrepair) ) ############################################################################## ### Check Limits ############################################################################### $ExcludedHDD = "X:" # Use a ',' seperated list of Drives in UPPERCASE to be excluded "D:","X:","Y:" $SVCFilter = "*" # Use "exch*" to filter for Exchange-Services only $SVCExclude = "MSEXCHANGENOTIFICATIONSBROKER","WBIOSRVC","MAPSBROKER","SPPSVC","SHELLHWDETECTION","REMOTEREGISTRY","CLR_OPTIMIZATION_V4.0.30319_32","CLR_OPTIMIZATION_V4.0.30319_64","TRUSTEDINSTALLER" # Use a ',' seperated list of Services in UPPERCASE to be excluded if ( -not $smtphost ) { $smtphost = (Resolve-DnsName -Type mx -Name $($to.Split('@')[-1])).NameExchange } ############################################################################### if ( $Exchange -and (Get-PSSnapin -Registered | where {$_.Name -ilike "Microsoft.Exchange.Management.*"} | measure).count -gt 0 ) { $a = (Get-PSSnapin | where {$_.Name -ilike "Microsoft.Exchange.Management.*"} | measure).Count if ( $a -eq 0 ) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } } else { $Exchange = $false $CheckQueue = $false } if ( $CheckCluster ) { Import-Module Servermanager $a = Get-WindowsFeature | where { $_.Name -eq "Failover-Clustering" -and $_.Installed -eq $true } if ( $a.count -gt 0 ) { Import-Module $env:systemroot\system32\WindowsPowerShell\v1.0\Modules\FailoverClusters\FailoverClusters.psd1 } else { $CheckCluster = $false } } ############################################################################### ### Prep Report ############################################################################### $ServerList = @() if ( $Exchange ) { $ServerList += Get-ExchangeServer | select name -ExpandProperty Name } else { $ServerList += $env:computername if ( $CheckQueue ) { write-warning "Exchange is disabled: Disabling Queue-Check!" } $CheckQueue = $false } $report = "" $reportSVC = "" $reportHDD = "" $reportQUEUE = "" $sendEmail = $false $report = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>" $report += "<title>$subject</title>" $report += "<STYLE TYPE='text/css'>" $report += "<!-- td {" $report += "font-family: Tahoma;" $report += "font-size: 11px;" $report += "border-top: 1px solid #999999;" $report += "border-right: 1px solid #999999;" $report += "border-bottom: 1px solid #999999;" $report += "border-left: 1px solid #999999;" $report += "padding-top: 0px;" $report += "padding-right: 0px;" $report += "padding-bottom: 0px;" $report += "padding-left: 0px;}" $report += "body {" $report += "margin-left: 5px;" $report += "margin-top: 5px;" $report += "margin-right: 0px;" $report += "margin-bottom: 10px;}" $report += "table {" $report += "border: thin solid #000000;} -->" $report += "</style></head><body>" $report += "<table width='100%'>" $report += "<tr bgcolor='#CCCCCC'>" $report += "<td colspan='7' height='25' align='center'>" $report += "<font face='tahoma' color='#003399' size='4'><strong>$subject Report</strong></font>" $report += "</td></tr></table>" foreach ($machineName in $serverlist) { if ( $DEBUG ) { $machineName } ############################################################################### ### Check Services ############################################################################### if ( $CheckServices ) { if ( $SVCFilter -eq $NULL -or $SVCFilter -eq "*" ) { $result = get-WmiObject win32_service -ComputerName $machineName } else { $result = get-WmiObject win32_service -ComputerName $machineName | where {$_.displayName -match $SVCFilter} } $result = $result | where { $SVCExclude -notcontains $_.name.toUpper() } | where {$_.StartMode -match "Auto"} | where {$_.state -match "Stopped"} | Select state,name if ( $result ) { if ( -not $reportSVC ) { $reportSVC = "<h3>Services</h3><table width='100%'><tr bgcolor=#CCCCCC>" $reportSVC += "<td width='30%' align='center'>Server Name</td>" $reportSVC += "<td width='30%' align='center'>Service Name</td>" $reportSVC += "<td width='20%' align='center'></td>" $reportSVC += "<td width='20%' align='center'>Status</td></tr>`n" } foreach ($service in $result) { if ( $machineName -ilike $env:computername -and $SVCstart -eq $true) { start-service -name $service.name } Write-Host $machineName `t $service.name `t $service.state -ForegroundColor Red $reportSVC += "<tr>" $reportSVC += "<td>$machineName</td>" $reportSVC += "<td colspan=2>$($service.name)</td>" $reportSVC += "<td bgcolor='#FF0000' align=center>$($service.state)</td>" $reportSVC += "</tr>`n" } } } ############################################################################### ### Check HDD's ############################################################################### if ( $CheckHDD ) { $result = Get-WMIObject Win32_VOLUME -filter "DriveType=3 and (SystemVolume=False or SystemVolume=True)" -Computer $machineName | Select DriveLetter, DeviceID, SystemVolume, VolumeName, @{Name="FreeSpace";Expression={"{0:N1}" -f(($_.freespace / $_.capacity) * 100)}} # $result = Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -Computer $machineName | where {(($_.freespace/$_.size)*100) -le $HHDmin} | Select DeviceID, VolumeName, @{Name="FreeSpace";Expression={"{0:N1}" -f(($_.freespace / $_.size) * 100)}} if ( $DEBUG ) { $result write-host "------------------------------------------------" } $result = $result | where {$_.FreeSpace -le $HDDmin} if ( $DEBUG ) { $result } if ( $result ) { if ( -not $reportHDD ) { $reportHDD += "<h3>Volumes</h3><table width='100%'><tr bgcolor=#CCCCCC>" $reportHDD += "<td align='center'>Server Name</td>" $reportHDD += "<td align='center'>DeviceID</td>" $reportHDD += "<td align='center'>VolumeName Name</td>" $reportHDD += "<td lign='center'>FreeSpace (%)</td>" $reportHDD += "</tr>`n" } if ( $DEBUG ) { $ExcludedHDD } foreach ($hdd in $result) { if ( $hdd.DriveLetter.Length -gt 1 ) { if ( $ExcludedHDD -contains $hdd.DriveLetter.toUpper() ) { continue } } #$ExcludedHDD -notcontains $_.DriveLetter.toUpper() Write-Host $machineName `t $hdd.DeviceID `t $hdd.DriveLetter `t $hdd.FreeSpace "%" -ForegroundColor Red $reportHDD += "<tr>" $reportHDD += "<td>$machineName</td>" $reportHDD += "<td>$($hdd.DeviceID)</td>" $reportHDD += "<td>$($hdd.DriveLetter)</td>" $reportHDD += "<td bgcolor='#FF0000' align=center>$($hdd.FreeSpace)</td>" $reportHDD += "</tr>`n" } } } } ############################################################################### ### Check QUEUE ############################################################################### if ( $CheckQueue ) { $ver = (Get-ExchangeServer $machineName).AdminDisplayVersion.Major if ( $ver -gt 8 ) { if ( $ver -lt 15 ) { $result = Get-TransportServer $machineName | Get-Queue | select Identity, DeliveryType, MessageCount | where { $_.MessageCount -ge $QueueLimit } } else { $result = Get-TransportService $machineName | Get-Queue | select Identity, DeliveryType, MessageCount | where { $_.MessageCount -ge $QueueLimit } } if ( $result ) { if ( -not $reportQUEUE ) { $reportQUEUE = "<h3>Queue</h3><table width='100%'><tr bgcolor=#CCCCCC>" $reportQUEUE += "<td align='center'>Identidy</td>" $reportQUEUE += "<td align='center'>Delivery Type</td>" $reportQUEUE += "<td align='center'>Messages in Queue</td>" $reportQUEUE += "</tr>`n" } foreach ($queue in $result) { Write-Host $machineName `t $queue.Identity `t $queue.DeliveryType `t $queue.MessageCount -ForegroundColor Red $reportQUEUE += "<tr>" $reportQUEUE += "<td>$($queue.Identity)</td>" $reportQUEUE += "<td>$($queue.DeliveryType)</td>" $reportQUEUE += "<td bgcolor='#FF0000' align=center>$($queue.MessageCount)</td>" $reportQUEUE += "</tr>`n" } } } } ############################################################################### ### Check Cluster Resource ############################################################################### if ( $CheckCluster ) { $result = Get-ClusterResource | select name, state, resourcetype | where { $_.state -ne "Online" } if ( $result ) { if ( -not $reportCLUSTER ) { $reportCLUSTER = "<h3>Cluster</h3><table width='100%'><tr bgcolor=#CCCCCC>" $reportCLUSTER += "<td align='center'>Identidy</td>" $reportCLUSTER += "<td align='center'>Resource Type</td>" $reportCLUSTER += "<td align='center'>State</td>" $reportCLUSTER += "</tr>`n" } foreach ($queue in $result) { Write-Host $machineName `t $queue.name `t $queue.resourcetype `t $queue.state -ForegroundColor Red $reportCLUSTER += "<tr><td>$($queue.name)</td>" $reportCLUSTER += "<td>$($queue.resourcetype)</td>" $reportCLUSTER += "<td bgcolor='#FF0000' align=center>$($queue.state)</td></tr>`n" } # $reportCLUSTER = $reportCLUSTER + "</table><br><br>" } } ############################################################################### ### Check Certificates ############################################################################### if ( $CeckCerts ) { if ( $machineName -ne $env:computername -and $machineName -ne "localhost" ) { #$result = invoke-command -computername $machineName { param($Days) Get-ChildItem -Path cert:\LocalMachine\My -Recurse -ExpiringInDays $Days } -Args $CertExpiringInDays | $result = invoke-command -computername $machineName { param($Days) Get-ChildItem -Path cert:\LocalMachine\My -Recurse | where { $_.notafter -le (get-date).AddDays( $Days ) -AND $_.notafter -gt (get-date)} } -Args $CertExpiringInDays | select Subject, FriendlyName, Issuer, NotAfter } else { $result = Get-ChildItem -Path cert:\LocalMachine\My -Recurse | where { $_.notafter -le (get-date).AddDays( $CertExpiringInDays ) -AND $_.notafter -gt (get-date)} | select Subject, FriendlyName, Issuer, NotAfter } if ( $result ) { if ( -not $reportCerts ) { $reportCerts = "<h3>Certificates</h3><table width='100%'><tr bgcolor=#CCCCCC><td align='center'>Server Name</td><td align='center'>Subject</td><td align='center'>FriendlyName</td><td align='center'>Issuer</td><td align='center'>NotAfter</td></tr>`n" } foreach ( $queue in $result) { Write-Host $machineName `t $queue.Subject `t $queue.FriendlyName `t $queue.Issuer `t $queue.NotAfter -ForegroundColor Red $reportCerts += "<tr><td>$machineName</td>" $reportCerts += "<td>$($queue.Subject)</td>" $reportCerts += "<td>$($queue.FriendlyName)</td>" $reportCerts += "<td>$($queue.Issuer)</td>" $reportCerts += "<td bgcolor='#FF0000' align=center>$($queue.NotAfter)</td></tr>`n" } } } ############################################################################### ### Prepare Mail ############################################################################### if ( $reportSVC ) { $sendEmail = $true $report += $reportSVC + "</table><br/>" } if ( $reportHDD ) { $sendEmail = $true $report += $reportHDD + "</table><br/>" } if ( $reportQUEUE ) { $sendEmail = $true $report += $reportQUEUE + "</table><br/>" } if ( $reportCLUSTER ) { $sendEmail = $true $report += $reportCLUSTER + "</table><br/>" } if ( $reportCerts ) { $sendEmail = $true $report += $reportCerts + "</table><br/>" } $report += "</body></html>" if ( $sendEmail -and -not $DEBUG) { $smtp= New-Object System.Net.Mail.SmtpClient $smtphost $msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $report $msg.isBodyhtml = $true $smtp.send($msg) } if ( $DEBUG ) { $report }
Exchange Monitoring (ver 1.2.2)