Scheduled Task Last Run Status

Progel.Windows.ScheduledTasks.XP.Job.Monitor (UnitMonitor)

Checks for task last run status.

Knowledge Base article:

Summary

The monitor checks for tasks (jobs) run status and alerts if a job has failed.

Configuration

The default monitor scheduling is every 30' this can be changed via standard overrides. By default the monitor expects a 0 exit code from the job if it is successful, the exit code can be overridden as well.

Causes

A job can fail for several reasons, the most common ones are:

Resolutions

By default a new scheduled job runs in the context of the creating user. This should be avoided and an ad hoc account should be created for the job. Alternatively the Local System Account (SYSTEM) can be used to run jobs in an administrative context.

For failing commands checks the command line from the command prompt using the same credentials the taskscheduler is going to use. PsExec can be useful in this.

You can even try to rerun the task from here: Start Scheduled Task.

Element properties:

TargetProgel.Windows.ScheduledTasks.XP.Job
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeProgel.Windows.ScheduledTasks.XP.Job.MonitorType
RemotableFalse
AccessibilityInternal
Alert Message
Scheduled Task failed
Job/Task {0} Failed with exit code {2} ({3}). Last run date was {1}
RunAsDefault

Source Code:

<UnitMonitor ID="Progel.Windows.ScheduledTasks.XP.Job.Monitor" Accessibility="Internal" Enabled="true" Target="Progel.Windows.ScheduledTasks.XP.Job" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="false" Priority="Normal" TypeID="Progel.Windows.ScheduledTasks.XP.Job.MonitorType" ConfirmDelivery="true">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Progel.Windows.ScheduledTasks.XP.Job.Monitor_AlertMessageResourceID">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Warning</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="ProgelWindowsScheduledTasksLibrary!Progel.Windows.ScheduledTasks.Job"]/JobName$</AlertParameter1>
<AlertParameter2>$Data/Context/Property[@Name='LastRun']$</AlertParameter2>
<AlertParameter3>$Data/Context/Property[@Name='ExitCode']$</AlertParameter3>
<AlertParameter4>$Data/Context/Property[@Name='ExitCodeHex']$</AlertParameter4>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="SUCCESS" MonitorTypeStateID="SUCCESS" HealthState="Success"/>
<OperationalState ID="FAILED" MonitorTypeStateID="FAILED" HealthState="Warning"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>1800</IntervalSeconds>
<SyncTime/>
<TimeoutSeconds>120</TimeoutSeconds>
<JobName>$Target/Property[Type="ProgelWindowsScheduledTasksLibrary!Progel.Windows.ScheduledTasks.Job"]/JobName$</JobName>
<ExpectedExitCode>^0$</ExpectedExitCode>
<ManagementGroupName>$Target/ManagementGroup/Id$</ManagementGroupName>
<LogSuccessEvent>true</LogSuccessEvent>
</Configuration>
</UnitMonitor>