This example monitors the Task Scheduler for failed or excessive tasks on Windows. It consists of a set of entries for the sysedge.cf file and an associated schedlgu.cmd script. The schedlgu.cmd script counts *.job files, analyzes the *.txt files in the %SystemRoot%\Tasks directory, and writes the results into the %CASYSEDGE_DATA%\schedlgu.log file. SystemEDGE launches the script and monitors the schedlgu.log file to evaluate the current status.
Copy the schedlgu.cmd script into the %CASYSEDGE%\bin directory or add it to a configuration deployment package that delivers it to the %CASYSEDGE%\bin\managedscripts directory.
Entries for sysedge.cf
# Windows sample configuration for monitoring the Task Scheduler for failed or excessive tasks extension 55 integer readonly 'schedlgu.cmd %CASYSEDGE_DATA%\schedlgu.log' watch logfile 55 0x0 '%CASYSEDGE_DATA%\schedlgu.log' 'The task completed with an exit code of [(][0]*[^0].*[)]' 'Windows Task Scheduler Job Execution Errors' '' 10 warning watch logfile 56 0x0 '%CASYSEDGE_DATA%\schedlgu.log' 'WARNING' 'Windows Task Scheduler Warnings' '' 10 major watch logfile 57 0x0 '%CASYSEDGE_DATA%\schedlgu.log' 'ERROR' 'Windows Task Scheduler Errors' '' 10 critical monitor oid extensionGroup.55.0 55 0x100 600 absolute > 15 'Number of Scheduled Tasks > 15' '' 'SysHealth' 'Scheduled Tasks' 'Count' 'minor'
Extension script schedlgu.cmd
@echo off
REM SystemEDGE extension script for monitoring Windows Task Scheduler
setlocal
set SLOG=.\schedlgu.log
if "%1" NEQ "" set SLOG=%1
set SDIR=%SystemRoot%\Tasks
set SREC=
set DONE=N
REM Logical records in the Task Scheduler log file span multiple lines.
REM Convert into single line format (as %SLOG%) for monitoring via SystemEDGE.
if exist %SLOG% del %SLOG%
for /f "tokens=*" %%i in ('type "%SDIR%\schedlgu.txt"') do set LINE=%%i&call :parseline
REM Return number of configured tasks
set COUNT=0
for /f "tokens=*" %%i in ('dir /b "%SDIR%\*.job"') do call :countline
echo %COUNT%
endlocal
goto :EOF
:countline
set /a COUNT+=1
goto :EOF
:parseline
REM Replace double quotes with pound sign
set LINE=%LINE:"=#%
REM Check if we have already processed the most recent record in the log
if "%DONE%" EQU "Y" goto :EOF
REM Check for start of next logical record
if "%LINE:~0,1%" EQU "#" goto :startrecord
if "%LINE%" EQU "[ ***** Most recent entry is above this line ***** ]" set DONE=Y&goto :startrecord
REM Concatenate lines for current record
set SREC=%SREC% %LINE%
goto :EOF
:startrecord
if "%SREC%"=="" goto :initrecord
REM Restore double quotes
set SREC=%SREC:#="%
REM Write current record
@echo %SREC%>>"%SLOG%"
:initrecord
set SREC=%LINE%
| Copyright © 2011 CA. All rights reserved. | Tell Technical Publications how we can improve this information |