Last active
May 3, 2017 17:02
-
-
Save ayesamson/e7b1c25ac441725db03f8e718247252f to your computer and use it in GitHub Desktop.
Get-ClusterLogErrors
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
function Get-ClusterLogErrors { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[string]$servername | |
) | |
begin { | |
$filePath = "\\$($servername)\c$\Windows\Cluster\Reports\Cluster.log" | |
if (!(Test-Path $filePath)) { | |
Write-Output "Unable to connect to path [$($filePath)]" | |
Write-Output 'Terminating process.' | |
break; | |
} | |
} | |
process { | |
# SET dateString TO TODAY'S DATE (ie. 2017/05/03) | |
$dateString = (get-date).ToString('yyyy/MM/dd') | |
# ONLY LOOK FOR ERR ENTRIES | |
$errorString = 'ERR' | |
try { | |
# -join "`n" This needs to be in place in order for the following replace function properly convert line breaks to HTML | |
# -replace("`n","<br />") Added to preserve line breaks for HTML output | |
[string]$results = @(Get-Content -Path $filePath | Select-String $dateString | Select-String $errorString -CaseSensitive | Select-String -pattern 'NODE', 'rcm', 'RES', 'quorum', 'QUORUM' -CaseSensitive) -join "`n" -replace("`n","<br/>") #, 'mscs', 'ClNet' | |
} | |
catch { | |
Write-Output $_.Exception.Message | |
Write-Output 'Terminating process.' | |
break; | |
} | |
} | |
end { | |
#SEND NOTIFICATION | |
if ($results.Length -gt 0) { | |
# SET FONT FAMILY AND FONT SIZE | |
$body = "<span style='font-family:Courier New;font-size:10pt'>" + $results + "</span>" | |
# SMTP DETAILS | |
$from = 'Do Not Reply<[email protected]>' | |
$to = '[email protected]' | |
$sub = "$($servername) CLUSTER LOG ERROR REPORT - " + (get-date).ToString("yyyy-MM-dd") | |
$priority = 'High' #'High or Low' | |
$PSEmailServer = 'relay.domain.com' | |
$port = 25 | |
try { | |
# SEND MESSAGE | |
Send-MailMessage -From $from -To $to -Body $body -Subject $sub -Priority $priority -Port $port -BodyAsHtml -ErrorAction Stop | |
} | |
catch { | |
Write-Output $_.Exception.Message | |
Write-Output 'Terminating process.' | |
break; | |
} | |
} | |
} | |
} | |
# USAGE EXAMPLE: | |
Get-ClusterLogErrors 'servername' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment