Getting alerted when a Windows scheduled task fails

alertsscheduled-taskwindows-server-2003

I am looking for a way to get alerted if any of the scheduled tasks on a group of Windows 2003 servers fail (exit with a status code that is not 0). Scripts, commercial applications, and plug-ins to monitoring tools (like Nagios) are all open for consideration.

ActiveXperts Network Monitor comes up in most search results, but the scheduled task monitoring feature is a small part of a large commercial network monitoring package.

Below is a batch file script that will dump out the scheduled task results to a csv file that can be imported into SQL Server using SSIS.

rem MC: dump the scheduled task results into the specified outfile
@echo off

set outfile=c:\temp\scheduled_tasks.csv

rem MC: the for loop skips over the first blank that schtasks adds to the output
for /f "TOKENS=*" %%A in ('schtasks /query /fo csv /v') do ( echo %%A >> %outfile% )

The downside of this approach is that importing the csv file into a database table, running a query looking for status codes that are not 0, and sending out E-mails with alerts if anything was found seems like a cumbersome setup. I would rather use an existing solution than create a complex custom system from scratch.

Best Answer

I do this as part of the scheduled job. All the scheduled jobs I run are scripts. Even if it's a graphical app I launch it from a .bat file. All the scripts include error checking, and they use osql to append a row to a "job monitoring" table. Then one query on the table tells me which jobs succeeded, failed or (courtesy of a left join) didn't report any status. I run this query as a scheduled job on my own workstation and it mails me a report.

JR