Last Result Successful Monitor

Custom.Windows.ScheduledTask.LastResult.Monitor (UnitMonitor)

Knowledge Base article:

Summary

Windows Scheduled Task Last Result Monitor.

The monitor checks the last result code (exit code) of a scheduled task every minute.

Anything other than ‘0’ is considered a warning condition for an enabled scheduled task.

Configuration

Use overrides to:

Causes

The process called by the scheduled task failed

Authentication problems of the scheduled task’s user account

Resolutions

Consult the event log of the affected machine and/or Run Scheduled Task

Disable or delete the Scheduled Task

Element properties:

TargetCustom.Windows.ScheduledTask
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeCustom.Windows.ScheduledTask.DiscoveryData.LastResult.MonitorType
RemotableFalse
AccessibilityPublic
Alert Message
Scheduled Task failed to complete successfully
Last result code of Scheduled Task '{0}' was: {1}. It did not run successfully.
RunAsDefault

Source Code:

<UnitMonitor ID="Custom.Windows.ScheduledTask.LastResult.Monitor" Accessibility="Public" Enabled="true" Target="Custom.Windows.ScheduledTask" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="false" Priority="Normal" TypeID="Custom.Windows.ScheduledTask.DiscoveryData.LastResult.MonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Custom.Windows.ScheduledTask.LastResult.Monitor.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskName$</AlertParameter1>
<AlertParameter2>$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskLastResult$</AlertParameter2>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="NoFailure" MonitorTypeStateID="NoFailure" HealthState="Success"/>
<OperationalState ID="Failure" MonitorTypeStateID="Failure" HealthState="Warning"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>62</IntervalSeconds>
<BagValue>$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskLastResult$</BagValue>
<DesiredReturnCode>^0$</DesiredReturnCode>
<TaskState>$Target/Property[Type="Custom.Windows.ScheduledTask"]/TaskState$</TaskState>
</Configuration>
</UnitMonitor>