Private/Notifiers/Invoke-NotifierSyslog.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#requires -modules Posh-SYSLOG

function Invoke-NotifierSyslog {
    [cmdletbinding()]
    param(
        [parameter(Mandatory, ValueFromPipeline)]
        [ValidateScript({ $_.PSObject.TypeNames[0] -eq 'Watchmen.Notifier.Syslog' })]
        [pscustomobject]$Notifier,

        [parameter(Mandatory)]
        [ValidateScript({ $_.PSObject.TypeNames[0] -eq 'OperationValidationResult' })]
        [pscustomobject]$Results
    )

    if ($Notifier.Enabled) {

        Import-Module -Name Posh-SYSLOG -Verbose:$false -ErrorAction Stop

        $o = ($Notifier | Format-Table -Property * -AutoSize | Out-String)
        Write-Debug -Message "Syslog notifier called with options:`n$o"

        $msg = "$($Results.RawResult.Describe) -> $($Results.RawResult.Context) -> $($Results.RawResult.Name) -> $($Results.RawResult.Result.ToUpper())"

        foreach ($endpoint in $Notifier.Endpoints) {
            Send-SyslogMessage -Server $endpoint -Message $msg -Severity 'Critical' -Facility 'logalert'
        }

    }
}