Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayesamson/e7b1c25ac441725db03f8e718247252f to your computer and use it in GitHub Desktop.
Save ayesamson/e7b1c25ac441725db03f8e718247252f to your computer and use it in GitHub Desktop.
Get-ClusterLogErrors
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<do-not-reply@domain.com>'
$to = 'samson@domain.com'
$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