Recipe: Monitor Windows Task Scheduler status with Nagios
- Install and configure check_nt plugin on Nagios and NSCA/NRPE on the Windows server (which I leave as an exercise to the reader, due to abundance of docs elsewhere)
- On the Windows machine prepare a .cmd batch which barely resembles this:
@echo off
if x%1==x goto usage
set TF="%TEMP%\check_tasks.tmp"
schtasks /query /v /FO CSV > "%TF%"
if %1==running goto running
if %1==status goto status
goto usage
:running
for /F "delims=, tokens=2,5 usebackq" %%a in (%TF%) do if %%a-%%b=="%2"-"In esecuzione" (
set R="%%a %%b"
set RC=0
goto result
) ELSE (
set R="%%a not running!"
set RC=2
)
goto result
:status
SET R=2
SET RC=2
for /F "skip=1 delims=, tokens=2,9 usebackq" %%a in (%TF%) do if %%a-%%b=="%2"-"0" (
set R=%%b
SET RC=0
goto result
) ELSE (
set R=--
SET RC=2
)
goto result
:result
echo %R:"=%
goto end
:usage
echo Lists running or failed tasks
echo Usage: "%0 -- check if is running (CRITICAL if not)"
echo Usage: "%0 -- show numerical status for task and returns CRITICAL if not zero"
SET RC=3
:end
exit /B %RC%
- Configure the checks in NSC.ini (we use NRPE):
check_schtasks_status=check_tasks.cmd status $ARG1$
check_schtasks_running=check_tasks.cmd running
- In nagios configure your standard NRPE/NSCA check:
define command {
command_name check_nrpe_generic
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -n -u -c $ARG1$ -a $ARG2$
}
define service {
host_name yourhost
service_description Yourtask status
check_command check_nrpe_generic!check_schtasks_status!YourScheduleName
}
define service {
host_name yourhost
service_description Yourtask is running
check_command check_nrpe_generic!check_schtasks_running!YourScheduleName
}
Nessun commento:
Posta un commento