Monitor Schedule taks failure

Hi,

Does anyone have an idea of event ID generated in Application and services -> Microsoft-> Windows -> Task Scheduler -> Operational logs if any scheduled task fails. I need to monitor a schedule task if it fails.

Regards,

Daya Ram

July 29th, 2015 12:33pm

You may consider using Progel Windows Scheduled Tasks management packs which can freely download from https://pinpoint.microsoft.com/en-hk/Applications/12884902751.
Progel Windows Scheduled Tasks management packs monitor the performance, health, and availability of scheduled tasks on Windows Server 2012 R2, 2012, 2008 R2, 2008, Windows Server 2003, and Windows 2000 Server using your current System Center Operations Manager 2007 or 2012 infrastructure.

or

using Scheduled Task and PS Scheduled Job Management Pack
https://onedrive.live.com/?id=8E65D7FF8119FFA6%21161&cid=8E65D7FF8119FFA6&group=0&parId=8E65D7FF8119FFA6%21158&authkey=%21AD2usfPtucDzaY4&action=locate


Besides event id 201 is logged on Application and services -> Microsoft-> Windows -> Task Scheduler -> Operational logs when schedule task is finished and event description "return code is 0" for schedule task run successful.
Roger

Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 11:30pm

Hi,

I don't want to put any MP for just one task monitoring when I can monitor the task events without any issue.

Event ID 201 that you suggested is for task completed, I want to monitor the task failed events. Can you please suggest the events for task failed?

Regards,

Daya

July 30th, 2015 4:17am

The event id's for task Scheduler are here:

https://technet.microsoft.com/en-us/library/cc774899%28v=ws.10%29.aspx?f=255&MSPPError=-2147217396

You should be able to look for a specific scheduled task by name ... it needs the path in there though. I'd suggest getting a test machine and deliberately create a custom task that fails and look at the eventid and description.

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 4:35am

Thanks, will create a test task to fail and see what it logs.
July 30th, 2015 8:26am

Hi Daya Ram,

Create a timed script two state monitor where in use the below script editing your server name in the script [strComputer = "."]. Make sure that your default run as account must have local admin privilege on the box you are intended to monitor. 

Then provide the two states as below one for healthy and other for the failure. It should resolve the issue

Property[@Name='TaskStatus'] does not equal to 0  - for unhealthy

Property[@Name='TaskStatus'] equal to 0                - for success.

---------------------------------------------------------------------------------------------

Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

Dim strComputer, objWMIService, colOperatingSystems, objOperatingSystem, HostVersion
strComputer = "."
HostVersion = "W2K3higher"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    If (Left(objOperatingSystem.Version, 3) = "5.0" or Left(objOperatingSystem.Version, 3) = "5.1") Then HostVersion = "W2KorWXP"
Next

Dim oShell,TaskName,TaskNameTem, Status
Set oShell = CreateObject("Wscript.Shell")
oShell.run "cmd /c schtasks.exe /query /v /fo csv /nh > c:\tasksM.csv", 1, True


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\tasksM.csv", 1)

Dim arrTaskName(100)

'Modified SCHTASKS.EXE on Windows 2000 adds a blank line between header and listing
'Position of data is also slightly different in Windows 2000 and other OSes
LastRunPos = 6
If HostVersion="W2KorWXP" Then
   objTextFile.ReadLine
   LastRunPos = 5
End If

Do Until objTextFile.AtEndOfStream
  arrTasks = split(objTextFile.ReadLine, """,""")
  TaskNameTemp = Left(arrTasks(1), Len(arrTasks(1)) -1)
  TaskName = Right(TaskNameTemp, Len(TaskNameTemp) -1)
  TaskName = arrTasks(1)
  If TaskName = WScript.Arguments(0) Then
    oBag.AddValue "TaskStatus", arrTasks(LastRunPos)
    Call oAPI.LogScriptEvent("CheckTaskStatus.vbs", 115, 0, "Status of task " & WScript.Arguments(0) & " is : " & arrTasks(LastRunPos))
  End If
Loop

 
objTextFile.Close

Call oAPI.Return(oBag)

---------------------------------------------------------------------

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 10:00am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics