It would be extremely helpful in a server monitor to be able to monitor scheduled tasks.
Useful thresholds on scheduled tasks that I can think of would be
Running Status => x minutes/hours/days
Disabled Status => x minutes/hours/days
Last run time => x minutes/hours/days ago
Error code returned on last run - yes/no
Error code returned on last run => x runs
You can use custom plugin to monitor the scheduled tasks.
Please find attached ScheduledTask.zip. Please unzip this file and mention the name of the scheduled task to be monitored in the file "ScheduledTask.ps1" and copy paste the ScheduledTask folder into the plugins folder.
Eg: C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins
The scheduled task plugin contains the following metrics :
- state_value: Current state of the task
- numberOfMissedRuns : Number of task schedules that were missed from running
- lastRunBefore : Time of previous schedule tasks performed
- author : Task's owner
- state : Description of the task state
- lastRunTime : Previous date and time of the task scheduled
- createdon : Task created time
- errorCode : Error code of previous scheduled tasks
Hi,
For each server added, you will be able to monitor one plugin and each plugin can have up to 25 attributes. And, the Scheduled Task plugin that we have provided has around eight attributes. So if you would want to add and monitor multiple job tasks with the same metrics as given in the Scheduled Task plugin, it would exceed the default attribute limit.
However, if you wish to know and monitor only the name and status of a scheduled task, it is possible to add them as a single plugin monitor.
Please let us know if this helps.
Thanks!
You can write a custom plugin to monitor the scheduled tasks. Please find attached ScheduledTask.zip. We have used schtasks command to get data. it will remove the Get-ScheduledTask dependency. So this plugin will work fine in Windows 2008 R2.
- Unzip this file
- Mention the name of the scheduled task to be monitored in "ScheduledTask.ps1".
- Now, copy paste the ScheduledTask folder into the plugins folder.
Eg: C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins
Performance Metrics:
This plugin contains the following metrics:
- lastRunBefore : Time of the previous schedule task that was performed
- author : Task's owner
- Status : Current state of the task
- lastRunTime : Date and time of the previous scheduled task
- Start_Date : The time when the task was initiated
- errorCode : Error code of the previous scheduled task
Hope this helps. Let us know for further queries.
Thanks!
Hello,
I am attempting to use this on Server 2012 R2, and not seeing the correct stats being returned.
Has there been an updates to this, or would this be unique to my environment?
Thanks!
Hi,
Could you please share the logs to support@site24x7.com to analyze the issue?
It would be helpful for us to assist you better.
Thanks!
Hello,
We would like to know to how many tasks you would be monitoring. Because we have limitation on the plugin metrics, i.e., a maximum of 25 attributes only.
So please let us know the count of the scheduled tasks you would like to monitor, and based on that we shall give you suggestions.
Regards,
Muralikrishnan
Hi,
Using this plugin, you can get alerts for scheduled task failures by setting a threshold for the metric "errorCode". If the metric errorCode is 0, it means the previously scheduled task was completed successfully; if the errorCode is greater than 0, it means the previously scheduled task failed.
This plugin script does not have the support to alert when the scheduled tasks do not run. We are currently working on providing in-depth Windows Scheduled Tasks Monitoring and we shall include this metric in that.
Hope this helps. Let us know for further queries if any.
Happy Monitoring!
Reviving this thread.
Receiving an error in Site24x7 that the plug-in was not executed propely.
Running the PowerShell script manually results in -
PS C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ScheduledTask> C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ScheduledTask\ScheduledTask.ps1
Get-ScheduledTaskInfo : The system cannot find the file specified.
At C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ScheduledTask\ScheduledTask.ps1:79 char:13
+ $taskInfo = Get-ScheduledTaskInfo -TaskName $taskName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Get-ScheduledTaskInfo], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070002,Get-ScheduledTaskInfo
You cannot call a method on a null-valued expression.
At C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ScheduledTask\ScheduledTask.ps1:82 char:1
+ $data.Add("lastRunTime",$lastRunTime.ToString())
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
New-TimeSpan : Cannot bind parameter 'Start' to the target. Exception setting "Start": "Cannot convert null to type "System.DateTime"."
At C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ScheduledTask\ScheduledTask.ps1:88 char:34
+ $timespan = NEW-TIMESPAN –Start $lastRunTime –End $timenow
+ ~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [New-TimeSpan], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewTimeSpanCommand
You cannot call a method on a null-valued expression.
At C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ScheduledTask\ScheduledTask.ps1:90 char:1
+ $timediff = $timespan.Days.ToString() + " Days "+ $timespan.Hours.ToS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Adding - it appears the PS1 output results are correct, but still get the errors above when executing.
{
"heartbeat": "True",
"displayname": "Monitor Task - Throttled Disconnects Processor",
"version": "1",
"data": {
"state_value": 3,
"numberOfMissedRuns": null,
"lastRunBefore": null,
"author": "XXXXX",
"state": "Ready",
"errorCode": null,
"createdon": "2017-05-15T11:51:26.551516"
}
Hi,
Can you please share your agent logs with support@site24x7.com? That would help us analyze the issue further.
Thanks!
Regards
Mathangi