Can I get notified when a job fails?

I’m relatively new to PSU, but starting to get into it more seriously. A current challenge is thinking a new script/job is working great, but then coming back a few days later to see a ton of Job Failed logs.

I believe I’ve searched everywhere in the documentation, settings, etc, but I cannot find any reference to a built-in notification system. So I’m deducing that we, as developers, are supposed to build our own notification system based on various PowerShell concepts I may not be fully aware of yet.

For example, I’m seeing in my “Your topic is similar to…” pane on the right as I’m typing there’s evidently a Get-UAJobOutput function. So I’m now deducing I can/should write my own PSU Job Status Check script that gets jobs based on my needs, validates their status, then sends me a notification however I’d like.

Am I on the correct path? Or in left field?

Thank you! --Matt

Product: PowerShell Universal
Version: 5.4.3

You could create a trigger which executes a script which sends you an email and triggers on event type “Job failed”

1 Like

Yep. We use a trigger to execute the following script, which generates a ticket in our instance of FreshService.

   <#
    .SYNOPSIS
    Send a notification to FreshService
    
    .DESCRIPTION
    Send a notification to Freshservice from triggers in PowerShell Universal.
    
    .PARAMETER Data
    The trigger data. Generated by PowerShell Universal.

    .PARAMETER Job
    The trigger data. Generated by PowerShell Universal.
    #>
    param(
         [Parameter(Mandatory = $true, ParameterSetName = "Job")]
        $JobID
    )

$Job = Get-PSUJob -Id $JobID

$Job

    $FSAlertData = @{
        "alertname"      = "Job Finished with $($Job.Status.ToString())"
        "alertstatus"   = $Job.Status.ToString()
        "alertresource"    = $Job.ScriptFullPath
        "alertjobID" = $Job.Id
        "output" = $Job.Output
    }

$FSBody = ConvertTo-Json -InputObject $FSAlertData -Depth 5


$webheaders=@{}
$webheaders.Add("accept", "application/json")
$webheaders.Add("Authorization", "auth-key <redacted>")

Invoke-WebRequest -URI "https://<redacted>/integrations/24924/alerts" -Body $FSBody -Headers $webheaders -method POST -ContentType "application/json"
1 Like

You guys rock! Thank you so very much! --Matt

1 Like

No problem.