#Obtaining and filtering Active Fax Servers Import-Module PSRightFax -ErrorAction Stop -Verbose:$false $FaxServers = Get-RFServerNames -FaxServer # Get Alert State (if any) $BasePath = Join-Path -Path "\\Graphite" -ChildPath "Prod" $AlertStatePath = Join-Path -Path $BasePath -ChildPath "BadErrFileAlertState.xml" If (Test-Path -Path $AlertStatePath) { $AlertState = Import-Clixml -Path $AlertStatePath } Else { $AlertState = @{} } #Retreiving Error and Bad files from all Valid Fax servers $RunDate = Get-Date $RFJobs = ForEach ($FaxServer in $FaxServers) { Invoke-Command -ComputerName $FaxServer -ArgumentList $RunDate -AsJob -ScriptBlock { [CmdletBinding()] Param ( [datetime]$RunDate ) $Stack = $env:COMPUTERNAME -replace "faxsrv" ForEach ($Type in "bad","err") { If ($Type -eq "bad") { $Path = "E:\Program Files (x86)\Rightfax\EDC\Processors\GetDocuments" } Else { $Path = "E:\Program Files (x86)\Rightfax\EDC\Status\Processors\GetDocuments" } Try { $Files = @(Get-ChildItem -Path $Path -Include "*.$Type" -File -Recurse -ErrorAction Stop) } Catch { Write-Error $_ -ErrorAction Stop } [PSCustomObject]@{ Stack = $Stack Name = "metrics.winops.faxing.rightfax.$Stack.$($Type.Replace("err","error"))FileCount" Value = $Files.Count Date = $RunDate } } } } # Retrieve information from jobs $null = $RFJobs | Wait-Job ForEach ($RFJob in ($RFJobs | Sort-Object Location)) { $Alert = $false $FaxServer = $RFJob | Select-object -ExpandProperty Location Try { $Metric = $RFJob | Receive-Job -ErrorAction Stop $Stack = $Metric | Select-Object -First 1 -ExpandProperty Stack If ($AlertState.ContainsKey($Stack)) { $Alert = $true $Severity = "Resolved" } # Send metric's upstream $Metric | Select-Object Name,Value,Date } Catch { $Stack = $FaxServer -replace "faxsrv" Write-Warning "Error retrieving files from $FaxServer because $_. Sending alert to: $to" $ErrorResult = $_ $Alert = $true $Severity = "Critical" } $RFJob | Remove-Job If ($Alert) { $SendAlert = $false If ($AlertState.ContainsKey($Stack)) { If ($Severity -eq "Critical") { $Diff = $RunDate - $AlertState[$Stack] | Select-Object -ExpandProperty TotalMinutes If ($Diff -gt 15) { $SendAlert = $true $AlertState[$Stack] = $RunDate } } Else { Write-Verbose "Stack $Stack no longer in alert state" $SendAlert = $true $AlertState.Remove($Stack) } } Else { $SendAlert = $true $AlertState.Add($Stack, $RunDate) } #This will only send the alert outside of the nightly publish hours of 1 - 4 am. If (($SendAlert) -and (-not (((get-date).TimeOfDay.totalhours -ge 1) -and ((get-date).timeofday.totalhours -lt 4)))) { $Message = @" $FaxServer EDC is not converting inbound faxes EXSRE Information: $ErrorResult